Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use App\Ebay\EBaySessionProduct;
- class EbayImportProducts extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'ebay:importproducts';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Import your Products into Ebay';
- const IMAGE_UPLOAD_STATUS = '5';
- const IMPORT_PRODUCT_NO_XML_RESPONSE_STATUS = '6';
- const IMPORT_PRODUCT_EBAY_ERROR_STATUS = '7';
- const EBAY_VERB = 'AddFixedPriceItem';
- const EBAY__REVISE_VERB = 'ReviseFixedPriceItem';
- const EBAY_CATEGORY_SPECIFIC_VERB = 'GetCategorySpecifics';
- const EBAY_CATEGORY_FEATURES_VERB = 'GetCategoryFeatures';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- public function register()
- {
- $this->app->bind(
- 'EBaySessionProduct',
- function () {
- return new EBaySessionProduct;
- }
- );
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $variation_items =
- $matrix =
- $fee =
- $feeName =
- $fee_array =
- $color_variations =
- $color_variations_sort_arr = array();
- $verb = EbayImportProducts::EBAY_VERB;
- $verbRevise = EbayImportProducts::EBAY__REVISE_VERB;
- $category_verb = EbayImportProducts::EBAY_CATEGORY_SPECIFIC_VERB;
- $category_features_verb = EbayImportProducts::EBAY_CATEGORY_FEATURES_VERB;
- $devID = config('ebay.Dev_ID');
- $appID = config('ebay.App_ID');
- $certID = config('ebay.Cert_ID');
- $comp_version = config('ebay.COMPATIBILITY_LEVEL');
- $ebay_server_url = config('ebay.SERVER_URL');
- $getadmindata = DB::table('tbl_admin_ebay_setting')->first();
- $import_designer_id = $getadmindata->ebay_designer_import_product_id;
- $import_products = DB::table('tbl_ebay_products')
- ->join('tbl_magento_products', 'tbl_ebay_products.mage_pid', '=', 'tbl_magento_products.mp_pid')
- ->join('tbl_products', 'tbl_ebay_products.magento_id', '=', 'tbl_products.mage_pid')
- ->whereNull('tbl_ebay_products.cron_error')
- ->select('tbl_ebay_products.*', 'tbl_magento_products.*', 'tbl_products.designer_id')
- ->where([
- ['tbl_products.processed_status', '=', 1],
- ['tbl_products.for_ebay', '=', 1],
- ['tbl_products.product_status', '=', '1'],
- ['tbl_products.designer_id', '=', $import_designer_id]
- ])
- ->whereIn(
- 'tbl_ebay_products.product_ebay_status',
- array(
- EbayImportProducts::IMAGE_UPLOAD_STATUS,
- EbayImportProducts::IMPORT_PRODUCT_NO_XML_RESPONSE_STATUS,
- EbayImportProducts::IMPORT_PRODUCT_EBAY_ERROR_STATUS
- )
- )
- ->offset(0)->limit(1)
- ->groupBy('tbl_magento_products.mp_pid')
- ->orderBy('tbl_magento_products.mp_pid', 'asc')
- ->get();
- //echo "<pre>";print_r($import_products);exit;
- foreach ($import_products as $import_product) {
- try {
- $designer_general_settings = \App\Designer::where(
- 'designer_id',
- '=',
- $import_product->designer_id
- )->first();
- if ($designer_general_settings['is_ebay_shirtee_api_on'] == 1) {
- $cronName = \App\Constants::CRON_EBAY['IMPORT_PRODUCTS'];
- $cronExist = \App\CronDetail::where('cron_name', $cronName)->first();
- if ($cronExist) {
- $startDate = date('Y-m-d H:i:s');
- }
- $variation_items = (json_decode($import_product->mp_options));
- $import_product_data = (json_decode($import_product->mp_data));
- // Product Description
- if (!empty($import_product_data->description)
- && strlen($import_product_data->description) > 0
- && $import_product_data->description != '') {
- $product_description = $import_product_data->description;
- } else {
- $product_description = $import_product_data->short_description;
- }
- $product_sku = $import_product->mp_sku;
- $sku_want = substr($product_sku, strpos($product_sku, "_") + 1);
- $primary_category_id = \App\EbayBrowseData::where([
- ['sku', '=', $sku_want],
- ['language', '=', 4]
- ])->first();
- // Send mail and error log if category id not assigned
- if (empty($primary_category_id) && $primary_category_id == '') {
- $no_category_error = "Ebay Require that product assigned for atleast one category.
- But Below product have no category.
- please assign product's primary category from admin for below product ID: \n";
- $no_category_error .= "Product ID = $import_product->magento_id
- Product SKU = $import_product->mp_sku
- SKU in Browse Data Table = $sku_want";
- \Mail::raw(
- $no_category_error,
- function ($message) {
- ->subject('Product Have No Primary Category - Ebay Import Product Error');
- }
- );
- \Log::channel('ebay')->error('This Product have no Primary Category : Product ID -'
- . $import_product->magento_id.' Product SKU = '.$import_product->mp_sku.'
- SKU in Browse node table = '.$sku_want);
- \App\EbayListProduct::where(
- 'magento_id',
- $import_product->magento_id
- )->update(['cron_error' => '']);
- continue;
- }
- $ebay_category_id = $primary_category_id->node1;
- //echo "<pre>";print_r(count($variation_items[0]->additional_fields));exit;
- if (isset($variation_items[0]) && isset($variation_items[1])) {
- if ((count($variation_items[0]->additional_fields) > 0)
- && (count($variation_items[1]->additional_fields) > 0)) {
- $ebay_setting = \App\EbaySetting::where(
- 'designer_id',
- '=',
- $import_product->designer_id
- )->first();
- //echo "<pre>";print_r($ebay_setting);exit;
- if (isset($ebay_setting->max_dispatch_time)
- && $ebay_setting->max_dispatch_time != null
- && $ebay_setting->max_dispatch_time != '') {
- $max_dispatch_time = $ebay_setting->max_dispatch_time;
- } else {
- $max_dispatch_time = 7;
- }
- if (isset($ebay_setting->item_location)
- && $ebay_setting->item_location != null
- && $ebay_setting->item_location != '') {
- $item_location = $ebay_setting->item_location;
- } else {
- $item_location = 'Köln';
- }
- if (isset($ebay_setting->item_postcode)
- && $ebay_setting->item_postcode != null
- && $ebay_setting->item_postcode != '') {
- $item_postcode = $ebay_setting->item_postcode;
- } else {
- $item_postcode = 50827;
- }
- if (isset($ebay_setting->item_postcode)
- && $ebay_setting->item_postcode != null
- && $ebay_setting->item_postcode != '') {
- $item_postcode = $ebay_setting->item_postcode;
- } else {
- $item_postcode = 50827;
- }
- if (isset($ebay_setting->brand_name)
- && $ebay_setting->brand_name != null
- && $ebay_setting->brand_name != '') {
- $brand_name = $ebay_setting->brand_name;
- } else {
- $brand_name = 'Shirtee';
- }
- $siteID = $ebay_setting->ebay_site_id;
- $paymentProfileLists = new \App\EbayPaymentPolicy;
- $paymentProfileList = $paymentProfileLists->where(
- 'designer_id',
- $import_product->designer_id
- )->where('is_used', '=', 1)->first();
- $returnProfileLists = new \App\EbayRetunPolicy;
- $returnProfileList = $returnProfileLists->where(
- 'designer_id',
- $import_product->designer_id
- )->where('is_used', '=', 1)->first();
- $shippingProfileLists = new \App\EbayShippingPolicy;
- $shippingProfileList = $shippingProfileLists->where(
- 'designer_id',
- $import_product->designer_id
- )->where('is_used', '=', 1)->first();
- //$ebayhelper = new \App\Helpers\EbayHelper();
- //$ebaysettings = $ebayhelper->setEbaySettings($ebay_setting['0']->mode,$ebay_setting['0']->compatability_level,$ebay_setting['0']->paypal_email_address,$ebay_setting['0']->production_app_id,$ebay_setting['0']->production_dev_id,$ebay_setting['0']->production_cert_id,$ebay_setting['0']->production_user_tocken);
- $ebaycategoryspecifics = $this->getCategorySpecifics(
- $ebay_category_id,
- $ebay_setting,
- $siteID,
- $category_verb
- );
- $ebayeanenabled = $this->getCategoryFeatures(
- $ebay_category_id,
- $ebay_setting,
- $siteID,
- $category_features_verb
- );
- ///Build the request Xml string
- $dom = new \DOMDocument();
- $dom->encoding = 'utf-8';
- $dom->xmlVersion = '1.0';
- $dom->formatOutput = true;
- if ($import_product->product_ebay_id) {
- $root = $dom->createElementNS(
- 'urn:ebay:apis:eBLBaseComponents',
- 'ReviseFixedPriceItemRequest'
- );
- } else {
- $root = $dom->createElementNS(
- 'urn:ebay:apis:eBLBaseComponents',
- 'AddFixedPriceItemRequest'
- );
- }
- $request_node = $dom->createElement('RequesterCredentials');
- $ebay_auth = $dom->createElement(
- 'eBayAuthToken',
- $ebay_setting->production_user_tocken
- );
- $request_node->appendChild($ebay_auth);
- $root->appendChild($request_node);
- $detail_node = $dom->createElement('DetailLevel', 'ReturnAll');
- $root->appendChild($detail_node);
- $err_lang_node = $dom->createElement('ErrorLanguage', 'en_US');
- $root->appendChild($err_lang_node);
- $war_level_node = $dom->createElement('WarningLevel', 'High');
- $root->appendChild($war_level_node);
- $ver_node = $dom->createElement('Version', $comp_version);
- $root->appendChild($ver_node);
- /* Item Node start*/
- $item_node = $dom->createElement('Item');
- $itemId = $dom->createElement('ItemID', $import_product->product_ebay_id);
- $item_node->appendChild($itemId);
- $country = $dom->createElement('Country', $ebay_setting->ebay_country_code);
- $item_node->appendChild($country);
- $currency = $dom->createElement('Currency', $ebay_setting->ebay_currency);
- $item_node->appendChild($currency);
- $description = $dom->createElement('Description');
- $description_cdata = $dom->createCDATASection(trim($product_description));
- $description->appendChild($description_cdata);
- $item_node->appendChild($description);
- $dispatch_time = $dom->createElement('DispatchTimeMax', $max_dispatch_time);
- $item_node->appendChild($dispatch_time);
- $listing_duration = $dom->createElement('ListingDuration', 'GTC');
- $item_node->appendChild($listing_duration);
- $listing_type = $dom->createElement('ListingType', 'FixedPriceItem');
- $item_node->appendChild($listing_type);
- $location = $dom->createElement('Location', $item_location);
- $item_node->appendChild($location);
- $paymentmethods1 = $dom->createElement('PaymentMethods', 'CashOnPickup');
- $item_node->appendChild($paymentmethods1);
- if (isset($ebay_setting->paypal_email_address)
- && $ebay_setting->paypal_email_address != null
- && $ebay_setting->paypal_email_address != '') {
- $paymentmethods = $dom->createElement('PaymentMethods', 'PayPal');
- $item_node->appendChild($paymentmethods);
- $paypal_email = $dom->createElement(
- 'PayPalEmailAddress',
- $ebay_setting->paypal_email_address
- );
- $item_node->appendChild($paypal_email);
- }
- $post_code = $dom->createElement('PostalCode', $item_postcode);
- $item_node->appendChild($post_code);
- $primary_category = $dom->createElement('PrimaryCategory');
- $category_id = $dom->createElement('CategoryID', $ebay_category_id);
- $primary_category->appendChild($category_id);
- $item_node->appendChild($primary_category);
- /*$product_listing_details = $dom->createElement('ProductListingDetails');
- $product_ean = $dom->createElement('EAN','6219595798795');
- $product_listing_details->appendChild($product_ean);
- $item_node->appendChild($product_listing_details);*/
- /*$seller_profile = $dom->createElement('SellerProfiles');
- $seller_payment_profile = $dom->createElement('SellerPaymentProfile');
- $seller_profile->appendChild($seller_payment_profile);
- $seller_payment_profile->appendChild($payment_profile_id);
- $seller_payment_profile->appendChild($payment_profile_name);
- $seller_return_profile = $dom->createElement('SellerReturnProfile');
- $seller_profile->appendChild($seller_return_profile);
- $seller_return_profile->appendChild($retun_profile_id);
- $seller_return_profile->appendChild($return_profile_name);
- $seller_shipping_profile = $dom->createElement('SellerShippingProfile');
- $seller_profile->appendChild($seller_shipping_profile);
- $seller_shipping_profile->appendChild($shipping_profile_id);
- $seller_shipping_profile->appendChild($shipping_profile_name);
- $item_node->appendChild($seller_profile);*/
- $title = $dom->createElement(
- 'Title',
- htmlspecialchars($import_product->mp_name)
- );
- $item_node->appendChild($title);
- $condition = $dom->createElement('ConditionID', 1000);
- $item_node->appendChild($condition);
- //$pictures = $dom->createElement('PictureDetails');
- $ebay_images_array = unserialize($import_product->ebay_image_urls);
- $main_search_picture_details = $dom->createElement('PictureDetails');
- $picture_gallery_duration = $dom->createElement('GalleryDuration', 'Days_7');
- $main_search_picture_details->appendChild($picture_gallery_duration);
- $picture_gallery_type = $dom->createElement('GalleryType', 'Gallery');
- $main_search_picture_details->appendChild($picture_gallery_type);
- $picture_photo_display = $dom->createElement('PhotoDisplay', 'SuperSize');
- $main_search_picture_details->appendChild($picture_photo_display);
- $picture_source = $dom->createElement('PictureSource', 'EPS');
- $main_search_picture_details->appendChild($picture_source);
- $picture_search_url = $dom->createElement(
- 'PictureURL',
- $ebay_images_array['0']['0']
- );
- $main_search_picture_details->appendChild($picture_search_url);
- $item_node->appendChild($main_search_picture_details);
- /*for ($i = 0; $i < $length; $i++) {
- $picture_url = $dom->createElement('PictureURL', $ebay_images_array[$i]['0']);
- $pictures->appendChild($picture_url);
- }
- $item_node->appendChild($pictures);*/
- $returnpolicy = $dom->createElement('ReturnPolicy');
- //$refundoption = $dom->createElement('RefundOption','MoneyBack');
- $returns_accepted_option = $dom->createElement(
- 'ReturnsAcceptedOption',
- 'ReturnsAccepted'
- );
- $returns_within_option = $dom->createElement('ReturnsWithinOption', 'Days_30');
- $shipping_cost_paid = $dom->createElement('ShippingCostPaidByOption', 'Seller');
- //$returnpolicy->appendChild($refundoption);
- $returnpolicy->appendChild($returns_accepted_option);
- $returnpolicy->appendChild($returns_within_option);
- $returnpolicy->appendChild($shipping_cost_paid);
- $item_node->appendChild($returnpolicy);
- $shippingdetails = $dom->createElement('ShippingDetails');
- /*$salestax = $dom->createElement('SalesTax');
- $salestax_per = $dom->createElement('SalesTaxPercent','8.5');
- $salestaxstate = $dom->createElement('SalesTaxState','CA');
- $salestax->appendChild($salestax_per);
- $salestax->appendChild($salestaxstate);
- $shippingdetails->appendChild($salestax);*/
- $shippingtype = $dom->createElement('ShippingType', 'Flat');
- $shippingdetails->appendChild($shippingtype);
- $shippingserviceoptions = $dom->createElement('ShippingServiceOptions');
- $shippingservicepriority = $dom->createElement('ShippingServicePriority', '1');
- $shippingservice = $dom->createElement('ShippingService', 'DE_DHLPaket');
- $shippingservicecost = $dom->createElement('ShippingServiceCost', '0.0');
- $attr_cost_currency = new \DOMAttr('currencyID', $ebay_setting->ebay_currency);
- $shippingservicecost->setAttributeNode($attr_cost_currency);
- $shippingServiceadditionalcost = $dom->createElement(
- 'ShippingServiceAdditionalCost',
- '0.0'
- );
- $attr_additional_cost_currency = new \DOMAttr(
- 'currencyID',
- $ebay_setting->ebay_currency
- );
- $shippingServiceadditionalcost->setAttributeNode($attr_additional_cost_currency);
- //$expeditedservice = $dom->createElement('ExpeditedService','false');
- //$shippingtimemin = $dom->createElement('ShippingTimeMin','1');
- //$shippingtimemax = $dom->createElement('ShippingTimeMax','2');
- $freeshipping = $dom->createElement('FreeShipping', 'true');
- $shippingserviceoptions->appendChild($shippingservicepriority);
- $shippingserviceoptions->appendChild($shippingservice);
- $shippingserviceoptions->appendChild($shippingservicecost);
- $shippingserviceoptions->appendChild($shippingServiceadditionalcost);
- //$shippingserviceoptions->appendChild($expeditedservice);
- //$shippingserviceoptions->appendChild($shippingtimemin);
- //$shippingserviceoptions->appendChild($shippingtimemax);
- $shippingserviceoptions->appendChild($freeshipping);
- $shippingdetails->appendChild($shippingserviceoptions);
- $item_node->appendChild($shippingdetails);
- $itemspecifics = $dom->createElement('ItemSpecifics');
- if (count($ebaycategoryspecifics) > 0) {
- for ($i = 0; $i < count($ebaycategoryspecifics); $i++) {
- if ($ebaycategoryspecifics[$i]['Name'] == 'Marke'
- && $ebaycategoryspecifics[$i]['ValidationRules']['SelectionMode'] == 'FreeText') {
- $namevaluelist = $dom->createElement('NameValueList');
- $name = $dom->createElement('Name', 'Marke');
- $value = $dom->createElement('Value', $brand_name);
- $itemspecifics->appendChild(
- $namevaluelist
- );
- $namevaluelist->appendChild(
- $name
- );
- $namevaluelist->appendChild(
- $value
- );
- } elseif ($ebaycategoryspecifics[$i]['Name'] == 'Größe'
- && $ebaycategoryspecifics[$i]['ValidationRules']['SelectionMode'] == 'FreeText') {
- $namevaluelist = $dom->createElement(
- 'NameValueList'
- );
- $name = $dom->createElement('Name', 'Größe');
- $value = $dom->createElement('Value', 'S');
- $itemspecifics->appendChild($namevaluelist);
- $namevaluelist->appendChild($name);
- $namevaluelist->appendChild($value);
- } else {
- $namevaluelist = $dom->createElement('NameValueList');
- $name = $dom->createElement(
- 'Name',
- $ebaycategoryspecifics[$i]['Name']
- );
- if (isset($ebaycategoryspecifics[$i]['ValueRecommendation']['0']['Value'])) {
- $value = $dom->createElement(
- 'Value',
- $ebaycategoryspecifics[$i]['ValueRecommendation']['0']['Value']
- );
- } else {
- $value = $dom->createElement(
- 'Value',
- $ebaycategoryspecifics[$i]['ValueRecommendation']['Value']
- );
- }
- $itemspecifics->appendChild($namevaluelist);
- $namevaluelist->appendChild($name);
- $namevaluelist->appendChild($value);
- }
- }
- }
- /*$namevaluelist1 = $dom->createElement('NameValueList');
- $name1 = $dom->createElement('Name','Occasion');
- $value1 = $dom->createElement('Value','Special');
- $itemspecifics->appendChild($namevaluelist1);
- $namevaluelist1->appendChild($name1);
- $namevaluelist1->appendChild($value1);
- $namevaluelist2 = $dom->createElement('NameValueList');
- $name2 = $dom->createElement('Name','Brand');
- $value2 = $dom->createElement('Value','Shirtee');
- $itemspecifics->appendChild($namevaluelist2);
- $namevaluelist2->appendChild($name2);
- $namevaluelist2->appendChild($value2);
- $namevaluelist3 = $dom->createElement('NameValueList');
- $name3 = $dom->createElement('Name','Size Type');
- $value3 = $dom->createElement('Value','Regular');
- $itemspecifics->appendChild($namevaluelist3);
- $namevaluelist3->appendChild($name3);
- $namevaluelist3->appendChild($value3);
- $namevaluelist4 = $dom->createElement('NameValueList');
- $name4 = $dom->createElement('Name','Größe');
- $value4 = $dom->createElement('Value','S');
- $itemspecifics->appendChild($namevaluelist4);
- $namevaluelist4->appendChild($name4);
- $namevaluelist4->appendChild($value4);
- $namevaluelist5 = $dom->createElement('NameValueList');
- $name5 = $dom->createElement('Name','Style');
- $value5 = $dom->createElement('Value','Polo Shirt');
- $itemspecifics->appendChild($namevaluelist5);
- $namevaluelist5->appendChild($name5);
- $namevaluelist5->appendChild($value5);
- $namevaluelist6 = $dom->createElement('NameValueList');
- $name6 = $dom->createElement('Name','Sleeve Style');
- $value6 = $dom->createElement('Value','Short Sleeve');
- $itemspecifics->appendChild($namevaluelist6);
- $namevaluelist6->appendChild($name6);
- $namevaluelist6->appendChild($value6);
- $namevaluelist7 = $dom->createElement('NameValueList');
- $name7 = $dom->createElement('Name',"Bottoms Size (Men's)");
- $value7 = $dom->createElement('Value','S');
- $itemspecifics->appendChild($namevaluelist7);
- $namevaluelist7->appendChild($name7);
- $namevaluelist7->appendChild($value7);*/
- $item_node->appendChild($itemspecifics);
- $variations = $dom->createElement('Variations');
- $variationspecificsset = $dom->createElement('VariationSpecificsSet');
- $options_array = json_decode($import_product->mp_options);
- $option_length = count(json_decode($import_product->mp_options));
- for ($op = 0; $op < $option_length; $op++) {
- $option_namevaluelist = $dom->createElement('NameValueList');
- $option_name = $dom->createElement('Name', $options_array[$op]->title);
- $option_namevaluelist->appendChild($option_name);
- for ($opv=0; $opv < count($options_array[$op]->additional_fields); $opv++) {
- $option_value = $dom->createElement(
- 'Value',
- $options_array[$op]->additional_fields[$opv]->title
- );
- $option_namevaluelist->appendChild($option_value);
- }
- $variationspecificsset->appendChild($option_namevaluelist);
- }
- $variations->appendChild($variationspecificsset);
- $ad1_json = $variation_items[0];
- $ad2_json = $variation_items[1];
- $ad1_array = $variation_items[0]->additional_fields;
- $ad2_array = $variation_items[1]->additional_fields;
- $ad1_length = count($ad1_array);
- $ad2_length = count($ad2_array);
- // custom code start
- //echo "<pre>";print_r($ad1_array);echo "<br/>";print_r($ad2_array);exit;
- if ($ad2_length > $ad1_length) {
- $ad1_array = $variation_items[1]->additional_fields;
- $ad2_array = $variation_items[0]->additional_fields;
- $ad1_json = $variation_items[1];
- $ad2_json = $variation_items[0];
- $ad1_length = count($ad1_array);
- $ad2_length = count($ad2_array);
- }
- $new_ad1_array = $new_array1 = $new_ad2_array = $new_array2 = array();
- foreach ($ad1_array as $ad1_array_key => $ad1_array_value) {
- $new_ad1_array[] = (array) $ad1_array_value;
- }
- foreach ($new_ad1_array as $new_ad1_array_key => $new_ad1_array_value) {
- $new_ad1_array_value["option_name"] = $ad1_json->title;
- $new_array1[] = $new_ad1_array_value;
- }
- foreach ($ad2_array as $ad2_array_key => $ad2_array_value) {
- $new_ad2_array[] = (array) $ad2_array_value;
- }
- foreach ($new_ad2_array as $new_ad2_array_key => $new_ad2_array_value) {
- $new_ad2_array_value["option_name"] = $ad2_json->title;
- $new_array2[] = $new_ad2_array_value;
- }
- // custom code Ends
- $new_array1 = $this->arrayMsort($new_array1, array('value_id'=>SORT_ASC));
- $new_array2 = $this->arrayMsort($new_array2, array('value_id'=>SORT_ASC));
- $ad1_array = json_decode(json_encode($ad1_array), true);
- $ad2_array = json_decode(json_encode($ad2_array), true);
- $ad1_array = $this->arrayMsort($ad1_array, array('value_id'=>SORT_ASC));
- $ad2_array = $this->arrayMsort($ad2_array, array('value_id'=>SORT_ASC));
- //echo "<pre>";print_r((array)$ad1_array);
- //echo "<br/>";print_r((array)$ad2_array);exit;
- $valid3xl = array("16", "4", "198", "17");
- $valid4xl = array("16", "4", "198", "17");
- $valid_jh030_3xl = array("1624", "668", "1676", "1565", "839", "31");
- $valid_jh001_3xl = array("1624", "668", "1698");
- $valid_jh001_4xl = array("1624", "1698");
- $valid_jh001_5xl = array("1624", "1698");
- $valid_jh001_xs = array("3", "16");
- $valid_bctk301 = array("1151", "1236");
- $valid_swgl = array("3468");
- $valid_a88vl = array("2462");
- $valid_a88vl_xxl = array("1610");
- for ($ad1 = 0; $ad1 < $ad1_length; $ad1++) {
- for ($ad2 = 0; $ad2 < $ad2_length; $ad2++) {
- // start for JH030
- if ($sku_want == 'JH030'
- && $new_array2[$ad2]['sku'] == '3XL'
- && !in_array($new_array1[$ad1]['sku'], $valid_jh030_3xl)) {
- continue;
- }
- if ($sku_want == 'JH030'
- && $new_array1[$ad1]['sku'] == '3XL'
- && !in_array($new_array2[$ad2]['sku'], $valid_jh030_3xl)) {
- continue;
- }
- // end for JH030
- // start for BCTU004
- if ($sku_want == 'BCTU004'
- && $new_array2[$ad2]['sku'] == '3XL'
- && !in_array($new_array1[$ad1]['sku'], $valid3xl)) {
- continue;
- }
- if ($sku_want == 'BCTU004'
- && $new_array1[$ad1]['sku'] == '3XL'
- && !in_array($new_array2[$ad2]['sku'], $valid3xl)) {
- continue;
- }
- if ($sku_want == 'BCTU004'
- && $new_array2[$ad2]['sku'] == '4XL'
- && !in_array($new_array1[$ad1]['sku'], $valid4xl)) {
- continue;
- }
- if ($sku_want == 'BCTU004'
- && $new_array1[$ad1]['sku'] == '4XL'
- && !in_array($new_array2[$ad2]['sku'], $valid4xl)) {
- continue;
- }
- // End for BCTU004
- // start for JH001
- if ($sku_want == 'JH001'
- && $new_array2[$ad2]['sku'] == '3XL'
- && !in_array($new_array1[$ad1]['sku'], $valid_jh001_3xl)) {
- continue;
- }
- if ($sku_want == 'JH001'
- && $new_array1[$ad1]['sku'] == '3XL'
- && !in_array($new_array2[$ad2]['sku'], $valid_jh001_3xl)) {
- continue;
- }
- if ($sku_want == 'JH001'
- && $new_array2[$ad2]['sku'] == '4XL'
- && !in_array($new_array1[$ad1]['sku'], $valid_jh001_4xl)) {
- continue;
- }
- if ($sku_want == 'JH001'
- && $new_array1[$ad1]['sku'] == '4XL'
- && !in_array($new_array2[$ad2]['sku'], $valid_jh001_4xl)) {
- continue;
- }
- if ($sku_want == 'JH001'
- && $new_array2[$ad2]['sku'] == '5XL'
- && !in_array($new_array1[$ad1]['sku'], $valid_jh001_5xl)) {
- continue;
- }
- if ($sku_want == 'JH001'
- && $new_array1[$ad1]['sku'] == '5XL'
- && !in_array($new_array2[$ad2]['sku'], $valid_jh001_5xl)) {
- continue;
- }
- if ($sku_want == 'JH001'
- && $new_array2[$ad2]['sku'] == 'XS'
- && !in_array($new_array1[$ad1]['sku'], $valid_jh001_xs)) {
- continue;
- }
- if ($sku_want == 'JH001'
- && $new_array1[$ad1]['sku'] == 'XS'
- && !in_array($new_array2[$ad2]['sku'], $valid_jh001_xs)) {
- continue;
- }
- // end for JH001
- // start for BCTK301
- if ($sku_want == 'BCTK301'
- && in_array($new_array1[$ad1]['sku'], $valid_bctk301)) {
- continue;
- }
- if ($sku_want == 'BCTK301' && in_array($new_array2[$ad2]['sku'], $valid_bctk301)) {
- continue;
- }
- // end for BCTK301
- // start for SWGL1,SWGL2,A88VL
- if ($sku_want == 'SWGL1' && in_array($new_array1[$ad1]['sku'], $valid_swgl)) {
- continue;
- }
- if ($sku_want == 'SWGL1' && in_array($new_array2[$ad2]['sku'], $valid_swgl)) {
- continue;
- }
- if ($sku_want == 'SWGL2' && in_array($new_array1[$ad1]['sku'], $valid_swgl)) {
- continue;
- }
- if ($sku_want == 'SWGL2' && in_array($new_array2[$ad2]['sku'], $valid_swgl)) {
- continue;
- }
- if ($sku_want == 'A88VL' && in_array($new_array1[$ad1]['sku'], $valid_a88vl)) {
- continue;
- }
- if ($sku_want == 'A88VL' && in_array($new_array2[$ad2]['sku'], $valid_a88vl)) {
- continue;
- }
- // end for SWGL1,SWGL2,A88VL
- // start for A88VL XXL
- if ($sku_want == 'A88VL'
- && $new_array2[$ad2]['sku'] == 'XXL'
- && in_array($new_array1[$ad1]['sku'], $valid_a88vl_xxl)) {
- continue;
- }
- if ($sku_want == 'A88VL'
- && $new_array1[$ad1]['sku'] == 'XXL'
- && in_array($new_array2[$ad2]['sku'], $valid_a88vl_xxl)) {
- continue;
- }
- // End for A88VL XXL
- $variation = $dom->createElement('Variation');
- $sku = $dom->createElement('SKU', $import_product->mp_sku.
- "__".$new_array1[$ad1]['sku']."__".$new_array2[$ad2]['sku']);
- $price_cal = number_format($ad1_array[$ad1]['price'] +$ad2_array[$ad2]['price'], 2);
- if ($price_cal == 0.00) {
- $price_cal = number_format(1, 2);
- }
- $startprice = $dom->createElement('StartPrice', $import_product_data->price);
- $quantity = $dom->createElement('Quantity', '1');
- $variationproductlistingdetails = $dom->createElement(
- 'VariationProductListingDetails'
- );
- if (isset($ebayeanenabled['Category']['EANEnabled'])
- && $ebayeanenabled['Category']['EANEnabled'] == 'Required') {
- $fake_country = $this->getRandomEAN(2); // generate 13 length random number
- $fake_country_code = '2'.$fake_country;
- $random_ean_ebay = $this->generateEAN(13, $fake_country_code);
- $variationproductlistingdetails_ean = $dom->createElement(
- 'EAN',
- $random_ean_ebay
- );
- $variationproductlistingdetails->appendChild(
- $variationproductlistingdetails_ean
- );
- }
- $ad_variationspecifics = $dom->createElement('VariationSpecifics');
- $ad1_namevaluelist = $dom->createElement('NameValueList');
- $ad1_name = $dom->createElement('Name', $new_array1[$ad1]['option_name']);
- $ad1_value = $dom->createElement('Value', $new_array1[$ad1]['title']);
- $ad1_namevaluelist->appendChild($ad1_name);
- $ad1_namevaluelist->appendChild($ad1_value);
- $ad_variationspecifics->appendChild($ad1_namevaluelist);
- $ad2_namevaluelist = $dom->createElement('NameValueList');
- $ad2_name = $dom->createElement('Name', $new_array2[$ad2]['option_name']);
- $ad2_value = $dom->createElement('Value', $new_array2[$ad2]['title']);
- $ad2_namevaluelist->appendChild($ad2_name);
- $ad2_namevaluelist->appendChild($ad2_value);
- $ad_variationspecifics->appendChild($ad2_namevaluelist);
- $variation->appendChild($sku);
- $variation->appendChild($startprice);
- $variation->appendChild($quantity);
- $variation->appendChild($variationproductlistingdetails);
- $variation->appendChild($ad_variationspecifics);
- $variations->appendChild($variation);
- }
- }
- $picture_variation = $dom->createElement('Pictures');
- $picture_variation_name = $dom->createElement('VariationSpecificName', 'color');
- $picture_variation->appendChild($picture_variation_name);
- $variations->appendChild($picture_variation);
- //echo "<pre>";print_r($variation_items[1]->additional_fields);exit;
- $color_variations = json_decode(
- json_encode($variation_items[1]->additional_fields),
- true
- );
- $color_variations = $this->arrayMsort(
- $color_variations,
- array('value_id'=>SORT_ASC)
- );
- //echo "<pre>";print_r($color_variations);exit;
- foreach ($color_variations as $color_variation) {
- $value_ids[] = $color_variation['value_id'];
- }
- foreach ($value_ids as $value_id) {
- foreach ($ebay_images_array as $images_array) {
- if ($value_id == $images_array['1']) {
- $color_images[]=$images_array['0'];
- }
- }
- }
- //echo "<pre>";print_r(array_values($color_variations));exit;
- $color_variations_sort_arr = array_values($color_variations);
- for ($var_pic = 0; $var_pic < count($color_variations_sort_arr); $var_pic++) {
- $variation_specific_pic_set = $dom->createElement('VariationSpecificPictureSet');
- $variation_specific_pic_val = $dom->createElement(
- 'VariationSpecificValue',
- $color_variations_sort_arr[$var_pic]['title']
- );
- $variation_pic_url = $dom->createElement('PictureURL', $color_images[$var_pic]);
- $variation_specific_pic_set->appendChild($variation_specific_pic_val);
- $variation_specific_pic_set->appendChild($variation_pic_url);
- if ($var_pic == count($color_variations_sort_arr)-1) {
- $measurementImage = $this->getMeasurementImage($sku_want, 4);
- $image_path = url('/');
- $measurementImageUrl = $image_path.'/browsenode/measurementimage/'
- .$measurementImage;
- if (!empty($measurementImage) && $measurementImage != '') {
- $ebaybrowsenodeimages = $this->getBrowseNodeImagesEbay(
- $ebay_setting,
- $siteID,
- $measurementImageUrl
- );
- }
- //echo "<pre>";print_r($ebaybrowsenodeimages);exit;
- if (count($ebaybrowsenodeimages) > 0) {
- for ($siz_pic = 0; $siz_pic < count($ebaybrowsenodeimages); $siz_pic++) {
- $variation_size_url = $dom->createElement(
- 'PictureURL',
- $ebaybrowsenodeimages[$siz_pic]
- );
- $variation_specific_pic_set->appendChild($variation_size_url);
- }
- }
- /*$ebay_browse_images = \App\EbayBrowseMeasurementImage::where(
- 'browse_data_id',
- '=',
- $primary_category_id->id
- )->get();
- if (count($ebay_browse_images) > 0) {
- for ($siz_pic = 0; $siz_pic < count($ebay_browse_images); $siz_pic++) {
- $variation_size_url = $dom->createElement(
- 'PictureURL',
- $ebay_browse_images[$siz_pic]->ebay_measurement_image_url
- );
- $variation_specific_pic_set->appendChild($variation_size_url);
- }
- }*/
- }
- $picture_variation->appendChild($variation_specific_pic_set);
- }
- $item_node->appendChild($variations);
- $site_country_node = $dom->createElement('Site', $ebay_setting->ebay_site_name);
- $item_node->appendChild($site_country_node);
- // ItemSpecifics to specify Item start
- // ItemSpecifics to specify Item ends
- $root->appendChild($item_node);
- /* Item Node Ends*/
- $dom->appendChild($root);
- $xml = $dom->saveXML();
- //echo $xml;exit;
- if ($import_product->product_ebay_id) {
- $verb = $verbRevise;
- }
- $ebay_session_product = new \EBaySessionProduct(
- $ebay_setting->production_user_tocken,
- $devID,
- $appID,
- $certID,
- $ebay_server_url,
- $comp_version,
- $siteID,
- $verb
- );
- $responseXml = $ebay_session_product->sendHttpRequest($xml);
- //echo "<pre>";print_r($responseXml);echo "</pre>";exit;
- if (stristr($responseXml, 'HTTP 404') || $responseXml == '') {
- DB::table('tbl_ebay_products')->where(
- 'magento_id',
- $import_product->magento_id
- )->update(['product_ebay_status' => '6'], ['cron_error' => '']);
- $no_response_error = "There is some Error in Ebays Trading API AddFixedPriceItem call.
- For Below product: \n";
- $no_response_error .= "Product ID = ".$import_product->magento_id."
- Product SKU = ".$import_product->mp_sku;
- \Mail::raw(
- $no_response_error,
- function ($message) {
- ->subject('No Response From Ebay - Ebay Import Product Error');
- }
- );
- \Log::channel('ebay')->info('There is some Error in Ebays Trading API
- AddFixedPriceItem call.
- For Product Magento id - '.$import_product->magento_id.' Product sku - '
- .$import_product->mp_sku.' Please wait for sometime and try again.');
- } else {
- $responseDoc = new \DomDocument();
- $responseDoc->loadXML($responseXml);
- $errorsnodes = $responseDoc->getElementsByTagName('Errors');
- foreach ($errorsnodes as $errorsnode) {
- $errorNames = $errorsnode->getElementsByTagName("SeverityCode");
- if ($errorNames->item('0')->nodeValue == "Error") {
- $errorDB[] = $errorsnode->getElementsByTagName(
- "ErrorCode"
- )->item('0')->nodeValue;
- $replshortmsg = str_replace(
- "<",
- "<",
- $errorsnode->getElementsByTagName(
- 'ShortMessage'
- )->item(0)->nodeValue
- ); $shortMsgDB[] =
- str_replace(">", ">", $replshortmsg);
- $longMsgDB[] = str_replace(
- ">",
- ">",
- str_replace(
- "<",
- "<",
- $errorsnode->getElementsByTagName('LongMessage')->item(0)->nodeValue
- )
- );
- }
- } // foreach $feeNode
- if ((isset($errorDB)
- && (count($errorDB) > 0))
- && (isset($shortMsgDB)
- && (count($shortMsgDB) > 0))
- && (isset($longMsgDB)
- && (count($longMsgDB) > 0))) {
- DB::table('tbl_ebay_products')->where(
- 'magento_id',
- $import_product->magento_id
- )->update([
- 'product_ebay_status' => '7',
- 'error' => 'Error',
- 'error_code'=>serialize($errorDB),
- 'error_short_msg'=>serialize($shortMsgDB),
- 'error_long_msg'=>serialize($longMsgDB),
- 'cron_error'=> ''
- ]);
- //$code_link = "https://developer.ebay.com/devzone/xml/docs/Reference/ebay/Errors/errormessages.htm#".$codeDB;
- //echo "\033[0;31mError: There is some error in Ebay's Product import script.";
- $script_error = "There is some Error in Ebays Product import script.
- For Below product: \n";
- $script_error .= "Product ID = ".$import_product->magento_id."
- Product SKU = ".$import_product->mp_sku;
- \Mail::raw(
- $script_error,
- function ($message) {
- ->subject('Ebay Product import script Error');
- }
- );
- \Log::channel('ebay')->info('There is some Error in Ebays Product import script.
- For Product Magento id - '
- .$import_product->magento_id.' Product sku - '.$import_product->mp_sku);
- } else {
- if ($import_product->product_ebay_id) {
- $responses = $responseDoc->getElementsByTagName(
- "ReviseFixedPriceItemResponse"
- );
- } else {
- $responses = $responseDoc->getElementsByTagName("AddFixedPriceItemResponse");
- }
- $itemID = "";
- foreach ($responses as $response) {
- $acks = $response->getElementsByTagName("Ack");
- $ack = $acks->item(0)->nodeValue;
- //echo "Ack = $ack <BR />\n"; // Success if successful
- $startTimes = $response->getElementsByTagName("StartTime");
- $startTime = $startTimes->item(0)->nodeValue;
- $start_date_array = date_parse($startTime);
- $start_date_string = date(
- 'Y-m-d H:i:s',
- mktime(
- $start_date_array['hour'],
- $start_date_array['minute'],
- $start_date_array['second'],
- $start_date_array['month'],
- $start_date_array['day'],
- $start_date_array['year']
- )
- );
- $endTimes = $response->getElementsByTagName("EndTime");
- $endTime = $endTimes->item(0)->nodeValue;
- $end_date_array = date_parse($endTime);
- $end_date_string = date(
- 'Y-m-d H:i:s',
- mktime(
- $end_date_array['hour'],
- $end_date_array['minute'],
- $end_date_array['second'],
- $end_date_array['month'],
- $end_date_array['day'],
- $end_date_array['year']
- )
- );
- $itemIDs = $response->getElementsByTagName("ItemID");
- $itemID = $itemIDs->item(0)->nodeValue;
- $ebay_link = "https://www.ebay.de/itm/".$itemID."?ViewItem=&item=".$itemID;
- $feeNodes = $responseDoc->getElementsByTagName('Fee');
- foreach ($feeNodes as $feeNode) {
- $feeNames = $feeNode->getElementsByTagName("Name");
- if ($feeNames->item(0)) {
- $feeName[] = $feeNames->item(0)->nodeValue;
- $fees = $feeNode->getElementsByTagName('Fee');//Fee amount in Fee
- $fee[] = $fees->item(0)->nodeValue;
- } // if feeName
- } // foreach $feeNode
- $fee_array=array_combine($feeName, $fee);
- $fee_array_serialize=serialize($fee_array);
- DB::table('tbl_ebay_products')->where(
- 'magento_id',
- $import_product->magento_id
- )->update(
- ['product_ebay_id' => $itemID,
- 'product_ebay_status' => '8',
- 'error' => '',
- 'error_code'=>'',
- 'error_short_msg'=>'',
- 'error_long_msg'=>'',
- 'cron_error'=>null,
- 'ebay_status' => 'Product Uploaded',
- 'ebay_list_start_time'=>$start_date_string,
- 'ebay_list_end_time'=>$end_date_string,
- 'ebay_fees'=>$fee_array_serialize,
- 'ebay_list_url'=>$ebay_link,
- 'ebay_product_xml'=>$xml]
- );
- $designerDetails = \App\Designer::where(
- 'designer_id',
- $import_product->designer_id
- )->first();
- $success_msg = "Congratulation!! You successfully created.
- $import_product->mp_product.
- on ebay.\n";
- $success_msg .= "Please check your Product on ebay at
- $ebay_link";
- \Mail::raw(
- $success_msg,
- function ($message) use ($designerDetails) {
- $message->to($designerDetails->designer_email)->bcc(
- )
- //->cc('[email protected]')
- ->subject(
- 'Congratulation!! Product Successfully Added on Ebay.'
- );
- }
- );
- \Log::channel('ebay')->info('Congratulation!! You successfully created'
- . $import_product->mp_product.'
- On Ebay. Please check your Product on ebay at '.$ebay_link);
- if ($cronExist) {
- $endDate = date('Y-m-d H:i:s');
- callChannel($startDate, $endDate, $cronExist->id, 'ebay');
- }
- }
- }
- }
- }
- }
- }
- } catch (\Exception $e) {
- $designerDetials = \App\Designer::where('designer_id', $import_product->designer_id)->first();
- $error = $e->getMessage();
- $cron_error = "Error : $error
- Product ID : $import_product->magento_id
- Product SKU : $import_product->mp_sku
- Designer Name = $designerDetials->designer_name
- Designer Email = $designerDetials->designer_email";
- \Mail::raw(
- $cron_error,
- function ($message) {
- ->subject('Ebay Import Products Cron Error');
- }
- );
- \Log::channel('ebay')->error('Error :'.$e->getMessage().' For Product ID -'
- . $import_product->magento_id.' Product SKU = '.$import_product->mp_sku);
- app('db')->rollback();
- }
- }
- //$xml = $dom->saveXML();
- //echo $xml;
- //exit;
- }
- public function getBrowseNodeImagesEbay($ebay_setting, $siteID, $imageurl)
- {
- $ebay_browse_url = array();
- $devID = config('ebay.Dev_ID');
- $appID = config('ebay.App_ID');
- $certID = config('ebay.Cert_ID');
- $comp_version = config('ebay.COMPATIBILITY_LEVEL');
- $ebay_server_url = config('ebay.SERVER_URL');
- $requestXmlBody = '<?xml version="1.0" encoding="utf-8"?>';
- $requestXmlBody.= '<UploadSiteHostedPicturesRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
- $requestXmlBody.= "<RequesterCredentials>
- <eBayAuthToken>". trim($ebay_setting->production_user_tocken)."</eBayAuthToken>
- </RequesterCredentials>";
- $requestXmlBody.= '<ErrorLanguage>en_US</ErrorLanguage>';
- $requestXmlBody.= "<Version>" .$comp_version. "</Version>";
- $requestXmlBody.= "<ExternalPictureURL>".trim($imageurl)."</ExternalPictureURL>";
- $requestXmlBody.= '</UploadSiteHostedPicturesRequest>';
- //echo "<pre>";print_r($requestXmlBody);exit;
- // xml creation code ends for upload image services
- //Create a new eBay session with all details pulled in from included keys.php
- $session = new \EBaySessionProduct(
- $ebay_setting->production_user_tocken,
- $devID,
- $appID,
- $certID,
- $ebay_server_url,
- $comp_version,
- $siteID,
- 'UploadSiteHostedPictures'
- );
- //send the request and get response
- $responseXml = $session->sendHttpRequest($requestXmlBody);
- if (stristr($responseXml, 'HTTP 404') || $responseXml == '') {
- \Log::channel('ebay')
- ->info('Ebay not getting any response during browse measurement image upload for image - ' . $imageurl);
- } else {
- $responseDoc = new \DomDocument();
- $responseDoc->loadXML($responseXml);
- $errors = $responseDoc->getElementsByTagName('Errors');
- if ($errors->length == 0) {
- $responses = $responseDoc->getElementsByTagName("UploadSiteHostedPicturesResponse");
- foreach ($responses as $response) {
- $acks = $response->getElementsByTagName("Ack");
- $ack = $acks->item(0)->nodeValue;
- //echo "Ack = $ack <BR />\n"; // Success if successful
- $picturesDatas = $response->getElementsByTagName("SiteHostedPictureDetails");
- foreach ($picturesDatas as $picturesData) {
- $fullurls = $picturesData->getElementsByTagName("FullURL");
- //$fullurl[] = $fullurls->item(0)->nodeValue;
- $ebay_browse_url[] = $fullurls->item(0)->nodeValue;
- }
- }
- } else {
- $error = $errors->item(0)->getElementsByTagName('SeverityCode');
- $errorDB = $error->item(0)->nodeValue;
- if ($errors->length > 0 && $errorDB != 'Warning') {
- $code = $errors->item(0)->getElementsByTagName('ErrorCode');
- $shortMsg = $errors->item(0)->getElementsByTagName('ShortMessage');
- $longMsg = $errors->item(0)->getElementsByTagName('LongMessage');
- $codeDB = $code->item(0)->nodeValue;
- $shortMsgDB = (count($shortMsg) > 0) ?
- str_replace(">", ">", str_replace("<", "<", $shortMsg->item(0)->nodeValue))
- : '';
- $longMsgDB = (count($longMsg) > 0) ?
- str_replace(">", ">", str_replace("<", "<", $longMsg->item(0)->nodeValue))
- : '';
- \Log::channel('ebay')
- ->info('Ebay getting some error during browse measurement image upload for image - ' . $imageurl .
- 'Error:' .$errorDB.'
- Error Code:' .$codeDB.'
- Error Short Msg:' .$shortMsgDB.'
- Error Long Msg:' .$longMsgDB);
- } else {
- $responses = $responseDoc->getElementsByTagName("UploadSiteHostedPicturesResponse");
- foreach ($responses as $response) {
- $acks = $response->getElementsByTagName("Ack");
- $ack = $acks->item(0)->nodeValue;
- //echo "Ack = $ack <BR />\n"; // Success if successful
- $picturesDatas = $response->getElementsByTagName("SiteHostedPictureDetails");
- foreach ($picturesDatas as $picturesData) {
- $fullurls = $picturesData->getElementsByTagName("FullURL");
- //$fullurl[] = $fullurls->item(0)->nodeValue;
- $ebay_browse_url[] = $fullurls->item(0)->nodeValue;
- }
- }
- }
- }
- }
- return $ebay_browse_url;
- }
- public function getMeasurementImage($sku, $language)
- {
- $measureMentImage = \App\BrowseMeasurementImage::with('browseData')
- ->whereHas('browseData', function ($query) use ($sku, $language) {
- $query->where('sku', '=', $sku)->where('language', '=', $language);
- })->first();
- return $measureMentImage['measurement_image'];
- }
- public function getCategorySpecifics($category_id, $ebay_setting, $siteID, $category_verb)
- {
- $new_recommendation_array = array();
- $devID = config('ebay.Dev_ID');
- $appID = config('ebay.App_ID');
- $certID = config('ebay.Cert_ID');
- $comp_version = config('ebay.COMPATIBILITY_LEVEL');
- $ebay_server_url = config('ebay.SERVER_URL');
- $dom = new \DOMDocument();
- $dom->encoding = 'utf-8';
- $dom->xmlVersion = '1.0';
- $dom->formatOutput = true;
- $root = $dom->createElementNS('urn:ebay:apis:eBLBaseComponents', 'GetCategorySpecificsRequest');
- $request_node = $dom->createElement('RequesterCredentials');
- $ebay_auth = $dom->createElement('eBayAuthToken', $ebay_setting->production_user_tocken);
- $request_node->appendChild($ebay_auth);
- $root->appendChild($request_node);
- $detail_node = $dom->createElement('DetailLevel', 'ReturnAll');
- $root->appendChild($detail_node);
- $category_id_node = $dom->createElement('CategoryID', $category_id);
- $root->appendChild($category_id_node);
- $err_lang_node = $dom->createElement('ErrorLanguage', 'de_DE');
- $root->appendChild($err_lang_node);
- $war_level_node = $dom->createElement('WarningLevel', 'High');
- $root->appendChild($war_level_node);
- $ver_node = $dom->createElement('Version', $comp_version);
- $root->appendChild($ver_node);
- $dom->appendChild($root);
- $xml = $dom->saveXML();
- $ebay_category_specifics = new \EBaySessionProduct(
- $ebay_setting->production_user_tocken,
- $devID,
- $appID,
- $certID,
- $ebay_server_url,
- $comp_version,
- $siteID,
- $category_verb
- );
- $responseXml = $ebay_category_specifics->sendHttpRequest($xml);
- $array = json_decode(json_encode((array)simplexml_load_string($responseXml)), true);
- $cat_namerecommendations = $array['Recommendations']['NameRecommendation'];
- foreach ($cat_namerecommendations as $recommendation_key => $recommendation_value) {
- if (isset($recommendation_value['ValidationRules']['MinValues'])) {
- $new_recommendation_array[] = $recommendation_value;
- }
- }
- return $new_recommendation_array;
- }
- public function getCategoryFeatures($category_id, $ebay_setting, $siteID, $category_verb)
- {
- $new_recommendation_array = array();
- $devID = config('ebay.Dev_ID');
- $appID = config('ebay.App_ID');
- $certID = config('ebay.Cert_ID');
- $comp_version = config('ebay.COMPATIBILITY_LEVEL');
- $ebay_server_url = config('ebay.SERVER_URL');
- $dom = new \DOMDocument();
- $dom->encoding = 'utf-8';
- $dom->xmlVersion = '1.0';
- $dom->formatOutput = true;
- $root = $dom->createElementNS('urn:ebay:apis:eBLBaseComponents', 'GetCategoryFeaturesRequest');
- $request_node = $dom->createElement('RequesterCredentials');
- $ebay_auth = $dom->createElement('eBayAuthToken', $ebay_setting->production_user_tocken);
- $request_node->appendChild($ebay_auth);
- $root->appendChild($request_node);
- $detail_node = $dom->createElement('DetailLevel', 'ReturnAll');
- $root->appendChild($detail_node);
- $category_id_node = $dom->createElement('CategoryID', $category_id);
- $root->appendChild($category_id_node);
- $feature_id_node = $dom->createElement('FeatureID', 'EANEnabled');
- $root->appendChild($feature_id_node);
- $view_all_node = $dom->createElement('ViewAllNodes', true);
- $root->appendChild($view_all_node);
- $err_lang_node = $dom->createElement('ErrorLanguage', 'de_DE');
- $root->appendChild($err_lang_node);
- $war_level_node = $dom->createElement('WarningLevel', 'High');
- $root->appendChild($war_level_node);
- $ver_node = $dom->createElement('Version', $comp_version);
- $root->appendChild($ver_node);
- $dom->appendChild($root);
- $xml = $dom->saveXML();
- $ebay_category_features = new \EBaySessionProduct(
- $ebay_setting->production_user_tocken,
- $devID,
- $appID,
- $certID,
- $ebay_server_url,
- $comp_version,
- $siteID,
- $category_verb
- );
- $responseXml = $ebay_category_features->sendHttpRequest($xml);
- $arrayeanenabled = json_decode(json_encode((array)simplexml_load_string($responseXml)), true);
- return $arrayeanenabled;
- }
- public function getRandomEAN($length)
- {
- $chars = "1234567890";
- $clen = strlen($chars)-1;
- $id = '';
- for ($i = 0; $i < $length; $i++) {
- $id .= $chars[mt_rand(0, $clen)];
- }
- return ($id);
- }
- public function generateEAN($number, $fake_country)
- {
- $code = $fake_country . str_pad($number, 9, '0', STR_PAD_LEFT);
- $weightflag = true;
- $sum = 0;
- // Weight for a digit in the checksum is 3, 1, 3.. starting from the last digit.
- // loop backwards to make the loop length-agnostic. The same basic functionality
- // will work for codes of different lengths.
- for ($i = strlen($code) - 1; $i >= 0; $i--) {
- $sum += (int)$code[$i] * ($weightflag?3:1);
- $weightflag = !$weightflag;
- }
- $code .= (10 - ($sum % 10)) % 10;
- return $code;
- }
- public function arrayMsort($array, $cols)
- {
- $colarr = array();
- foreach ($cols as $col => $order) {
- $colarr[$col] = array();
- foreach ($array as $k => $row) {
- $colarr[$col]['_'.$k] = strtolower($row[$col]);
- }
- }
- $eval = 'array_multisort(';
- foreach ($cols as $col => $order) {
- $eval .= '$colarr[\''.$col.'\'],'.$order.',';
- }
- $eval = substr($eval, 0, -1).');';
- eval($eval);
- $ret = array();
- foreach ($colarr as $col => $arr) {
- foreach ($arr as $k => $v) {
- $k = substr($k, 1);
- if (!isset($ret[$k])) {
- $ret[$k] = $array[$k];
- }
- $ret[$k][$col] = $array[$k][$col];
- }
- }
- return $ret;
- }
- }
Add Comment
Please, Sign In to add comment