When added from a third-party product to the cart. I want to change the quantity of goods in the basket. Get alert Product (........ ) is over.
if(is_array($arCartPrice)){
//if($arCartPrice['OPTIONS']['MINIMUM']>1){$QUANTITY=$arCartPrice['OPTIONS']['MINIMUM'];}else{$QUANTITY=1;}
$QUANTITY=$arCartPrice['AVAILABLE_NUM'];
$DefaultCategory = 12;
$DefaultTaxGroup = 0;
$Price = $arCartPrice['PRICE_CONVERTED'];
$PriceVAT = round($Price);
$Reference = $arCartPrice['ARTICLE'].' / '.$arCartPrice['BRAND'];
//Presta init
global $context;
if(!$context){$context = Context::getContext();}
$logged = $context->cookie->__get('logged');
$id_cart = $context->cookie->__get('id_cart');
$id_lang = $context->cookie->__get('id_lang');
$id_guest = $context->cookie->__get('id_guest');
$id_currency = $context->cookie->__get('id_currency');
// Add cart if no cart found
if (!$id_cart){
$context->cart = new Cart();
$context->cart->id_customer = $context->customer->id;
$context->cart->id_currency = $id_currency;
$context->cart->add();
if($context->cart->id){
$context->cookie->id_cart = (int)$context->cart->id;
}
$id_cart = (int)$context->cart->id;
}
$doAdd="Y";
//if(!$logged>0){$doAdd="N"; $TCore->arErrorMessages[] = 'You must be logged in to buy products';}
//if(trim($Reference)=='' OR !$Price>0 OR !$QUANTITY>0){$doAdd="N"; $TCore->arErrorMessages[] = 'Add to cart data is missing!';}
if(!$id_cart>0){$doAdd="N"; ErAdd("Your cookie <b>id_cart</b> is wrong!",1);}
if(!$id_lang>0){$doAdd="N"; ErAdd("Your cookie <b>id_lang</b> is wrong!",1);}
if($doAdd!="N"){
//Check avail. tecdoc item in Presta
$sql = 'SELECT p.`id_product`, pl.`name` FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`)
WHERE pl.`id_lang` = '.$id_lang.' AND
p.`price` = '.$Price.' AND
p.`reference` = "'.$Reference.'"
';
$arRes = Db::getInstance()->executeS($sql);
if(count($arRes)>0){
$NewTID = $arRes[0]['id_product'];
}else{
//Supplier data (for 1C integration)
$supplierName = $arCartPrice['SUPPLIER_STOCK'];
$supplierId = $suppliers = (Supplier::getIdByName($supplierName));
if (!$supplierId) {
$supplier = new Supplier();
$supplier->name = $supplierName;
$supplier->active = 1;
$supplier->add();
$supplierId = $supplier->id;
}
$obProduct = new Product(false,false,$id_lang);
$obProduct->id_category_default = $DefaultCategory;
$obProduct->unity = $arCartPrice['ADD_URL'];
$obProduct->name = $arCartPrice['ARTICLE'] .' / '.substr($arCartPrice['NAME'],0,400).' / '.$arCartPrice['BRAND'];
$obProduct->description = 'This product is created automatically by ';
$obProduct->description_short = $arCartPrice['SUPPLIER_STOCK'].' ['.$arCartPrice['DAY'].' days]';
$obProduct->price = $Price;
$obProduct->wholesale_price = $arCartPrice['PRICE'];
$obProduct->reference = $Reference;
$obProduct->link_rewrite = $arCartPrice['CPID'];
$obProduct->available_for_order = 1; //true
$obProduct->visibility = 'none';
$obProduct->is_virtual = 0;
//$obProduct->weight = round($arCartPrice['OPTIONS']['WEIGHT']/1000,2);
$obProduct->minimal_quantity = 1;
$obProduct->condition = 'used';
$obProduct->condition = 'refurbished';
$obProduct->available_now = $arCartPrice['AVAILABLE_NUM'];
$obProduct->quantity = $arCartPrice['AVAILABLE_NUM'];
//supplier
$obProduct->supplier_name = $supplierName;
$obProduct->id_supplier = $supplierId;
$obProduct->id_tax_rules_group = $DefaultTaxGroup;
//echo '<br><pre>';print_r($obProduct);echo '</pre>';die();
$obProduct->add();
if($obProduct->id>0){
$NewTID = $obProduct->id;
$obProduct->setWsCategories(Array(Array("id"=>$DefaultCategory)));
//Add image
if($arCartPrice['IMG_SRC']!='' AND $NewTID>0){
$shops = Shop::getShops(true, null, true);
$image = new Image();
$image->id_product = $NewTID;
$image->position = Image::getHighestPosition($NewTID)+1;
$image->cover = true; // or false;
if(($image->validateFields(false, true)) === true && ($image->validateFieldsLang(false, true)) === true && $image->add()){
$image->associateTo($shops);
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
if(Tools::copy($arCartPrice['IMG_SRC'], $tmpfile)){
$path = $image->getPathForCreation();
ImageManager::resize($tmpfile, $path.'.jpg');
}
unlink($tmpfile);
}
}
}else{
ErAdd("Prestashop new Item ID is false",1);
}
unset($obProduct);
}
if($NewTID>0){
//if($arCartPrice['AVAILABLE']>0){StockAvailable::setQuantity($NewTID, false, $arCartPrice['AVAILABLE']);}
StockAvailable::setQuantity($NewTID, 0, (int) $arCartPrice['AVAILABLE']);
$obCart = new Cart($id_cart);
$obCart->id_lang = $id_lang;
$obCart->id_currency = $id_currency;
if($obCart->updateQty((int)$QUANTITY=1, (int)$NewTID)){
Header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); die();
}else{
ErAdd(" Add to Cart is false. NewTID=".$NewTID,1);
}
How to fix the code so you can update the quantity of goods in your cart.
And the number of 10 pieces. 1 piece is added to the cart. I want to add more to my cart. How to implement it? When I add 2 pieces. I receive a message Product (........ ) is over..
enter image description here
First of all, after you created the product, check in the Backoffice if the quantity is well stored (If the newly created product quantity is equal with $arCartPrice['AVAILABLE_NUM'] )
Maybe you can try with enabled "Allow ordering when out of stock" .
Related
I am getting error after saving sales and error is occurring in update product function, this function is working fine when i am updating product, but when i try to update product using edit-sales it is giving me this error.
Error
Code where error is
Picture 1 is what error i am getting after saving the edited sales..
picture 2 is code where error is occurring....
This is controller.sales ( which is calling model.edit-sales)
static public function ctrEditSale(){
if(isset($_POST["editSale"])){
/*=============================================
FORMAT PRODUCTS AND CUSTOMERS TABLES
=============================================*/
$table = "sales";
$item = "code";
$value = $_POST["editSale"];
$getSale = ModelSales::mdlShowSales($table, $item, $value);
/*=============================================
CHECK IF THERE'S ANY EDITED SALE
=============================================*/
if($_POST["productsList"] == ""){
$productsList = $getSale["products"];
$productChange = false;
}else{
$productsList = $_POST["productsList"];
$productChange = true;
}
if($productChange){
$products = json_decode($getSale["products"], true);
$totalPurchasedProducts = array();
foreach ($products as $key => $value) {
array_push($totalPurchasedProducts, $value["quantity"]);
$tableProducts = "products";
$item = "id";
$value1 = $value["id"];
$order = "id";
$getProduct = ProductsModel::mdlShowProducts($tableProducts, $item, $value1, $order);
$item1a = "sales";
$value1a = $getProduct["sales"] - $value["quantity"];
$newSales = ProductsModel::mdlUpdateProduct($tableProducts, $item1a, $value1a, $value);
$item1b = "stock";
$value1b = $value["quantity"] + $getProduct["stock"];
$stockNew = ProductsModel::mdlUpdateProduct($tableProducts, $item1b, $value1b, $value);
}
$tableCustomers = "customers";
$itemCustomer = "id";
$valueCustomer = $_POST["selectCustomer"];
$getCustomer = ModelCustomers::mdlShowCustomers($tableCustomers, $itemCustomer, $valueCustomer);
$item1a = "purchases";
$value1a = $getCustomer["purchases"] - array_sum($totalPurchasedProducts);
$customerPurchases = ModelCustomers::mdlUpdateCustomer($tableCustomers, $item1a, $value1a, $valueCustomer);
/*=============================================
UPDATE THE CUSTOMER'S PURCHASES AND REDUCE THE STOCK AND INCREMENT PRODUCT SALES
=============================================*/
$productsList_2 = json_decode($productsList, true);
$totalPurchasedProducts_2 = array();
foreach ($productsList_2 as $key => $value) {
array_push($totalPurchasedProducts_2, $value["quantity"]);
$tableProducts_2 = "products";
$item_2 = "id";
$value_2 = $value["id"];
$order = "id";
$getProduct_2 = ProductsModel::mdlShowProducts($tableProducts_2, $item_2, $value_2, $order);
$item1a_2 = "sales";
$value1a_2 = $value["quantity"] + $getProduct_2["sales"];
$newSales_2 = ProductsModel::mdlUpdateProduct($tableProducts_2, $item1a_2, $value1a_2, $value_2);
$item1b_2 = "stock";
$value1b_2 = $getProduct_2["stock"] - $value["quantity"];
$newStock_2 = ProductsModel::mdlUpdateProduct($tableProducts_2, $item1b_2, $value1b_2, $value_2);
}
$tableCustomers_2 = "customers";
$item_2 = "id";
$value_2 = $_POST["selectCustomer"];
$getCustomer_2 = ModelCustomers::mdlShowCustomers($tableCustomers_2, $item_2, $value_2);
$item1a_2 = "purchases";
$value1a_2 = array_sum($totalPurchasedProducts_2) + $getCustomer_2["purchases"];
$customerPurchases_2 = ModelCustomers::mdlUpdateCustomer($tableCustomers_2, $item1a_2, $value1a_2, $value_2);
$item1b_2 = "lastPurchase";
date_default_timezone_set('America/Bogota');
$date = date('Y-m-d');
$hour = date('H:i:s');
$value1b_2 = $date.' '.$hour;
$dateCustomer_2 = ModelCustomers::mdlUpdateCustomer($tableCustomers_2, $item1b_2, $value1b_2, $value_2);
}
/*=============================================
SAVE PURCHASE CHANGES
=============================================*/
$data = array("idSeller"=>$_POST["idSeller"],
"idCustomer"=>$_POST["selectCustomer"],
"code"=>$_POST["editSale"],
"products"=>$productsList,
"tax"=>$_POST["newTaxPrice"],
"netPrice"=>$_POST["newNetPrice"],
"totalPrice"=>$_POST["saleTotal"],
"paymentMethod"=>$_POST["listPaymentMethod"]);
$answer = ModelSales::mdleditSale($table, $data);
if($answer == "ok"){
echo'<script>
localStorage.removeItem("range");
swal({
type: "success",
title: "The sale has been edited correctly",
showConfirmButton: true,
confirmButtonText: "Close"
}).then((result) => {
if (result.value) {
window.location = "sales";
}
})
</script>';
}
}
}
above code is calling model edit-sales with data to update database
This is model edit sales method
mdl:editsale
you put in last attribute all array $value, you only need to put only id $value['id']
$item1a = "sales";
$value1a = $getProduct["sales"] - $value["quantity"];
$newSales = ProductsModel::mdlUpdateProduct($tableProducts, $item1a, $value1a, $value['id']);
$item1b = "stock";
$value1b = $value["quantity"] + $getProduct["stock"];
$stockNew = ProductsModel::mdlUpdateProduct($tableProducts, $item1b, $value1b, $value['id']);
i have a site it running on a platform called "photo store" its a PHP site. there is image i want some one click that image redirect to my you tube channel but problem is all pages loading from template.so i did some coding and add a few line with if statement first i did only echo that works but when i try to redirect to YouTube it wand load 500 error coming can anyone help me??
this is a code
if(strpos($_SERVER['HTTP_REFERER'],'cart.php') or strpos($_SERVER['HTTP_REFERER'],'index.php')) // Clear the crumbs if coming from the cart or index
unset($_SESSION['crumbsSession']);
try
{
//$useGalleryID = $galleryID; // Original untouched gallery ID
$useMediaID = $mediaID; // Original untouched media ID
if(!$mediaID) // Make sure a media ID was passed
$smarty->assign('noAccess',1);
else
{
if($config['EncryptIDs']) // Decrypt IDs
{
$mediaID = k_decrypt($mediaID);
$useGalleryID = k_encrypt($_SESSION['id']);
}
else
$useGalleryID = $_SESSION['id'];
//echo $mediaID;
idCheck($mediaID); // Make sure ID is numeric
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM {$dbinfo[pre]}media WHERE media_id = '{$mediaID}'";
$mediaInfo = new mediaList($sql);
if($mediaInfo->getRows())
{
if($mediaID==985){
echo $mediaID;
window.location.replace("http://www.youtube.com");
}
else{
$media = $mediaInfo->getSingleMediaDetails('preview');
$galleryIDArray = $mediaInfo->getMediaGalleryIDs(); // Get an array of galleries this media is in
if(#!in_array($mediaID,$_SESSION['viewedMedia'])) // See if media has already been viewed
{
$newMediaViews = $media['views']+1;
mysqli_query($db,"UPDATE {$dbinfo[pre]}media SET views='{$newMediaViews}' WHERE media_id = '{$mediaID}'"); // Update views
$media['views'] = $newMediaViews; // Update the array so the count shown is the new count
$_SESSION['viewedMedia'][] = $mediaID;
}
//print_r($media); exit;
/*
if(!$_SESSION['crumbsSession']) // Get a crumb trail - doesn't work for contibutors yet
{
#$galleryInfo = mysqli_fetch_assoc(mysqli_query($db,"SELECT * FROM {$dbinfo[pre]}media_galleries WHERE gmedia_id = '{$mediaID}' ORDER BY mg_id LIMIT 1"));
if($galleryInfo['gallery_id'])
{
$galleriesMainPageLink['page'] = "gallery.php?mode=gallery";
$_SESSION['galleriesData'][0]['linkto'] = linkto($galleriesMainPageLink); // Check for SEO
$_SESSION['galleriesData'][0]['name'] = $lang['galleries']; //
$_SESSION['crumbsSession'] = galleryCrumbsFull($galleryInfo['gallery_id']);
}
}
*/
// Check for video sample
$mediaInfo2 = new mediaTools($mediaID);
if($media['dsp_type'] == 'video') // Make sure the DSP type is set to video
{
if($video = $mediaInfo2->getVidSampleInfoFromDB()) // Make sure video file exists
{
$videoCheck = $mediaInfo2->verifyVidSampleExists();
if($videoCheck['status']) { // Make sure the video exists
//print_k($videoCheck); exit;
if($videoCheck['url'] and $config['passVideoThroughPHP'] === false)
$video['url'] = $videoCheck['url']; // Use URL method
else
$video['url'] = $config['settings']['site_url'].'/video.php?mediaID='.$media['encryptedID']; // Use PHP pass-through
//echo $video['url']; exit;
//print_k($video);
$media['videoStatus'] = 1;
$media['videoInfo'] = $video;
} else {
$media['videoStatus'] = 0;
}
}
else
$media['videoStatus'] = 0;
}
else
{
/*
* Get an estimated preview width and height
*/
$sample = $mediaInfo2->getSampleInfoFromDB();
$sampleSize = getScaledSizeNoSource($sample['sample_width'],$sample['sample_height'],$config['settings']['preview_size'],$crop=0);
$media['previewWidth'] = $sampleSize[0];
$media['previewHeight'] = $sampleSize[1];
}
$mediaPrice = getMediaPrice($media); // Get the media price based on the license
$mediaCredits = getMediaCredits($media); // Get the media credits based on the license
// Get category ID - Make sure member has access to category - maybe add this later
$galleryIDArrayFlat = ($galleryIDArray) ? implode(",",$galleryIDArray) : 0;
/*
* Prints *****************************************************************************************************************************
*/
$galleryPrintsResult = mysqli_query($db,
"
SELECT DISTINCT(item_id)
FROM {$dbinfo[pre]}item_galleries
LEFT JOIN {$dbinfo[pre]}prints
ON {$dbinfo[pre]}item_galleries.item_id = {$dbinfo[pre]}prints.print_id
WHERE {$dbinfo[pre]}item_galleries.gallery_id IN ({$galleryIDArrayFlat})
AND {$dbinfo[pre]}item_galleries.mgrarea = 'prints'
AND ({$dbinfo[pre]}prints.attachment = 'media' OR {$dbinfo[pre]}prints.attachment = 'both')
"
); // Find out which prints are assigned to galleries this photo is in
$galleryPrintsRows = mysqli_num_rows($galleryPrintsResult);
while($galleryPrint = mysqli_fetch_array($galleryPrintsResult))
$printIDArray[] = $galleryPrint['item_id'];
$mediaPrintsResult = mysqli_query($db,"SELECT * FROM {$dbinfo[pre]}media_prints WHERE media_id = '{$mediaID}'"); // Find what prints have been directly assigned to this photo // GROUP BY print_id
$mediaPrintsRows = mysqli_num_rows($mediaPrintsResult);
//echo $mediaPrintsRows; exit; // Testing
while($mediaPrint = mysqli_fetch_array($mediaPrintsResult))
{
if($mediaPrint['printgrp_id']) // Is a group assignment
{
// Select print groups
$mediaPrintsGroupsResult = mysqli_query($db,
"
SELECT *
FROM {$dbinfo[pre]}prints
LEFT JOIN {$dbinfo[pre]}groupids
ON {$dbinfo[pre]}prints.print_id = {$dbinfo[pre]}groupids.item_id
WHERE {$dbinfo[pre]}groupids.group_id = '{$mediaPrint[printgrp_id]}'
AND {$dbinfo[pre]}prints.active = 1
AND {$dbinfo[pre]}prints.deleted = 0
AND {$dbinfo[pre]}groupids.mgrarea = 'prints'
"
);
//$pgRows = mysqli_num_rows($mediaPrintsGroupsResult); // Testing
//echo $pgRows;
while($mediaPrintsGroup = mysqli_fetch_array($mediaPrintsGroupsResult))
$printIDArray[] = $mediaPrintsGroup['print_id'];
}
else
{
$printIDArray[] = $mediaPrint['print_id'];
if($mediaPrint['customized'])
{
$printCustomizedIDs[] = $mediaPrint['print_id']; // Add this ID to the custom array list
$customPrint[$mediaPrint['print_id']] = $mediaPrint; // Get the actual values for the custom item
}
}
}
if($printIDArray)
$printsIDArrayFlat = implode(",",$printIDArray);
else
$printsIDArrayFlat = 0;
// Now that we have the print ID array select the prints that the customer has access to and assign them to smarty
$printsResult = mysqli_query($db,
"
SELECT *
FROM {$dbinfo[pre]}prints
LEFT JOIN {$dbinfo[pre]}perms
ON ({$dbinfo[pre]}prints.print_id = {$dbinfo[pre]}perms.item_id AND {$dbinfo[pre]}perms.perm_area = 'prints')
WHERE ({$dbinfo[pre]}prints.print_id IN ({$printsIDArrayFlat}) OR {$dbinfo[pre]}prints.all_galleries = 1)
AND {$dbinfo[pre]}prints.active = 1
AND {$dbinfo[pre]}prints.deleted = 0
AND ({$dbinfo[pre]}prints.everyone = 1 OR {$dbinfo[pre]}perms.perm_value IN ({$memberPermissionsForDB}))
ORDER BY {$dbinfo[pre]}prints.sortorder
"
);
if($returnRows = mysqli_num_rows($printsResult))
{
while($print = mysqli_fetch_assoc($printsResult))
{
$print['price'] = defaultPrice($print['price']); // Make sure to assign a default price if needed
$print['credits'] = defaultCredits($print['credits']); // Make sure to assign default credits if needed
/*
* Custom Pricing calculations
*/
if(#in_array($print['print_id'],$printCustomizedIDs))
{
$print['price_calc'] = $customPrint[$print['print_id']]['price_calc'];
$print['price'] = defaultPrice($customPrint[$print['print_id']]['price']);
$print['credits'] = defaultCredits($customPrint[$print['print_id']]['credits']);
$print['credits_calc'] = $customPrint[$print['print_id']]['credits_calc'];
$print['quantity'] = $customPrint[$print['print_id']]['quantity'];
}
/*
* Advanced Pricing calculations
*/
switch($print['price_calc'])
{
case 'add':
$print['price'] = $mediaPrice + $print['price'];
break;
case 'sub':
$print['price'] = $mediaPrice - $print['price'];
break;
case 'mult':
$print['price'] = $mediaPrice * $print['price'];
break;
}
switch($print['credits_calc'])
{
case 'add':
$print['credits'] = $mediaCredits + $print['credits'];
break;
case 'sub':
$print['credits'] = $mediaCredits - $print['credits'];
break;
case 'mult':
$print['credits'] = $mediaCredits * $print['credits'];
break;
}
//echo $mediaCredits.'-'.$print['credits'].'-'.$print['credits_calc']."/";
if($print['quantity'] != '0') // Make sure the quantity is other than 0
{
$printsArray[$print['print_id']] = printsList($print,$mediaID);
$optionsResult = mysqli_query($db,"SELECT og_id FROM {$dbinfo[pre]}option_grp WHERE parent_type = 'prints' AND parent_id = '{$print[print_id]}' AND deleted = 0"); // See if there are any options for this item
if(mysqli_num_rows($optionsResult))
{
$printsArray[$print['print_id']]['addToCartLink'] = $printsArray[$print['print_id']]['linkto']; // Workbox popup
$printsArray[$print['print_id']]['directToCart'] = false; // Workbox popup
}
else
{
if($config['EncryptIDs'])
$printsArray[$print['print_id']]['addToCartLink'] = "{$siteURL}/cart.php?mode=add&type=print&id=".$printsArray[$print['print_id']]['encryptedID']."&mediaID={$media[encryptedID]}"; // Direct to cart
else
$printsArray[$print['print_id']]['addToCartLink'] = "{$siteURL}/cart.php?mode=add&type=print&id={$print[print_id]}&mediaID={$media[media_id]}"; // Direct to cart
$printsArray[$print['print_id']]['directToCart'] = true; // Direct to cart
}
}
}
$smarty->assign('printRows',$returnRows);
$smarty->assign('prints',$printsArray);
}
/*
* Digital Files *****************************************************************************************************************************
*/
require_once 'media.details.inc.php';
/*
* Products *****************************************************************************************************************************
*/
$galleryProductsResult = mysqli_query($db,
"
SELECT DISTINCT(item_id)
FROM {$dbinfo[pre]}item_galleries
LEFT JOIN {$dbinfo[pre]}products
ON {$dbinfo[pre]}item_galleries.item_id = {$dbinfo[pre]}products.prod_id
WHERE {$dbinfo[pre]}item_galleries.gallery_id IN ({$galleryIDArrayFlat})
AND {$dbinfo[pre]}item_galleries.mgrarea = 'products'
AND ({$dbinfo[pre]}products.attachment = 'media' OR {$dbinfo[pre]}products.attachment = 'both')
"
); // Find out which products are assigned to galleries this photo is in
$galleryProductsRows = mysqli_num_rows($galleryProductsResult);
while($galleryProduct = mysqli_fetch_array($galleryProductsResult))
$productIDsArray[] = $galleryProduct['item_id'];
$mediaProductsResult = mysqli_query($db,"SELECT * FROM {$dbinfo[pre]}media_products WHERE media_id = '{$mediaID}'"); // Find what products have been directly assigned to this photo // GROUP BY prod_id
$mediaProductsRows = mysqli_num_rows($mediaProductsResult);
while($mediaProduct = mysqli_fetch_array($mediaProductsResult))
{
if($mediaProduct['prodgrp_id']) // Is a group assignment
{
// Select product groups
$mediaProductsGroupsResult = mysqli_query($db,
"
SELECT *
FROM {$dbinfo[pre]}products
LEFT JOIN {$dbinfo[pre]}groupids
ON {$dbinfo[pre]}products.prod_id = {$dbinfo[pre]}groupids.item_id
WHERE {$dbinfo[pre]}groupids.group_id = '{$mediaProduct[prodgrp_id]}'
AND {$dbinfo[pre]}products.active = 1
AND {$dbinfo[pre]}products.deleted = 0
AND {$dbinfo[pre]}groupids.mgrarea = 'products'
"
);
while($mediaProductsGroup = mysqli_fetch_array($mediaProductsGroupsResult))
$productIDsArray[] = $mediaProductsGroup['prod_id'];
}
else
{
$productIDsArray[] = $mediaProduct['prod_id'];
if($mediaProduct['customized'])
{
$productCustomizedIDs[] = $mediaProduct['prod_id']; // Add this ID to the custom array list
$customProduct[$mediaProduct['prod_id']] = $mediaProduct; // Get the actual values for the custom item
}
}
}
if($productIDsArray)
$productIDsArrayFlat = implode(",",$productIDsArray);
else
$productIDsArrayFlat = 0;
//print_r($productCustomizedIDs); exit;
// Now that we have the product ID array select the products that the customer has access to and assign them to smarty
$productsResult = mysqli_query($db,
"
SELECT *
FROM {$dbinfo[pre]}products
LEFT JOIN {$dbinfo[pre]}perms
ON ({$dbinfo[pre]}products.prod_id = {$dbinfo[pre]}perms.item_id AND {$dbinfo[pre]}perms.perm_area = 'products')
WHERE ({$dbinfo[pre]}products.prod_id IN ({$productIDsArrayFlat}) OR {$dbinfo[pre]}products.all_galleries = 1)
AND {$dbinfo[pre]}products.active = 1
AND {$dbinfo[pre]}products.deleted = 0
AND ({$dbinfo[pre]}products.everyone = 1 OR {$dbinfo[pre]}perms.perm_value IN ({$memberPermissionsForDB}))
ORDER BY {$dbinfo[pre]}products.sortorder
"
);
if($returnRows = mysqli_num_rows($productsResult))
{
while($product = mysqli_fetch_array($productsResult))
{
$product['price'] = defaultPrice($product['price']); // Make sure to assign a default price if needed
$product['credits'] = defaultCredits($product['credits']); // Make sure to assign default credits if needed
/*
* Custom Pricing calculations
*/
if(#in_array($product['prod_id'],$productCustomizedIDs))
{
$product['price_calc'] = $customProduct[$product['prod_id']]['price_calc'];
$product['price'] = defaultPrice($customProduct[$product['prod_id']]['price']);
$product['credits'] = defaultCredits($customProduct[$product['prod_id']]['credits']);
$product['credits_calc'] = $customProduct[$product['prod_id']]['credits_calc'];
$product['quantity'] = $customProduct[$product['prod_id']]['quantity'];
}
/*
* Advanced Pricing calculations
*/
switch($product['price_calc'])
{
case 'add':
$product['price'] = $mediaPrice + $product['price'];
break;
case 'sub':
$product['price'] = $mediaPrice - $product['price'];
break;
case 'mult':
$product['price'] = $mediaPrice * $product['price'];
break;
}
switch($product['credits_calc'])
{
case 'add':
$product['credits'] = $mediaCredits + $product['credits'];
break;
case 'sub':
$product['credits'] = $mediaCredits - $product['credits'];
break;
case 'mult':
$product['credits'] = $mediaCredits * $product['credits'];
break;
}
if($product['quantity'] != '0') // Make sure the quantity is other than 0
{
if($product['product_type'] == '1') // Check if this is a media based product
$productsArray[$product['prod_id']] = productsList($product,$mediaID); // Media based
else
$productsArray[$product['prod_id']] = productsList($product,false); // Stand Alone
$optionsResult = mysqli_query($db,"SELECT og_id FROM {$dbinfo[pre]}option_grp WHERE parent_type = 'products' AND parent_id = '{$product[prod_id]}' AND deleted = 0"); // See if there are any options for this item
if(mysqli_num_rows($optionsResult))
{
$productsArray[$product['prod_id']]['addToCartLink'] = $productsArray[$product['prod_id']]['linkto']; // Workbox popup
$productsArray[$product['prod_id']]['directToCart'] = false; // Workbox popup
}
else
{
if($config['EncryptIDs'])
{
$cartLink = "{$siteURL}/cart.php?mode=add&type=product&id=".$productsArray[$product['prod_id']]['encryptedID'];
if($product['product_type'] == '1') $cartLink .= "&mediaID={$media[encryptedID]}";
$productsArray[$product['prod_id']]['addToCartLink'] = $cartLink; // Direct to cart
}
else
{
$cartLink = "{$siteURL}/cart.php?mode=add&type=product&id={$product[prod_id]}";
if($product['product_type'] == '1') $cartLink .= "&mediaID={$media[media_id]}";
$productsArray[$product['prod_id']]['addToCartLink'] = $cartLink; // Direct to cart
}
$productsArray[$product['prod_id']]['directToCart'] = true; // Direct to cart
}
}
}
$smarty->assign('productRows',$returnRows);
$smarty->assign('products',$productsArray);
}
/*
* Collections *****************************************************************************************************************************
*/
$galleryCollectionsResult = mysqli_query($db,"SELECT item_id FROM {$dbinfo[pre]}item_galleries WHERE mgrarea = 'collections' AND gallery_id IN ({$galleryIDArrayFlat})"); // Find collections from galleries
$galleryCollectionsRows = mysqli_num_rows($galleryCollectionsResult);
if($galleryCollectionsRows)
{
while($galleryCollection = mysqli_fetch_array($galleryCollectionsResult))
$collectionIDs[] = $galleryCollection['item_id'];
}
$mediaCollectionsResult = mysqli_query($db,"SELECT coll_id FROM {$dbinfo[pre]}media_collections WHERE cmedia_id = '{$mediaID}'"); // Find collections this item is directly in
$mediaCollectionsRows = mysqli_num_rows($mediaCollectionsResult);
if($mediaCollectionsRows)
{
while($mediaCollection = mysqli_fetch_array($mediaCollectionsResult))
$collectionIDs[] = $mediaCollection['coll_id'];
}
if($collectionIDs) // Only do if some were found
{
$collectionIDsFlat = implode(',',$collectionIDs);
$collectionsResult = mysqli_query($db,
"
SELECT *
FROM {$dbinfo[pre]}collections
LEFT JOIN {$dbinfo[pre]}perms
ON ({$dbinfo[pre]}collections.coll_id = {$dbinfo[pre]}perms.item_id AND {$dbinfo[pre]}perms.perm_area = 'collections')
WHERE {$dbinfo[pre]}collections.active = 1
AND {$dbinfo[pre]}collections.deleted = 0
AND ({$dbinfo[pre]}collections.everyone = 1 OR {$dbinfo[pre]}perms.perm_value IN ({$memberPermissionsForDB}))
AND ({$dbinfo[pre]}collections.quantity = '' OR {$dbinfo[pre]}collections.quantity > '0')
AND {$dbinfo[pre]}collections.coll_id IN ({$collectionIDsFlat})
ORDER BY {$dbinfo[pre]}collections.sortorder
"
); // Select collections that member has access to
if($returnRows = mysqli_num_rows($collectionsResult))
{
while($collections = mysqli_fetch_array($collectionsResult))
{
$collectionsArray[$collections['coll_id']] = collectionsList($collections);
$collectionsWithAccess[] = $collections['coll_id'];
}
$smarty->assign('collectionRows',$returnRows);
$smarty->assign('collections',$collectionsArray);
}
}
/*
* Packages *****************************************************************************************************************************
*/
/*
$galleryPackagesResult = mysqli_query($db,
"
SELECT *
FROM {$dbinfo[pre]}packages
WHERE all_galleries = 1
AND (attachment = 'media' OR attachment = 'both')
"
); // Find packages that are assigned to all galleries and are attached to media or both
$galleryPackagesRows = mysqli_num_rows($galleryPackagesResult);
while($galleryPackage = mysqli_fetch_array($galleryPackagesResult))
$packageIDsArray[] = $galleryPackage['pack_id'];
*/
$galleryPackagesResult = mysqli_query($db,
"
SELECT DISTINCT(item_id)
FROM {$dbinfo[pre]}item_galleries
LEFT JOIN {$dbinfo[pre]}packages
ON {$dbinfo[pre]}item_galleries.item_id = {$dbinfo[pre]}packages.pack_id
WHERE {$dbinfo[pre]}item_galleries.gallery_id IN ({$galleryIDArrayFlat})
AND {$dbinfo[pre]}item_galleries.mgrarea = 'packages'
AND ({$dbinfo[pre]}packages.attachment = 'media' OR {$dbinfo[pre]}packages.attachment = 'both')
"
); // Find out which packages are assigned to galleries this photo is in or all galleries and attached to media or both
$galleryPackagesRows = mysqli_num_rows($galleryPackagesResult);
while($galleryPackage = mysqli_fetch_array($galleryPackagesResult))
$packageIDsArray[] = $galleryPackage['item_id'];
//print_r($packageIDsArray); // Testing
$mediaPackagesResult = mysqli_query($db,"SELECT * FROM {$dbinfo[pre]}media_packages
window.location.replace("http://www.youtube.com"); is wrong
use thins:
header("Location: http://www.youtube.com");
exit;
Remember that this must be called before any actual output is sent
We are building a script that makes an xml export of orders. In the export, we need to get the EAN code of the product that has been ordered. Currently we use WooCommerce to get the product info, and get the _sku from there.
However, we notice something is going wrong with our multisite setup.
When a product is ordered from site B, we sometimes are unable to get the EAN code of the ordered product, or get a wrong EAN code.
This because if we use our script and ask WooCommerce -> getOrder -> getItems, we get the product id's from site A, not site B. So when we try to get the _sku info from an ordered item, it's looking for the wrong product.
How can we make sure that with our script, it knows what _sku to take when we get our order information so that it doesn't matter which site the order came from, the order information is always correct?
function bol_2020_custom_process_order_manual($order_id) {
global $voorletters;
$order = new WC_Order( $order_id );
// $myuser_id = (int)$order->user_id;
// $user_info = get_userdata($myuser_id);
// $customer = new WC_Customer($order_id);
$items = $order->get_items();
$xml_order_id = $order_id;
$xml_ORDER_DATE = date('Y-m-d');
$xml_DELIVERY_START_DATE = '2017-09-07';
$xml_DELIVERY_END_DATE = '2017-09-08';
$xml_SUPPLIER_NAME = 'DOMAINNAME.nl';
$xml_SUPPLIER_NAME2 = '';
$xml_SUPPLIER_NAME3 = '';
$xml_SUPPLIER_STREET = '**** 71A';
$xml_SUPPLIER_ZIP = '******';
$xml_SUPPLIER_CITY = '********';
$xml_SUPPLIER_COUNTRY = 'NL';
$xml_BUYUR_NAME = get_post_meta($order_id,'_shipping_first_name',true).' '.get_post_meta($order_id,'_shipping_last_name',true);
$xml_BUYUR_NAME2 = get_post_meta($order_id,'_shipping_company',true);
$xml_BUYUR_NAME3 = '';
$xml_BUYUR_STREET = get_post_meta($order_id,'_shipping_address_1',true).' '.get_post_meta($order_id,'_shipping_address_2',true);
$xml_BUYUR_ZIP = get_post_meta($order_id,'_shipping_postcode',true);
$xml_BUYUR_CITY = get_post_meta($order_id,'_shipping_city',true);
$xml_BUYUR_COUNTRY = get_post_meta($order_id,'_shipping_country',true);
$imp = new DOMImplementation;
$dtd = $imp->createDocumentType('ORDER', '', 'openTRANS_ORDER_1_0.dtd');
$dom = $imp->createDocument("", "", $dtd);
$dom->encoding = 'UTF-8';
$root = $dom->appendChild($root = $dom->createElement('ORDER'));
$order_version = $root->appendChild($dom->createAttribute('version'));
$order_version->value = '1.0';
$order_type = $root->appendChild($dom->createAttribute('type'));
$order_type->value = 'standard';
$root->appendChild($client = $dom->createElement('ORDER_HEADER'));
$order_info = $client->appendChild($dom->createElement('ORDER_INFO'));
$order_info->appendChild($ORDER_ID = $order_info->appendChild($dom->createElement('ORDER_ID')));
$ORDER_ID->appendChild($dom->createTextNode($voorletters.$xml_order_id));
$order_info->appendChild($ALT_CUSTOMER_ORDER_ID = $order_info->appendChild($dom->createElement('ALT_CUSTOMER_ORDER_ID')));
$ALT_CUSTOMER_ORDER_ID->appendChild($dom->createTextNode(''));
$order_info->appendChild($ORDER_DATE = $order_info->appendChild($dom->createElement('ORDER_DATE')));
$ORDER_DATE->appendChild($dom->createTextNode($xml_ORDER_DATE));
$DELIVERY_DATE = $order_info->appendChild($order_info->appendChild($dom->createElement('DELIVERY_DATE')));
$DELIVERY_DATE_ATT = $DELIVERY_DATE->appendChild($dom->createAttribute('type'));
$DELIVERY_DATE_ATT->value = 'fixed';
$DELIVERY_START_DATE = $DELIVERY_DATE->appendChild($dom->createElement('DELIVERY_START_DATE'));
$DELIVERY_START_DATE->appendChild($dom->createTextNode($xml_DELIVERY_START_DATE));
$DELIVERY_END_DATE = $DELIVERY_DATE->appendChild($dom->createElement('DELIVERY_END_DATE'));
$DELIVERY_END_DATE->appendChild($dom->createTextNode($xml_DELIVERY_END_DATE));
$ORDER_PARTIES = $order_info->appendChild($order_info->appendChild($dom->createElement('ORDER_PARTIES')));
$BUYER_PARTY = $ORDER_PARTIES->appendChild($dom->createElement('BUYER_PARTY'));
$PARTY_ID = $BUYER_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID_ = $PARTY_ID->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID__ATT = $PARTY_ID_->appendChild($dom->createAttribute('type'));
$PARTY_ID__ATT->value = 'ILN';
//$PARTY_ID_->appendChild($dom->createTextNode('4317784032988'));
$PARTY_ID_->appendChild($dom->createTextNode('4317784044110'));
$SUPPLIER_PARTY = $ORDER_PARTIES->appendChild($dom->createElement('SUPPLIER_PARTY'));
$PARTY_ID = $SUPPLIER_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID_ = $PARTY_ID->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID__ATT = $PARTY_ID_->appendChild($dom->createAttribute('type'));
$PARTY_ID__ATT->value = 'ILN';
$PARTY_ID_->appendChild($dom->createTextNode('4317784000000'));
$SHIPMENT_PARTIES = $ORDER_PARTIES->appendChild($dom->createElement('SHIPMENT_PARTIES'));
$DELIVERY_PARTY = $SHIPMENT_PARTIES->appendChild($dom->createElement('DELIVERY_PARTY'));
$PARTY = $DELIVERY_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID = $PARTY->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID_ATT = $PARTY_ID->appendChild($dom->createAttribute('type'));
$PARTY_ID_ATT->value = 'supplier_specific';
$PARTY_ID->appendChild($dom->createTextNode(''));
$ADDRESS = $PARTY->appendChild($dom->createElement('ADDRESS'));
$NAME = $ADDRESS->appendChild($dom->createElement('NAME'));
$NAME->appendChild($dom->createTextNode($xml_SUPPLIER_NAME));
$NAME2 = $ADDRESS->appendChild($dom->createElement('NAME2'));
$NAME2->appendChild($dom->createTextNode($xml_SUPPLIER_NAME2));
$NAME3 = $ADDRESS->appendChild($dom->createElement('NAME3'));
$NAME3->appendChild($dom->createTextNode($xml_SUPPLIER_NAME3));
$STREET = $ADDRESS->appendChild($dom->createElement('STREET'));
$STREET->appendChild($dom->createTextNode($xml_SUPPLIER_STREET));
$ZIP = $ADDRESS->appendChild($dom->createElement('ZIP'));
$ZIP->appendChild($dom->createTextNode($xml_SUPPLIER_ZIP));
$CITY = $ADDRESS->appendChild($dom->createElement('CITY'));
$CITY->appendChild($dom->createTextNode($xml_SUPPLIER_CITY));
$COUNTRY = $ADDRESS->appendChild($dom->createElement('COUNTRY'));
$COUNTRY->appendChild($dom->createTextNode($xml_SUPPLIER_COUNTRY));
$FINAL_DELIVERY_PARTY = $SHIPMENT_PARTIES->appendChild($dom->createElement('FINAL_DELIVERY_PARTY'));
$PARTY = $FINAL_DELIVERY_PARTY->appendChild($dom->createElement('PARTY'));
$PARTY_ID = $PARTY->appendChild($dom->createElement('PARTY_ID'));
$PARTY_ID_ATT = $PARTY_ID->appendChild($dom->createAttribute('type'));
$PARTY_ID_ATT->value = 'buyer_specific';
$PARTY_ID->appendChild($dom->createTextNode(''));
$ADDRESS = $PARTY->appendChild($dom->createElement('ADDRESS'));
$NAME = $ADDRESS->appendChild($dom->createElement('NAME'));
$NAME->appendChild($dom->createTextNode($xml_BUYUR_NAME));
$NAME2 = $ADDRESS->appendChild($dom->createElement('NAME2'));
$NAME2->appendChild($dom->createTextNode($xml_BUYUR_NAME2));
$NAME3 = $ADDRESS->appendChild($dom->createElement('NAME3'));
$NAME3->appendChild($dom->createTextNode($xml_BUYUR_NAME3));
$STREET = $ADDRESS->appendChild($dom->createElement('STREET'));
$STREET->appendChild($dom->createTextNode($xml_BUYUR_STREET));
$ZIP = $ADDRESS->appendChild($dom->createElement('ZIP'));
$ZIP->appendChild($dom->createTextNode($xml_BUYUR_ZIP));
$CITY = $ADDRESS->appendChild($dom->createElement('CITY'));
$CITY->appendChild($dom->createTextNode($xml_BUYUR_CITY));
$COUNTRY = $ADDRESS->appendChild($dom->createElement('COUNTRY'));
$COUNTRY->appendChild($dom->createTextNode($xml_BUYUR_COUNTRY));
$PARTIAL_SHIPMENT_ALLOWED = $order_info->appendChild($order_info->appendChild($dom->createElement('PARTIAL_SHIPMENT_ALLOWED')));
$PARTIAL_SHIPMENT_ALLOWED->appendChild($dom->createTextNode('False'));
$TRANSPORT = $order_info->appendChild($order_info->appendChild($dom->createElement('TRANSPORT')));
$INCOTERM = $TRANSPORT->appendChild($dom->createElement('INCOTERM'));
$INCOTERM->appendChild($dom->createTextNode(''));
$LOCATION = $TRANSPORT->appendChild($dom->createElement('LOCATION'));
$LOCATION->appendChild($dom->createTextNode('EKD'));
$TRANSPORT_REMARK = $TRANSPORT->appendChild($dom->createElement('TRANSPORT_REMARK'));
$TRANSPORT_REMARK->appendChild($dom->createTextNode('10'));
$REMARK_GENERAL = $order_info->appendChild($order_info->appendChild($dom->createElement('REMARK')));
$REMARK_GENERAL_ = $REMARK_GENERAL->appendChild($dom->createAttribute('type'));
$REMARK_GENERAL_->value = 'general';
$REMARK_GENERAL->appendChild($dom->createTextNode('SUPERHANDIG.NL IS HÉT ADRES VOOR PROF. GEREEDSCHAP EN ACCESSOIRES!'));
$REMARK_ORDER = $order_info->appendChild($order_info->appendChild($dom->createElement('REMARK')));
$REMARK_ORDER_ = $REMARK_ORDER->appendChild($dom->createAttribute('type'));
$REMARK_ORDER_->value = 'order';
$REMARK_ORDER->appendChild($dom->createTextNode($voorletters.$xml_order_id));
$ORDER_ITEM_LIST = $root->appendChild($client = $dom->createElement('ORDER_ITEM_LIST'));
$i = 0;
foreach ($items as $item) {
$ean = get_post_meta($item['product_id'], '_sku'); // for single products
$qty = $item['qty'];
if(empty($ean[0])){
$ean = get_post_meta($item['variation_id'], '_sku'); // for variable products
}
$i++;
$ORDER_ITEM = $ORDER_ITEM_LIST->appendChild($dom->createElement('ORDER_ITEM'));
$LINE_ITEM_ID = $ORDER_ITEM->appendChild($dom->createElement('LINE_ITEM_ID'));
$LINE_ITEM_ID->appendChild($dom->createTextNode($i));
$ARTICLE_ID = $ORDER_ITEM->appendChild($dom->createElement('ARTICLE_ID'));
$SUPPLIER_AID = $ARTICLE_ID->appendChild($dom->createElement('SUPPLIER_AID'));
$SUPPLIER_AID->appendChild($dom->createTextNode(''));
$INTERNATIONAL_AID = $ARTICLE_ID->appendChild($dom->createElement('INTERNATIONAL_AID'));
$INTERNATIONAL_AID_ = $INTERNATIONAL_AID->appendChild($dom->createAttribute('type'));
$INTERNATIONAL_AID_->value = 'EAN';
$INTERNATIONAL_AID->appendChild($dom->createTextNode($ean[0]));
$BUYER_AID = $ARTICLE_ID->appendChild($dom->createElement('BUYER_AID'));
$BUYER_AID_ = $BUYER_AID->appendChild($dom->createAttribute('type'));
$BUYER_AID_->value = 'BP';
$BUYER_AID->appendChild($dom->createTextNode(''));
$BUYER_AID = $ARTICLE_ID->appendChild($dom->createElement('BUYER_AID'));
$BUYER_AID_ = $BUYER_AID->appendChild($dom->createAttribute('type'));
$BUYER_AID_->value = 'IN';
$BUYER_AID->appendChild($dom->createTextNode(''));
$DESCRIPTION_SHORT = $ARTICLE_ID->appendChild($dom->createElement('DESCRIPTION_SHORT'));
$DESCRIPTION_SHORT->appendChild($dom->createTextNode(''));
$QUANTITY = $ORDER_ITEM->appendChild($dom->createElement('QUANTITY'));
$QUANTITY->appendChild($dom->createTextNode($qty));
$ORDER_UNIT = $ORDER_ITEM->appendChild($dom->createElement('ORDER_UNIT'));
$ORDER_UNIT->appendChild($dom->createTextNode('C62'));
}
$ORDER_SUMMARY = $root->appendChild($client = $dom->createElement('ORDER_SUMMARY'));
$TOTAL_ITEM_NUM = $ORDER_SUMMARY->appendChild($dom->createElement('TOTAL_ITEM_NUM'));
$TOTAL_ITEM_NUM->appendChild($dom->createTextNode($i));
$dom->formatOutput = true;
$dom->save($_SERVER['DOCUMENT_ROOT'].'/ede_orders/xml/'.$voorletters.$xml_order_id.'.xml');
}
https://gist.github.com/webstylecenter/2491735366a70d82336512e0d0cc4e8f
How to Update in existing quantity in amazon seller using amazon marketplace web service.when update product then old quantity remove and new quantity add.but I want existing quantity Update. For ex. old Quantity 5 then update 10 more Quantity then total quantity 5+10 = 15.
My Code.
require_once 'vendor/autoload.php';
if ($client->validateCredentials()) {
$product = new MCS\MWSProduct();
$product->sku = $request['ItemSKU'];
$product->price = $request['SalePrice'];
$product->quantity = $request['Qty'];
$product->product_id = $request['ASINNo'];;
$product->product_id_type = $request['ProductType'];;
$product->condition_type = $request['ConditionType'];;
$product->title = $request['Title'];;
$product->sale_price = $request['SalePrice'];
//print_r($product);
if ($product->validate()) {
$result = $client->postProduct($product);
if($result){
$arr['status'] = TRUE;
$arr['submitid'] = $result['FeedSubmissionId'];
$info = $client->GetFeedSubmissionResult($result['FeedSubmissionId']);
}
}
2 . One another code :
$client = new MCS\MWSClient([
'Marketplace_Id' => $Amazon_MarketPlaceId,
'Seller_Id' => $Amazon_SellerId,
'Access_Key_ID' => $Amazon_AWSAccessKeyId,
'Secret_Access_Key' => $Amazon_SecretKey,
'MWSAuthToken' => $Amazon_MWSAuthToken
]);
if ($client->validateCredentials()) {
foreach($request as $key => $value){
$SKU_Prices[$key] = $value;
}
if(!empty($SKU_Prices)){
$result = $client->updatePrice($SKU_Prices);
if($result){
$arr['status'] = TRUE;
$arr['submitid'] = $result['FeedSubmissionId'];
}else{
$arr['status'] = FALSE;
$arr['submitid'] = 0;
}
}
}
Please let me know how to Update.
I'm developing an import products cron.
In my code I have:
if ($supplier = Supplier::getIdByName(trim($prodotto['Supplier']['Name']))) {
$product->id_supplier = (int)$supplier;
} else {
$supplier = new Supplier();
$supplier->name = $prodotto['Supplier']['Name'];
$supplier->active = true;
$supplier->add();
$product->id_supplier = (int)$supplier->id;
$supplier->associateTo($product->id_shop_list);
}
The result is:
product created
supplier created
product without supplier
Where am I wrong?
You have to add also a new ProductSupplier, after you saved te new product use this snippet of code (obviously, adapt it to your needs :)):
// Product supplier
if (isset($product->id_supplier) && property_exists($product, 'supplier_reference'))
{
$id_product_supplier = ProductSupplier::getIdByProductAndSupplier((int)$product->id, 0, (int)$product->id_supplier);
if ($id_product_supplier)
$product_supplier = new ProductSupplier((int)$id_product_supplier);
else
$product_supplier = new ProductSupplier();
$product_supplier->id_product = $product->id;
$product_supplier->id_product_attribute = 0;
$product_supplier->id_supplier = $product->id_supplier;
$product_supplier->product_supplier_price_te = $product->wholesale_price;
$product_supplier->product_supplier_reference = $product->supplier_reference;
$product_supplier->save();
}