Inventory API

General ShopSite user discussion

Inventory API

Postby misterfogg » Sat Jun 16, 2018 11:33 am

So i have been racking my brain. Gone through 6 different programmers and $$$ to try to get the inventory file to upload inventory to my store. I don't know what yall need to see why it isn't working. I have a couple of different code here to look at. Basically i get a XML file every 30 minutes with changes to inventory. I want that to then update my inventory for my store. I have several thousand products. Every Sunday I get an XML file with ALL items to be updated. I have 3 cron jobs running but don't know if they are set up right. Sorry for the long code but this is frustrating me. Let me know what other files you may need? DB Sync, etc
Thanks in Advance, David

<?php

/*** FILES ***/
//$update_folder_look = glob("xml-update/*.xml");
//$update_file_count = count($update_folder_look);

/*** START AT FILE NUMBER 0 ***/
//$file_num_start = 0;


/*** FILES ***/
$xml_product_url = simplexml_load_file("http://morris.morriscostumes.com/out/176364/item_updateyny_001.xml") or die("Error: Cannot create object");
$update_file_count = $xml_product_url->of;


/*** START AT FILE NUMBER ***/
$file_num_start = $xml_product_url->file_no;


$xml_new_products = simplexml_load_file("../products.xml") or die("Error: Cannot create object");

for ($update_num_loop = "$file_num_start"; $update_num_loop <= $update_file_count; ++$update_num_loop){

//$xml_update = simplexml_load_file($update_folder_look[$update_num_loop]);
if($update_num_loop<10){
$xml_update = simplexml_load_file('http://morris.morriscostumes.com/out/176364/item_updateyny_00'.$update_num_loop.'.xml');
}else{
$xml_update = simplexml_load_file('http://morris.morriscostumes.com/out/176364/item_updateyny_0'.$update_num_loop.'.xml');
}

foreach ($xml_update->Available as $xml_update_value) {

foreach ($xml_new_products->Products->Product as $xml_new_products_value) {

if (reset($xml_update_value->Part) == reset($xml_new_products_value->ManufacturerPartNumber)) {

$xml_new_products_value->SKU = reset($xml_update_value->Sku);
$xml_new_products_value->Weight = reset($xml_update_value->Detail[0]->Weight);
$xml_new_products_value->Price = reset($xml_update_value->Detail[0]->Price) * 2;
$xml_new_products_value->GTIN = reset($xml_update_value->Gtin);
$xml_new_products_value->QuantityOnHand = reset($xml_update_value->Qty);

}

}

}

}

//$xml_new_products->asXML('products.xml');

echo 'done';

?>


SECOND CODE

<?php
set_time_limit(0);
ignore_user_abort(1);

include ('functions_categories.php');

function array_check($array, $key, $val) {
foreach ($array as $item)
if (isset($item[$key]) && $item[$key] == $val)
return true;
return false;
}

/*** FILES ***/
$inventory_folder_look = glob("xml-inventory/*.xml");
$inventory_file_count = count($inventory_folder_look);
$csv = array_map('str_getcsv', file('csv/web-categories.csv'));


/*** START AT FILE NUMBER 0 ***/
$file_num_start = 0;

/*** ARRAY FOR CATEGORIES EXPORT ***/
$data_cats = array();

$data_cats['ShopSitePages']['Response'][] = array(
'ResponseCode' => 1,
'ResponseDescription' => 'success',
);


