Best Atoum code snippet using template.addChild
class.ebay.operations.php
Source:class.ebay.operations.php
...47 public static function getStore()48 {49 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);50 $xml = $api->getBaseXMLRequest('GetStore');51 $xml->addChild('LevelLimit', '1');52 return $api->DoRequest('GetStore', $xml);53 }54 /**55 * Retrieves the category structure for the store56 *57 * @param int $parentCategoryId The category ID for the topmost category to return58 * @return SimpleXMLElement The category structure59 */60 public static function getStoreCategories($levelLimit = 1, $parentCategoryId = self::ROOT_CATEGORY_ID)61 {62 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);63 $xml = $api->getBaseXMLRequest('GetStore');64 $xml->addChild('CategoryStructureOnly', 'true');65 $xml->addChild('LevelLimit', $levelLimit);66 if ($parentCategoryId > self::ROOT_CATEGORY_ID) {67 $xml->addChild('RootCategoryID', $parentCategoryId);68 }69 return $api->DoRequest('GetStore', $xml);70 }71 /**72 * Retrieves the latest category hierarchy for the eBay site73 *74 * @param int $levelLimit The maximum depth of the heirarchy to retrieve75 * @param int $parentCategoryId The ID of the highest-level category to return. Defaults to null to retrieve all categories.76 * @return SimpleXMLElement The category hierarchy77 */78 public static function getCategories($levelLimit = 1, $parentCategoryId = null)79 {80 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);81 $xml = $api->getBaseXMLRequest('GetCategories');82 $xml->addChild('LevelLimit', $levelLimit);83 if (!is_null($parentCategoryId)) {84 $xml->addChild('CategoryParent', $parentCategoryId);85 }86 $xml->addChild('DetailLevel', 'ReturnAll');87 return $api->DoRequest('GetCategories', $xml);88 }89 /**90 * Gets the current version of the category heirarchy91 *92 * @return string The category version93 */94 public static function getCategoryVersion()95 {96 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);97 $xml = $api->getBaseXMLRequest('GetCategories');98 $result = $api->DoRequest('GetCategories', $xml);99 return (string)$result->CategoryVersion;100 }101 /**102 * Gets the features and details of a specific category103 *104 * @param int $categoryId The ID of the category to retrieve details for105 * @return SimpleXMLElement106 */107 public static function getCategoryFeatures($categoryId)108 {109 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);110 $xml = $api->getBaseXMLRequest('GetCategoryFeatures');111 $xml->addChild('DetailLevel', 'ReturnAll');112 $xml->addChild('CategoryID', $categoryId);113 $xml->addChild('AllFeaturesForCategory', true);114 return $api->DoRequest('GetCategoryFeatures', $xml);115 }116 /**117 * Retrieve the mappings between categories and their corresponding characteristic sets118 *119 * @param int $categoryId The ID of the category to retrieve details for120 * @return SimpleXMLElement121 */122 public static function getCategory2CS($categoryId)123 {124 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);125 $xml = $api->getBaseXMLRequest('GetCategory2CS');126 $xml->addChild('DetailLevel', 'ReturnAll');127 $xml->addChild('CategoryID', $categoryId);128 return $api->DoRequest('GetCategory2CS', $xml);129 }130 /**131 * Retrieves usage information about platform notifications for a given application. You can use this notification information to troubleshoot issues with platform notifications. You can call this up to 50 times per hour for a given application.132 *133 * @param int $endTime Specifies the end date and time for which notification information will be retrieved. EndTime is optional. If no EndTime is specified, the current time (the time the call is made) is used. If no EndTime is specified or if an invalid EndTime is specified, date range errors are returned in the response. For an EndTime to be valid, it must be no more than 72 hours before the time the of the call, it cannot be before the StartTime, and it cannot be later than the time of the call. If an invalid EndTime is specified, the current time is used.134 * @param string $itemId Specifies an item ID for which detailed notification information will be retrieved. ItemID is optional. If no ItemID is specified, the response will not include any individual notification details.135 * @param int $startTime Specifies the start date and time for which notification information will be retrieved. StartTime is optional. If no StartTime is specified, the default value of 24 hours prior to the call time is used. If no StartTime is specified or if an invalid StartTime is specified, date range errors are returned in the response. For a StartTime to be valid, it must be no more than 72 hours before the time of the call, it cannot be more recent than the EndTime, and it cannot be later than the time of the call. If an invalid StartTime is specified, the default value is used.136 * @return SimpleXMLElement137 */138 public static function getNotificationsUsage($endTime = null, $itemId = null, $startTime = null)139 {140 $api = new ISC_ADMIN_EBAY_API();141 $xml = $api->getBaseXMLRequest('GetNotificationsUsage');142 if ($endTime !== null) {143 $xml->EndTime = date('c', $endTime);144 }145 if ($itemId !== null) {146 $xml->ItemID = $itemId;147 }148 if ($startTime !== null) {149 $xml->StartTime = date('c', $startTime);150 }151 return $api->DoRequest('GetNotificationsUsage', $xml);152 }153 /**154 * Retrieves the requesting application's notification preferences. Details are only returned for events for which a preference was set at one point. For example, if you enabled notification for the EndOfAuction event and later disabled it, the GetNotificationPreferences response would cite the EndOfAuction event preference as Disabled. Otherwise, no details would be returned regarding EndOfAuction.155 *156 * @param string $preferenceLevel Specifies what type of Preference to retrieve. NotificationRoleCodeType: Application, CustomCode, Event, User, UserData157 * @return SimpleXMLElement158 */159 public static function getNotificationPreferences($preferenceLevel = 'Application')160 {161 $api = new ISC_ADMIN_EBAY_API();162 $xml = $api->getBaseXMLRequest('GetNotificationPreferences');163 $xml->PreferenceLevel = $preferenceLevel;164 return $api->DoRequest('GetNotificationPreferences', $xml);165 }166 /**167 * Get the URL of the store's eBay notification listener168 * @return string the URL of the eBay notification listener169 */170 public static function getPlatformNotificationsListenerUrl()171 {172 $customPlatformUrl = GetConfig('EbayPlatformNotificationUrl');173 if (!empty($customPlatformUrl)) {174 return $customPlatformUrl;175 }176 return GetConfig('ShopPath') . '/ebaylistener.php';177 }178 /**179 * Enable or disable all platform notifications and configures the listener URL.180 *181 * @param bool $enabled182 * @return SimpleXMLElement183 */184 public static function setApplicationNotificationsEnabled($enabled = true)185 {186 $api = new ISC_ADMIN_EBAY_API();187 $xml = $api->getBaseXMLRequest('SetNotificationPreferences');188 $applicationDeliveryPreferences = $xml->addChild('ApplicationDeliveryPreferences');189 if ($enabled) {190 $applicationDeliveryPreferences->ApplicationEnable = 'Enable';191 } else {192 $applicationDeliveryPreferences->ApplicationEnable = 'Disable';193 }194 $applicationDeliveryPreferences->ApplicationURL = self::getPlatformNotificationsListenerUrl();195 $applicationDeliveryPreferences->DeviceType = 'Platform';196 return $api->DoRequest('SetNotificationPreferences', $xml);197 }198 /**199 * Enable or disable specific platform notifications.200 *201 * @param array $events e.g. array('ItemSold' => 'true', 'ItemUnsold' => false, ...)202 * @return SimpleXMLElement or false if no events provided203 */204 public static function setApplicationNotificationEvents($events)205 {206 if (empty($events)) {207 return false;208 }209 $api = new ISC_ADMIN_EBAY_API();210 $xml = $api->getBaseXMLRequest('SetNotificationPreferences');211 $userDeliveryPreferenceArray = $xml->addChild('UserDeliveryPreferenceArray');212 foreach ($events as $event => $enable) {213 $notificationEnable = $userDeliveryPreferenceArray->addChild('NotificationEnable');214 $notificationEnable->EventType = $event;215 if ($enable) {216 $notificationEnable->EventEnable = 'Enable';217 } else {218 $notificationEnable->EventEnable = 'Disable';219 }220 }221 return $api->DoRequest('SetNotificationPreferences', $xml);222 }223 /**224 * Verifies an addItem request225 *226 * @param array $product The array of product data227 * @param ISC_ADMIN_EBAY_TEMPLATE $template The template to use to add the product228 * @return SimpleXMLElement The XML result of the AddItem request229 */230 public static function verifyAddItem($product, $template)231 {232 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);233 $xml = $api->getBaseXMLRequest('VerifyAddItem');234 self::addItemData($xml, $product, $template);235 return $api->DoRequest('VerifyAddItem', $xml);236 }237 /**238 * Lists a single item on eBay239 *240 * @param array $product The array of product data241 * @param ISC_ADMIN_EBAY_TEMPLATE $template The template to use to add the product242 * @return SimpleXMLElement The XML result of the AddItem request243 */244 public static function addItem($product, $template)245 {246 // update this method to support selling multiple quantity auction items as in the addItems request.247 // this function isn't beind used currently however.248 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);249 $xml = $api->getBaseXMLRequest('AddItem');250 self::addItemData($xml, $product, $template);251 return $api->DoRequest('AddItem', $xml);252 }253 /**254 * Lists a single fixed-price item on eBay. This operation is used when fixed price item specific fields are required such as variations.255 *256 * @param array $product The array of product data257 * @param ISC_ADMIN_EBAY_TEMPLATE $template The template to use to add the product258 * @return SimpleXMLElement The XML result of the AddItem request259 */260 public static function addFixedPriceItem($product, $template)261 {262 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);263 $xml = $api->getBaseXMLRequest('AddFixedPriceItem');264 self::addItemData($xml, $product, $template);265 return $api->DoRequest('AddFixedPriceItem', $xml);266 }267 /**268 * Lists up to 5 items on eBay269 *270 * @param array $products The array of products containing product data to list271 * @param ISC_ADMIN_EBAY_TEMPLATE $template The template to use to add the product272 * @return SimpleXMLElement The XML result of the AddItems request273 */274 public static function addItems($products, $template)275 {276 $api = new ISC_ADMIN_EBAY_API(self::$SITE_ID);277 $xml = $api->getBaseXMLRequest('AddItems');278 foreach ($products as $product) {279 // add each item280 try {281 $itemContainer = $xml->addChild('AddItemRequestContainer');282 $itemContainer->addChild('MessageID', $product['productid']);283 self::addItemData($itemContainer, $product, $template);284 }285 catch (ISC_EBAY_LISTING_EXCEPTION $ex) {286 }287 }288 return $api->DoRequest('AddItems', $xml);289 }290 /**291 * Adds an Item element for the specified product and template into the supplied XML element292 *293 * @param SimpleXMLElement $xml The XML element to add the item to294 * @param array $product The array of product data295 * @param ISC_ADMIN_EBAY_TEMPLATE $template The template to use to add the product296 */297 private static function addItemData(&$xml, $product, $template)298 {299 $template->setProductData($product);300 $productId = $product['productid'];301 $item = $xml->addChild('Item');302 $item->addChild('Site', $template->getSiteCode());303 // required details304 $item->addChild('Country', $template->getItemLocationCountry());305 $item->addChild('Currency', $template->getCurrencyCode());306 $item->addChild('ListingDuration', $template->getListingDuration());307 $item->addChild('ListingType', $template->getSellingMethod());308 $item->addChild('Location', $template->getItemLocationCityState());309 $item->addChild('PostalCode', $template->getItemLocationZip());310 $item->addChild('Title', isc_html_escape($product['prodname']));311 $item->addChild('Description', isc_html_escape($product['proddesc']));312 $item->addChild('SKU', isc_html_escape($product['prodcode']));313 $primaryOptions = $template->getPrimaryCategoryOptions();314 // are item specifics supported by the primary category?315 if (!empty($primaryOptions['item_specifics_supported'])) {316 $itemSpecifics = null;317 // brand name318 if (!empty($product['brandname'])) {319 $itemSpecifics = $item->addChild('ItemSpecifics');320 $specific = $itemSpecifics->addChild('NameValueList');321 $specific->addChild('Name', GetLang('Brand'));322 $specific->addChild('Value', $product['brandname']);323 }324 // do we have custom fields for the product?325 if (!empty($product['custom_fields'])) {326 if ($itemSpecifics == null) {327 $itemSpecifics = $item->addChild('ItemSpecifics');328 }329 foreach ($product['custom_fields'] as $customField) {330 $specific = $itemSpecifics->addChild('NameValueList');331 $specific->addChild('Name', $customField['fieldname']);332 $specific->addChild('Value', $customField['fieldvalue']);333 }334 }335 }336 // does this product have a upc? it can be used to pull in product information337 if (!empty($primaryOptions['catalog_enabled']) && !empty($product['upc'])) {338 $productListingDetails = $item->addChild('ProductListingDetails');339 $productListingDetails->addChild('UPC', $product['upc']);340 }341 // does the product have a variation?342 if ($product['prodvariationid']) {343 $variationId = $product['prodvariationid'];344 $variations = $item->addChild('Variations');345 $variationSpecificsSet = $variations->addChild('VariationSpecificsSet');346 $lastOptionName = '';347 $variationOptions = array();348 // add the variation options349 $res = Store_Variations::getOptions($variationId);350 while ($optionRow = $GLOBALS['ISC_CLASS_DB']->Fetch($res)) {351 if ($optionRow['voname'] != $lastOptionName) {352 $lastOptionName = $optionRow['voname'];353 $nameValueList = $variationSpecificsSet->addChild('NameValueList');354 $nameValueList->addChild('Name', $lastOptionName);355 }356 $nameValueList->addChild('Value', $optionRow['vovalue']);357 $variationOptions[$optionRow['voptionid']] = array($optionRow['voname'], $optionRow['vovalue']);358 }359 // add the combinations360 $res = Store_Variations::getCombinations($productId, $variationId);361 while ($comboRow = $GLOBALS['ISC_CLASS_DB']->Fetch($res)) {362 $variation = $variations->addChild('Variation');363 if ($comboRow['vcsku']) {364 $variation->addChild('SKU', $comboRow['vcsku']);365 }366 $variation->addChild('Quantity', $template->getQuantityToSell());367 $startPrice = $template->getStartPrice(false);368 $comboStartPrice = CalcProductVariationPrice($startPrice, $comboRow['vcpricediff'], $comboRow['vcprice']);369 $comboStartPrice = ConvertPriceToCurrency($comboStartPrice, $template->getCurrency());370 $variation->addChild('StartPrice', $comboStartPrice);371 // add the options for this combination372 $variationSpecifics = $variation->addChild('VariationSpecifics');373 $options = explode(',', $comboRow['vcoptionids']);374 foreach ($options as $optionId) {375 list($optionName, $optionValue) = $variationOptions[$optionId];376 $nameValueList = $variationSpecifics->addChild('NameValueList');377 $nameValueList->addChild('Name', $optionName);378 $nameValueList->addChild('Value', $optionValue);379 }380 }381 // add images382 $optionPictures = Store_Variations::getCombinationImagesForFirstOption($productId, $variationId);383 if (!empty($optionPictures)) {384 $pictures = $variations->addChild('Pictures');385 // we'll be adding images for the first option set386 list($optionName) = current($variationOptions);387 $pictures->addChild('VariationSpecificName', $optionName);388 foreach ($optionPictures as $optionName => $imageUrl) {389 $variationSpecificPictureSet = $pictures->addChild('VariationSpecificPictureSet');390 $variationSpecificPictureSet->addChild('VariationSpecificValue', $optionName);391 $variationSpecificPictureSet->addChild('PictureURL', $imageUrl);392 }393 }394 }395 // add quantity396 if (!$product['prodvariationid']) {397 $item->addChild('Quantity', $template->getTrueQuantityToSell());398 }399 $item->addChild('PrivateListing', (int)$template->isPrivateListing());400 // schedule date401 if ($template->getScheduleDate()) {402 $item->addChild('ScheduleTime', $template->getScheduleDate());403 }404 // condition405 if ($template->getItemCondition()) {406 $item->addChild('ConditionID', $template->getItemCondition());407 }408 // payment details409 foreach ($template->getPaymentMethods() as $paymentMethod) {410 $item->addChild('PaymentMethods', $paymentMethod);411 }412 if (in_array('PayPal', $template->getPaymentMethods())) {413 $item->addChild('PayPalEmailAddress', $template->getPayPalEmailAddress());414 }415 // add categories416 $item->addChild('PrimaryCategory')->addChild('CategoryID', $template->getPrimaryCategoryId());417 if ($template->getSecondaryCategoryId()) {418 $item->addChild('SecondaryCategory')->addChild('CategoryID', $template->getSecondaryCategoryId());419 }420 $item->addChild('CategoryMappingAllowed', (int)$template->getAllowCategoryMapping());421 // add store categories422 if ($template->getPrimaryStoreCategoryId()) {423 $storeFront = $item->addChild('Storefront');424 $storeFront->addChild('StoreCategoryID', $template->getPrimaryStoreCategoryId());425 if ($template->getSecondaryStoreCategoryId()) {426 $storeFront->addChild('StoreCategory2ID', $template->getSecondaryStoreCategoryId());427 }428 }429 // prices430 if ($template->getSellingMethod() == ISC_ADMIN_EBAY::CHINESE_AUCTION_LISTING) {431 $item->addChild('StartPrice', $template->getStartPrice());432 if ($template->getReservePrice() !== false) {433 $item->addChild('ReservePrice', $template->getReservePrice());434 }435 if ($template->getBuyItNowPrice() !== false) {436 $item->addChild('BuyItNowPrice', $template->getBuyItNowPrice());437 }438 }439 elseif (!$product['prodvariationid']) {440 $item->addChild('StartPrice', $template->getStartPrice());441 }442 // add return policy info443 $policy = $item->addChild('ReturnPolicy');444 $policy->addChild('ReturnsAcceptedOption', $template->getReturnsAcceptedOption());445 if ($template->getReturnsAccepted()) {446 if ($template->getAdditionalPolicyInfo()) {447 $policy->addChild('Description', isc_html_escape($template->getAdditionalPolicyInfo()));448 }449 if ($template->getReturnOfferedAs()) {450 $policy->addChild('RefundOption', $template->getReturnOfferedAs());451 }452 if ($template->getReturnsPeriod()) {453 $policy->addChild('ReturnsWithinOption', $template->getReturnsPeriod());454 }455 if ($template->getReturnCostPaidBy()) {456 $policy->addChild('ShippingCostPaidByOption', $template->getReturnCostPaidBy());457 }458 }459 // counter460 $item->addChild('HitCounter', $template->getCounterStyle());461 // gallery option462 $pictureDetails = $item->addChild('PictureDetails');463 $pictureDetails->addChild('GalleryType', $template->getGalleryType());464 if ($template->getGalleryType() == 'Featured') {465 $pictureDetails->addChild('GalleryDuration', $template->getFeaturedGalleryDuration());466 }467 if ($template->getItemPhoto()) {468 if ($template->getGalleryType() != 'None') {469 $pictureDetails->addChild('GalleryURL', $template->getItemPhoto());470 }471 $pictureDetails->addChild('PictureURL', $template->getItemPhoto());472 }473 // listing features474 foreach ($template->getListingFeatures() as $feature) {475 $item->addChild('ListingEnhancement', $feature);476 }477 // domestic shipping478 if ($template->getUseDomesticShipping()) {479 // add shipping details480 $shippingDetails = $item->addChild('ShippingDetails');481 // the actual shipping type - Flat or Calculated - where's our freight option gone?482 $shippingDetails->addChild('ShippingType', $template->getShippingType());483 //$insuranceDetails = $shippingDetails->addChild('InsuranceDetails');484 $shippingDetails->addChild('InsuranceOption', 'NotOffered');485 $calculatedRate = null;486 // add checkout instructions487 if ($template->getCheckoutInstructions()) {488 $shippingDetails->addChild('PaymentInstructions', $template->getCheckoutInstructions());489 }490 // add sales tax - US only491 if ($template->getUseSalesTax()) {492 $salesTax = $shippingDetails->addChild('SalesTax');493 $salesTax->addChild('SalesTaxState', $template->getSalesTaxState());494 $salesTax->addChild('SalesTaxPercent', $template->getSalesTaxPercent());495 $salesTax->addChild('ShippingIncludedInTax', $template->getShippingIncludedInTax());496 }497 $domesticServices = $template->getDomesticShippingServices();498 $domesticSettings = $template->getDomesticShippingSettings();499 if (empty($domesticSettings)) {500 throw new Exception('Missing domestic shipping settings');501 }502 // add a pickup service - can't get this to work gives error: ShippingService is required if Insurance, SalesTax, or AutoPay is specified. (10019)503 if ($domesticSettings['offer_pickup']) {504 $domesticServices['Pickup'] = array(505 'additional_cost' => 0,506 'cost' => 0 //(double)$domesticServices['pickup_cost'] // where has this option gone?507 );508 }509 if (empty($domesticServices)) {510 throw new Exception('Missing domestic shipping services');511 }512 $domesticFeeShipping = (bool)$domesticSettings['is_free_shipping'];513 // add our domestic services514 self::addShippingServices($shippingDetails, $domesticSettings, $domesticServices, 'ShippingServiceOptions', $domesticFeeShipping);515 // buy it fast enabled? domestic only516 if ($domesticSettings['get_it_fast']) {517 $item->addChild('GetItFast', true);518 $item->addChild('DispatchTimeMax', 1); // required for getitfast519 }520 else {521 // add handling time522 $item->addChild('DispatchTimeMax', $template->getHandlingTime());523 }524 if ($domesticSettings['cost_type'] == 'Calculated') {525 if ($calculatedRate == null) {526 $calculatedRate = self::addCalculatedDetails($shippingDetails, $template);527 }528 // handling cost529 if ($domesticSettings['handling_cost']) {530 $calculatedRate->addChild('PackagingHandlingCosts', $domesticSettings['handling_cost']);531 }532 }533 // international shipping - we can't supply international services if we don't specify domestic534 if ($template->getUseInternationalShipping()) {535 $internationalSettings = $template->getInternationalShippingSettings();536 $internationalServices = $template->getInternationalShippingServices();537 if (empty($internationalSettings)) {538 throw new Exception('Missing international shipping settings');539 }540 if (empty($internationalServices)) {541 throw new Exception('Missing international shipping services');542 }543 // add our international services544 self::addShippingServices($shippingDetails, $internationalSettings, $internationalServices, 'InternationalShippingServiceOption', false, true);545 if ($internationalSettings['cost_type'] == 'Calculated') {546 if ($calculatedRate == null) {547 $calculatedRate = self::addCalculatedDetails($shippingDetails, $template);548 }549 // handling cost550 if ($internationalSettings['handling_cost']) {551 $calculatedRate->addChild('InternationalPackagingHandlingCosts', $internationalSettings['handling_cost']);552 }553 }554 }555 }556 else {557 // domestic pickup only558 $item->addChild('ShipToLocations', 'None');559 }560 }561 /**562 * Processes and adds shipping services to the XML element563 *564 * @param SimpleXMLElement $shippingDetails The referenced shipping details element to add shipping services into565 * @param array $shippingServices The shipping services to add566 * @param array $shippingSettings Associated shipping settings for the services567 * @param string $optionName The name of the XML element to add for each service568 * @param bool $freeShipping Should be free shipping be applied to the first service?569 * @param bool $addShipTo Adds the ship to location. Valid only for international.570 */571 private static function addShippingServices(&$shippingDetails, $shippingSettings, $shippingServices, $optionName, $freeShipping = false, $addShipTo = false)572 {573 $serviceCount = 0;574 foreach ($shippingServices as $serviceType => $service) {575 $shippingServiceOption = $shippingDetails->addChild($optionName);576 // free shipping can only be applied to the first service577 $shippingServiceOption->addChild('ShippingService', $serviceType);578 $shippingServiceOption->addChild('ShippingServicePriority', $serviceCount + 1);579 if ($freeShipping && $serviceCount == 0){580 $shippingServiceOption->addChild('FreeShipping', true);581 }582 elseif ($shippingSettings['cost_type'] == 'Flat') {583 $shippingServiceOption->addChild('ShippingServiceCost', (double)$service['cost']);584 $shippingServiceOption->addChild('ShippingServiceAdditionalCost', (double)$service['additional_cost']);585 }586 if ($addShipTo) {587 if (empty($service['ship_to_locations'])) {588 throw new Exception("Missing international ship to locations for service '" . $serviceType . "'.");589 }590 foreach ($service['ship_to_locations'] as $locationCode) {591 $shippingServiceOption->addChild('ShipToLocation', $locationCode);592 }593 }594 $serviceCount++;595 }596 }597 /**598 * Adds calculated rate details to the shipping details599 *600 * @param SimpleXMLElement $shippingDetails601 * @param ISC_ADMIN_EBAY_TEMPLATE $template602 * @return SimpleXMLElement603 */604 private static function addCalculatedDetails(&$shippingDetails, $template)605 {606 $calculatedRate = $shippingDetails->addChild('CalculatedShippingRate');607 $calculatedRate->addChild('MeasurementUnit', 'English');608 $calculatedRate->addChild('OriginatingPostalCode', $template->getItemLocationZip());609 // add dimensions - whole inches only610 $depth = round(ConvertLength($template->getItemDepth(), 'in'));611 $length = round(ConvertLength($template->getItemLength(), 'in'));612 $width = round(ConvertLength($template->getItemWidth(), 'in'));613 $depthXML = $calculatedRate->addChild('PackageDepth', $depth);614 $depthXML->addAttribute('measurementSystem', 'English');615 $depthXML->addAttribute('unit', 'in');616 $lengthXML = $calculatedRate->addChild('PackageLength', $length);617 $lengthXML->addAttribute('measurementSystem', 'English');618 $lengthXML->addAttribute('unit', 'in');619 $widthXML = $calculatedRate->addChild('PackageWidth', $width);620 $widthXML->addAttribute('measurementSystem', 'English');621 $widthXML->addAttribute('unit', 'in');622 //add weight in pounds and ounces623 $weightTotal = ConvertWeight($template->getItemWeight(), 'lbs');624 $weightMajor = floor($weightTotal);625 $weightMinor = ConvertWeight($weightTotal - $weightMajor, 'ounces', 'lbs');626 if ($weightMinor < 1) {627 $weightMinor = 1;628 }629 $calculatedRate->addChild('WeightMajor', $weightMajor);630 $calculatedRate->addChild('WeightMinor', $weightMinor);631 return $calculatedRate;632 }633 /**634 * Ends up to 10 items on eBay635 *636 * @param array $item The array of item contains item id and reason of ending637 * @return SimpleXMLElement The XML result of the AddItems request638 */639 public static function endItems($items)640 {641 $api = new ISC_ADMIN_EBAY_API();642 $xml = $api->getBaseXMLRequest('EndItems');643 foreach ($items as $item) {644 $itemContainer = $xml->addChild('EndItemRequestContainer');645 $itemContainer->addChild('MessageID', $item['Id']);646 if (!empty ($item['EndingReason'])) {647 $itemContainer->addChild('EndingReason', $item['EndingReason']);648 }649 $itemContainer->addChild('ItemID', $item['Id']);650 }651 return $api->DoRequest('EndItems', $xml);652 }653 /**654 * Ends a single item on eBay655 *656 * @param int $itemId The item id657 * @param string $itemId The reason of ending the listing658 * @return SimpleXMLElement The XML result of the AddItems request659 */660 public static function endItem($itemId, $endingReason)661 {662 $api = new ISC_ADMIN_EBAY_API();663 $xml = $api->getBaseXMLRequest('EndItem');664 $xml->addChild('MessageID', $itemId);665 $xml->addChild('EndingReason', $endingReason);666 $xml->addChild('ItemID', $itemId);667 return $api->DoRequest('EndItem', $xml);668 }669 /**670 * Get the order transaction for item sold671 *672 * @param int $orderId The ID of the order673 * @return SimpleXMLElement The XML result of the GetOrderTransactions request674 */675 public static function getOrderTransactions($orderId)676 {677 $api = new ISC_ADMIN_EBAY_API();678 $xml = $api->getBaseXMLRequest('GetOrderTransactions');679 $orderIDArray = $xml->addChild('OrderIDArray');680 $orderIDArray->addChild('OrderID', $orderId);681 return $api->DoRequest('GetOrderTransactions', $xml);682 }683}...
Facebook.php
Source:Facebook.php
...85 {86 $feedwriter = new FeedWriter();87 $filename = $feedwriter->generateFileName($this->channel_feed->id,'xml');88 $listings = new \SimpleXMLElement('<listings></listings>');89 $listings->addChild('title',$this->channel_feed->name);90 $link = $listings->addChild('link',DFBUILDER_MAIN_WEBSITE_URL.'download/'.DFBUILDER_CHANNEL_FOLDER.'/'.$filename);91 $link->addAttribute('rel','self');92 if(count($results) > 0 ) {93 foreach($results as $generated_id=>$source) {94 $item = $listings->addChild('listing');95 if($this->detectAdress($mapping_template)) {96 $address = $item->addChild('address');97 $address->addAttribute('format','simple');98 }99 foreach ($mapping_template as $mapping_value) {100 switch ($mapping_value->channel_field_name) {101 case 'image_link':102 $imagelink = $item->addChild('image');103 $imagelink->addChild('link',$this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]));104 break;105 default:106 $item->addChild($mapping_value->channel_field_name,$this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]));107 }108 }109 if(count($custom_fields) > 0) {110 foreach($custom_fields as $custom_field) {111 if(isset($source['_source'][$custom_field->field_name])) {112 $item->addChild(MappingValidator::formatMapping($custom_field->custom_field_name),$this->sanitizeSimpleXmlNodes($source['_source'][$custom_field->field_name]));113 }114 }115 }116 }117 }118 return $listings->asXML();119 }120 protected function buildHotelFeed($results, $mapping_template, $custom_fields = [], $repeating_node = 'products', $append_childs = [],$root_node=null)121 {122 $listings = new \SimpleXMLElement('<listings></listings>');123 if(count($results) > 0 ) {124 foreach($results as $generated_id=>$source) {125 $item = $listings->addChild('listing');126 $rating = null;127 $address = null;128 if($this->detectRating($mapping_template)) {129 $rating = $item->addChild('guest_ratings',null);130 }131 if($this->detectAdress($mapping_template)) {132 $address = $item->addChild('address');133 $address->addAttribute('format','simple');134 }135 foreach ($mapping_template as $mapping_value) {136 switch ($mapping_value->channel_field_name) {137 case 'guest_ratings-number_of_reviewers':138 case 'guest_ratings-rating_system':139 case 'guest_ratings-rating_score':140 $rating->addChild($mapping_value->channel_field_name,$this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]));141 break;142 case 'addr1':143 case 'city':144 case 'country':145 case 'postal_code':146 case 'region':147 $component = $address->addChild('component',$this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]));148 $component->addAttribute('name',$mapping_value->channel_field_name);149 break;150 case 'image_link':151 $imagelink = $item->addChild('image');152 $imagelink->addChild('link',$this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]));153 break;154 default:155 $item->addChild($mapping_value->channel_field_name,$this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]));156 }157 }158 if(count($custom_fields) > 0) {159 foreach($custom_fields as $custom_field) {160 if(isset($source['_source'][$custom_field->field_name])) {161 $item->addChild(MappingValidator::formatMapping($custom_field->custom_field_name),$this->sanitizeSimpleXmlNodes($source['_source'][$custom_field->field_name]));162 }163 }164 }165 }166 }167 return $listings->asXML();168 }169 /**170 * @param $results171 * @param $mapping_template172 * @param array $custom_fields173 * @param string $repeating_node174 * @param array $append_childs175 * @return mixed176 */177 protected function buildFeed($results, $mapping_template, $custom_fields = [], $repeating_node = 'products', $append_childs = [],$root_node=null)178 {179 $feedwriter = new FeedWriter();180 $filename = $feedwriter->generateFileName($this->channel_feed->id,'xml');181 $rss = new \SimpleXMLElement('<'.$this->root_node.' version="2.0" xmlns:g="http://base.google.com/ns/1.0"></'.$this->root_node.'>');182 $channel = $rss->addChild('channel');183 $channel->addChild('title',$this->channel_feed->name);184 $channel->addChild('description',$this->channel_feed->name);185 $channel->addChild('pubDate',date("D M j G:i:s"));186 $channel->addChild('link',DFBUILDER_MAIN_WEBSITE_URL.'download/'.DFBUILDER_CHANNEL_FOLDER.'/'.$filename);187 if(count($results) > 0 ) {188 foreach($results as $generated_id=>$source) {189 $item = $channel->addChild($repeating_node);190 foreach ($mapping_template as $mapping_value) {191 switch ($mapping_value->channel_field_name) {192 case 'link':193 case 'title':194 $item->addChild($mapping_value->channel_field_name,$this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]));195 break;196 default:197 $item->addChild($mapping_value->channel_field_name,$this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]));198 }199 }200 if(count($custom_fields) > 0) {201 foreach($custom_fields as $custom_field) {202 if(isset($source['_source'][$custom_field->field_name])) {203 $item->addChild(MappingValidator::formatMapping($custom_field->custom_field_name),$this->sanitizeSimpleXmlNodes($source['_source'][$custom_field->field_name]));204 }205 }206 }207 }208 }209 return $rss->asXML();210 }211 /**212 * @return mixed213 */214 public function buildChannel()215 {216 switch($this->channel_feed->fk_channel_type_id) {217 case 45:...
Bazaavoice.php
Source:Bazaavoice.php
...50 protected function buildFeed($results, $mapping_template, $custom_fields = [], $repeating_node = 'products', $append_childs = [],$root_node=null)51 {52 $feed = new \SimpleXMLElement('<'.$this->root_node.' xmlns="http://www.bazaarvoice.com/xs/PRR/ProductFeed/5.6" name="beslist" 53 incremental="false" extractDate="'.gmdate(DATE_ATOM,time()).'"></'.$this->root_node.'>');54 $products = $feed->addChild('Products');55 if(count($results) > 0 ) {56 $brands = [];57 $categories = [];58 /**59 * first save the brands and categories60 */61 foreach ($results as $generated_id => $source) {62 foreach ($this->mapping_template as $mapping_value) {63 if (isset($source['_source'][$mapping_value->channel_field_name])) {64 if($mapping_value->channel_field_name == 'Brand') {65 $brands[] = $source['_source'][$mapping_value->channel_field_name];66 }67 if($mapping_value->channel_field_name == 'Category') {68 $categories[] = $source['_source'][$mapping_value->channel_field_name];69 }70 }71 }72 }73 $categories = array_unique($categories);74 $brands = array_unique($brands);75 /**76 * Set brands node77 */78 $brand_ids = [];79 if(count($brands) > 0 ) {80 $brands_node = $feed->addChild("Brands");81 $brand_counter = 1;82 foreach ($brands as $b) {83 $brand_node = $brands_node->addChild('Brand');84 $brand_node->addChild('ExternalId', $brand_counter);85 $brand_node->addChild('Name', $b);86 $brand_ids[$b] = $brand_counter;87 $brand_counter++;88 }89 }90 /**91 * Set categories node92 */93 $cat_ids =[];94 if(count($categories) > 0 ) {95 $categories_node = $feed->addChild("Categories");96 $category_counter = 1;97 foreach ($categories as $c) {98 $category_node = $categories_node->addChild('Category');99 $category_node->addChild('ExternalId', $category_counter);100 $category_node->addChild('Name', $c);101 $cat_ids[$c] = $category_counter;102 $category_counter++;103 }104 }105 foreach ($results as $generated_id => $source) {106 $product = $products->addChild('Product');107 foreach ($this->mapping_template as $mapping_value) {108 /**109 * Brand id110 */111 if($mapping_value->channel_field_name == 'Brand') {112 $brand_search = array_search($source['_source'][$mapping_value->channel_field_name],$brands);113 if($brand_search !== false ){114 if(isset($brand_ids[$brands[$brand_search]])) {115 $product->addChild('BrandExternalId',$brand_ids[$brands[$brand_search]]);116 }117 }118 continue;119 }120 /**121 * Category id122 */123 if($mapping_value->channel_field_name == 'Category' ) {124 $category_search = array_search($source['_source'][$mapping_value->channel_field_name],$cat_ids);125 if(isset($cat_ids[$categories[$category_search]])) {126 $product->addChild('CategoryExternalId',$cat_ids[$categories[$category_search]]);127 }128 continue;129 }130 if (isset($source['_source'][$mapping_value->channel_field_name])) {131 $field_value = $this->sanitizeSimpleXmlNodes($source['_source'][$mapping_value->channel_field_name]);132 switch($mapping_value->channel_field_name ) {133 case 'EAN':134 $eans = $product->addChild('EANs');135 $eans->addChild('EAN',$field_value);136 break;137 case 'ISBN':138 $isbn = $product->addChild('ISBNs');139 $isbn->addChild('ISBN',$field_value);140 break;141 case 'ManufacturerPartNumber':142 $ManufacturerPartNumber = $product->addChild('ManufacturerPartNumbers');143 $ManufacturerPartNumber->addChild('ManufacturerPartNumber',$field_value);144 break;145 case 'ModelNumber':146 $ModelNumbers = $product->addChild('ModelNumbers');147 $ModelNumbers->addChild('ModelNumber',$field_value);148 break;149 case 'UPC':150 $UPCS = $product->addChild('UPCs');151 $UPCS->addChild('UPC',$field_value);152 break;153 default:154 $product->addChild($mapping_value->channel_field_name, $field_value);155 }156 }157 }158 /**159 * Custom velden toevoegen..160 */161 if(count($custom_fields) > 0) {162 $fields = $product->addChild('Attributes');163 foreach($custom_fields as $custom_field) {164 $field = $fields->addChild('Attribute');165 $field->addAttribute("id",$custom_field->field_name);166 if(isset($source['_source'][$custom_field->field_name])) {167 $field->addAttribute('name',$custom_field->custom_field_name);168 $field->addAttribute('value',$this->sanitizeSimpleXmlNodes($source['_source'][$custom_field->field_name]));169 }170 }171 }172 }173 }174 return $feed->asXML();175 }176 /**177 * @return string178 */...
addChild
Using AI Code Generation
1$myTemplate->addChild('child1', 'child1.html');2$myTemplate->addChild('child2', 'child2.html');3$myTemplate->addChild('child3', 'child3.html');4$myTemplate->assign('var1', 'value1');5$myTemplate->assign('var2', 'value2');6$myTemplate->assign('var3', 'value3');7$myTemplate->parse('main', 'main.html');8$myTemplate->parse('child1', 'child1.html');9$myTemplate->parse('child2', 'child2.html');10$myTemplate->parse('child3', 'child3.html');11$myTemplate->parseParent('main', 'child1');12$myTemplate->parseParent('main', 'child2');13$myTemplate->parseParent('main', 'child3');14$myTemplate->parseChild('child1', 'main');15$myTemplate->parseChild('child2', 'main');16$myTemplate->parseChild('child3', 'main');17$myTemplate->show('main');18$myTemplate->assign('var1', 'value1');19$myTemplate->assign('var2', 'value2');20$myTemplate->assign('var3', 'value3');21$myTemplate->parse('main', 'main.html');22$myTemplate->show('main');23$myTemplate->assign('var1', 'value1');
addChild
Using AI Code Generation
1$myTemplate->addChild($myTemplate2, 'myTemplate2');2$myTemplate->addChild($myTemplate3, 'myTemplate3');3$myTemplate->addChild($myTemplate4, 'myTemplate4');4$myTemplate->addChild($myTemplate5, 'myTemplate5');5$myTemplate->addChild($myTemplate6, 'myTemplate6');6$myTemplate->addChild($myTemplate7, 'myTemplate7');7$myTemplate->addChild($myTemplate8, 'myTemplate8');8$myTemplate->addChild($myTemplate9, 'myTemplate9');9$myTemplate->addChild($myTemplate10, 'myTemplate10');10$myTemplate->addChild($myTemplate11, 'myTemplate11');11$myTemplate->addChild($myTemplate12, 'myTemplate12');12$myTemplate->addChild($myTemplate13, 'myTemplate13');13$myTemplate->addChild($myTemplate14, 'myTemplate14');14$myTemplate->addChild($myTemplate15, 'myTemplate15');15$myTemplate->addChild($myTemplate16, 'myTemplate16');16$myTemplate->addChild($myTemplate17, 'myTemplate17');
addChild
Using AI Code Generation
1$t->addChild('child1','child1.tpl');2$t->addChild('child2','child2.tpl');3$t->addChild('child3','child3.tpl');4$t->addChild('child4','child4.tpl');5$t->addChild('child5','child5.tpl');6$t->addChild('child6','child6.tpl');7$t->addChild('child7','child7.tpl');8$t->addChild('child8','child8.tpl');9$t->addChild('child9','child9.tpl');10$t->addChild('child10','child10.tpl');11$t->addChild('child11','child11.tpl');12$t->addChild('child12','child12.tpl');13$t->addChild('child13','child13.tpl');14$t->addChild('child14','child14.tpl');15$t->addChild('child15','child15.tpl');16$t->addChild('child16','child16.tpl');17$t->addChild('child17','child17.tpl');18$t->addChild('child18','child18.tpl');19$t->addChild('child19','child19.tpl');20$t->addChild('child20','child20.tpl');21$t->addChild('child21','child21.tpl');22$t->addChild('child22','child22.tpl');23$t->addChild('child23','child23.tpl');24$t->addChild('child24','child24.tpl');25$t->addChild('child25','child25.tpl');26$t->addChild('child26','child26.tpl');27$t->addChild('child27','child27.tpl');28$t->addChild('child28','child28.tpl');29$t->addChild('child29','child29.tpl');30$t->addChild('child30','child30.tpl');31$t->addChild('child31','child31.tpl');32$t->addChild('child32','child32.tpl');33$t->addChild('child33','child33.tpl');34$t->addChild('child34','child34.tpl');35$t->addChild('child35','child35.tpl');36$t->addChild('child36','child36.tpl');37$t->addChild('child37','child37.tpl');38$t->addChild('child38','child38.tpl');39$t->addChild('child39','child39.tpl');40$t->addChild('child40','child40.tpl');41$t->addChild('child41','child41.tpl');42$t->addChild('child42','child42.tpl');43$t->addChild('child43','child43.tpl');44$t->addChild('child44','child44.tpl');
addChild
Using AI Code Generation
1$tmpl->addChild('child','child.html');2$tmpl->displayParsedTemplate('child');3$tmpl->addChild('child2','child2.html');4$tmpl->displayParsedTemplate('child2');5$tmpl->addChild('child3','child3.html');6$tmpl->displayParsedTemplate('child3');7$tmpl->addChild('child4','child4.html');8$tmpl->displayParsedTemplate('child4');9$tmpl->addChild('child5','child5.html');10$tmpl->displayParsedTemplate('child5');11$tmpl->addChild('child6','child6.html');12$tmpl->displayParsedTemplate('child6');13$tmpl->addChild('child7','child7.html');14$tmpl->displayParsedTemplate('child7');15$tmpl->addChild('child8','child8.html');16$tmpl->displayParsedTemplate('child8');17$tmpl->addChild('child9','child9.html');18$tmpl->displayParsedTemplate('child9');19$tmpl->addChild('child10','child10.html');20$tmpl->displayParsedTemplate('child10');21$tmpl->addChild('child11','child11.html');22$tmpl->displayParsedTemplate('child11');
addChild
Using AI Code Generation
1$tmpl->addChild("child", "child.html");2$tmpl->parse("main", "main.html");3$tmpl->parse("child", "child.html");4$tmpl->parse("child", "child.html");5$tmpl->parse("child", "child.html");6$tmpl->parse("child", "child.html");7$tmpl->parse("child", "child.html");8$tmpl->parse("child", "child.html");9$tmpl->parse("child", "child.html");10$tmpl->parse("child", "child.html");11$tmpl->parse("child", "child.html");12$tmpl->parse("child", "child.html");13$tmpl->parse("child", "child.html");14$tmpl->parse("child", "child.html");15$tmpl->parse("child", "child.html");16$tmpl->parse("child", "child.html");17$tmpl->parse("child", "child.html");18$tmpl->parse("child", "child.html");
addChild
Using AI Code Generation
1$child = $template->addChild('child');2$child->setTemplateFile('child.php');3$child->assign('name','child template');4$child->display();5$child = $template->addChild('child');6$child->setTemplateFile('child.php');7$child->assign('name','child template');8$child->display();9$child = $template->addChild('child');10$child->setTemplateFile('child.php');11$child->assign('name','child template');12$child->display();13$child = $template->addChild('child');14$child->setTemplateFile('child.php');15$child->assign('name','child template');16$child->display();17$child = $template->addChild('child');18$child->setTemplateFile('child.php');19$child->assign('name','child template');20$child->display();21$child = $template->addChild('child');22$child->setTemplateFile('child.php');23$child->assign('name','child template');24$child->display();25$child = $template->addChild('child');26$child->setTemplateFile('child.php');27$child->assign('name','child template');28$child->display();29$child = $template->addChild('child');30$child->setTemplateFile('child.php');31$child->assign('name','child template');32$child->display();33$child = $template->addChild('child');34$child->setTemplateFile('child.php');35$child->assign('name','child template');36$child->display();37$child = $template->addChild('child');38$child->setTemplateFile('child.php');39$child->assign('name','child template');40$child->display();
addChild
Using AI Code Generation
1$parent = new Template("parent.html");2$child = new Template("child.html");3$parent->addChild($child,"child");4$parent->display();5{child}6$parent->addChild($child1,"child1")->addChild($child2,"child2");7$parent = new Template("parent.html");8$child1 = new Template("child1.html");9$child2 = new Template("child2.html");10$parent->addChild($child1,"child1")->addChild($child2,"child2");
addChild
Using AI Code Generation
1$child = $root->addChild('child');2$child->addChild('text','Hello');3$child->addChild('child2');4$child->addChild('child3');5$child->addChild('child4');6$child->addChild('child5');7$child->addChild('child6');8$child->addChild('child7');9$child->addChild('child8');10$child->addChild('child9');11$child->addChild('child10');12$child->addChild('child11');13$child->addChild('child12');14$child->addChild('child13');15$child->addChild('child14');16$child->addChild('child15');17$child->addChild('child16');18$child->addChild('child17');19$child->addChild('child18');20$child->addChild('child19');21$child->addChild('child20');22$child->addChild('child21');23$child->addChild('child22');24$child->addChild('child23');25$child->addChild('child24');26$child->addChild('child25');27$child->addChild('child26');28$child->addChild('child27');29$child->addChild('child28');30$child->addChild('child29');31$child->addChild('child30');32$child->addChild('child31');33$child->addChild('child32');34$child->addChild('child33');35$child->addChild('child34');
addChild
Using AI Code Generation
1$tpl = new Template("1.tpl");2$newNode = $tpl->addChild("newNode","new node value");3$tpl->addNode($newNode);4$tpl->display();5$tpl = new Template("1.tpl");6$newNode = $tpl->addChild("newNode","new node value");7$tpl->addNode($newNode);8$tpl->display();
addChild
Using AI Code Generation
1$tpl = new template('template1.xml');2$tpl->addChild('name', 'John Smith');3$tpl->display();4$tpl = new template('template2.xml');5$tpl->addChild('name', 'John Smith');6$tpl->display();7$tpl = new template('template3.xml');8$tpl->addChild('name', 'John Smith');9$tpl->display();10$tpl = new template('template4.xml');11$tpl->addChild('name', 'John Smith');12$tpl->display();13$tpl = new template('template5.xml');14$tpl->addChild('name', 'John Smith');15$tpl->display();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with addChild on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!