cronempower Posted March 9, 2017 Share Posted March 9, 2017 Hello, I'm new in prestashop and i'm trying to create, update and delete product with custom code. I create a product with $product = new Product(); $product->name; ..... $product->addToCategories(array($cat)); upload images and attributes with $countsize = count($get_size); for ($y=0; $y < $countsize; $y++) { $combinationAttributes = array(); $combinationAttributes[] = $get_size[$y]; $combinationAttributes[] = $get_color[$y]; /*echo '<pre>'; print_r($combinationAttributes); echo '</pre>';*/ if(!$product->productAttributeExists($combinationAttributes)) { $quantity = $get_qty[$y]; $reference = $get_all_sku[$y]; if ($y==0) $default = true; else $default = false; $idProductAttribute = $product->addProductAttribute((float)$price, (float)$weight, $unit_price_impact, (float)$ecotax, (int)$quantity, "", strval($reference), strval($supplier_reference), strval($ean13), $default, NULL, NULL); $product->addAttributeCombinaison($idProductAttribute, $combinationAttributes); } } and it works. I delete a product with $product = new Product($id_product, null, $id_lang, $id_shop, Context::getContext()->shop->setContext(Shop::CONTEXT_SHOP, $id_shop)); if ($product->delete()) echo 'Deleted'; else echo 'NOT deleted'; and i update a product $product = new Product($product_id); $product->setFieldsToUpdate(array('price','name','weight','id_manufacturer','reference','description','id_category_default','wholesale_price','link_rewrite')); $product->name = "test"; $product->save(); but i cannot update images or attributes I think is better to delete first images and attributes and create them again. So how can i update or delete images and attributes in single product? Sorry for my english Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now