/*** INVENTORY EXPORT ***/
for ($inventory_num_loop = "$file_num_start"; $inventory_num_loop < $inventory_file_count; ++$inventory_num_loop) {

$xml = simplexml_load_file($inventory_folder_look[$inventory_num_loop]);


$i = 0;
foreach ($xml->part as $key) {

$ss_category = array();

for ($k = 1; $k < 10; ++$k) {
if ($key->{web_category . $k}) {
$ss_category[] = $key->{web_category . $k};
$ss_category[] = '';
} else {
break;
}
}

unset($csv_filters);
$csv_filters = array();
foreach ($csv as $csv_vals) {

if($csv_vals[0] != $ss_category[0]){continue;}
$csv_filters[0] = $csv_vals[1];

if($csv_vals[2] != $ss_category[2]){continue;}
$csv_filters[1] = $csv_vals[3];

if ($csv_vals[4] != $ss_category[4]) {continue;}
$csv_filters[2] = $csv_vals[5];

if ($csv_vals[6] != $ss_category[6]) {continue;}
$csv_filters[3] = $csv_vals[7];

if ($csv_vals[8] != $ss_category[8]) {continue;}
$csv_filters[4] = $csv_vals[9];

if ($csv_vals[10] != $ss_category[10]) {continue;}
$csv_filters[5] = $csv_vals[11];

if ($csv_vals[12] != $ss_category[12]) {continue;}
$csv_filters[6] = $csv_vals[13];

if ($csv_vals[14] != $ss_category[14]) {continue;}
$csv_filters[7] = $csv_vals[15];

if ($csv_vals[16] != $ss_category[16]) {continue;}
$csv_filters[8] = $csv_vals[17];

}

$csv_filter = array_filter($csv_filters);

$c = 0;
foreach ($csv_filter as $cat_value) {

$c_plus1 = $c + 1;
$sub_cats_list = array();
$sub_cats = array();

if(count($csv_filter) > 1 && $c_plus1 < count($csv_filter)){
for ($e = $c_plus1; $e < count($csv_filter); ++$e) {
$sub_cats_list[] = array($csv_filter[$e]);
}

$sub_cats = array(
'Name' => $sub_cats_list
);
}

if (array_check($data_cats['ShopSitePages']['Pages']['Page'], 'Name', ucwords(strtolower($cat_value)))) {
$r = 0;
foreach ($data_cats['ShopSitePages']['Pages']['Page'] as $xml_cats_item) {
if ($xml_cats_item['Name'] == ucwords(strtolower($cat_value))) {
$new_product = array(
'Name' => trim(reset($key->name)),
'SKU' => reset($key->partnumber),
);

$data_cats['ShopSitePages']['Pages']['Page'][$r]['ProductLinks']['Product'][] = $new_product;

foreach ($sub_cats_list as $sub_cats_key => $sub_cats_val) {
if (!in_array($sub_cats_val, $data_cats['ShopSitePages']['Pages']['Page'][$r]['PageLinks']['Name'])) {
$data_cats['ShopSitePages']['Pages']['Page'][$r]['PageLinks']['Name'][] = $sub_cats_val;
}
}

}
$r++;
}

} else {

$cat_value_no_special_char = str_replace('& ', '', $cat_value);
$cat_value_url = str_replace(' ', '-', $cat_value_no_special_char);
$strurl = str_replace(' ', '-', $cat_value_url);
$str_url = preg_replace('/[^A-Za-z0-9\-]/', '', $strurl);
$data_cats['ShopSitePages']['Pages']['Page'][] = array(
'Name' => ucwords(strtolower($cat_value)),
'LinkText' => '',
'Name' => ucwords(strtolower($cat_value)),
'PageTitle' => ucwords(strtolower($cat_value)),
'Graphic' => 'none',
'PageGraphicDesc' => '',
'LinkName' => ucwords(strtolower($cat_value)),
'LinkGraphic' => 'none',
'LinkGraphicDesc' => '',
'LinkGraphicSize' => '0',
'LinkText' => '',
'LinksToPage' => '',
'PageLinks' => $sub_cats,
'ProductLinks' => array(
'Product' => array(
array(
'Name' => trim(reset($key->name)),
'SKU' => reset($key->partnumber),
),
),
),
'PageFileName' => strtolower($str_url) . '.html',
'MetaKeywords' => '',
'MetaDescription' => '',
'SearchProducts' => 'checked',
'Index' => 'checked',
'PageSitemap' => 'checked',
'PageSitemapPriority' => 'Google Default',
'DisplayName' => 'checked',
'DisplayGraphic' => 'checked',
'TextWrap' => 'On',
'Template' => 'caregory-overview-template.html',
'ItemAlignment' => 'Left aligned',
'Columns' => 'Two columns',
'PageLinkColumns' => 'Three columns',
'DisplayColumnBorders' => '',
'PageWidth' => '960',
'PageWidthType' => 'px',
'DisplayUniversalHeader' => 'checked',
'DisplayUniversalFooter' => 'checked',
'PageGlobalCrossSell' => '',
'TextColor' => '#000000',
'BackgroundColor' => '#FFFFFF',
'LinkColor' => '#A10B0B',
'VisitedLinkColor' => '#BA0C0C',
'ActiveLinkColor' => '#CC0001',
'BackgroundImage' => 'none',
'Order' => 'Ascending',
'ProductsSortField' => 'Name',
'PagesSortField' => 'Name',
'ProductsFirst' => 'checked',
'NumberProducts' => '0',
'PageField1' => '',
'PageField2' => '',
'PageField3' => '',
'PageField4' => '',
'PageField5' => '',
'PageField6' => '',
'PageField7' => '',
'PageField8' => '',
'PageField9' => '',
'PageField10' => '',
'PageField11' => '',
'PageField12' => '',
'PageField13' => '',
'PageField14' => '',
'PageField15' => '',
'PageField16' => '',
'PageField17' => '',
'PageField18' => '',
'PageField19' => '',
'PageField20' => '',
'PageField21' => '',
'PageField22' => '',
'PageField23' => '',
'PageField24' => '',
'PageField25' => '',
'PageID' => count($data_cats['ShopSitePages']['Pages']['Page']) + 1,
);

}

$c++;

}

/*if ($i == 1) {
break;
};*/

$i++;

}

}

//header('Content-Type: application/xml');
echo xml_encode($data_cats);
misterfogg
 
Posts: 4
Joined: Sat Jun 16, 2018 11:22 am

Re: Inventory API

Postby misterfogg » Wed Jun 20, 2018 5:06 pm

Is there any coders who will help me look into this?
misterfogg
 
Posts: 4
Joined: Sat Jun 16, 2018 11:22 am


Return to User Forum

Who is online

Users browsing this forum: Bing [Bot] and 18 guests

cron