Aegidius Posted July 30, 2013 Share Posted July 30, 2013 Hello How can I add a combination of a product from script? Thank you Egidio Link to comment Share on other sites More sharing options...
vekia Posted July 30, 2013 Share Posted July 30, 2013 hello you're talking about custom module? or some external stuff? Link to comment Share on other sites More sharing options...
Aegidius Posted July 30, 2013 Author Share Posted July 30, 2013 Is an external script. I'd like to use PS libraries. I have the attribute ID and dynamically I have to create new values for this attribute and then set that the product is available in different attributes. Link to comment Share on other sites More sharing options...
Aegidius Posted August 2, 2013 Author Share Posted August 2, 2013 It's not possible? Link to comment Share on other sites More sharing options...
vekia Posted August 2, 2013 Share Posted August 2, 2013 it's not as easy as it seems, many thinks depends on external script, we don't know it so its very very hard to say (especially for me, because i dont know anything about script) Link to comment Share on other sites More sharing options...
Aegidius Posted August 5, 2013 Author Share Posted August 5, 2013 Is there any API for that? For example I see ProductCore::addCombinationEntity() but I don't know how to use it. Link to comment Share on other sites More sharing options...
MahmutGulerce Posted April 21, 2014 Share Posted April 21, 2014 Hello there I agree Aegidius and want to type sometings more about the Prestashop classes as a software developer: Current class is too much complicated and bad (I'll explain) for understand. For example If you want create a php code (by using Prestashop native class and functions) to insert, update or import products with attributes, you have to Check attribute group exists in DB (there is not a function search by name, you must create a great mysql query ) If not exists you must create it add(); function of AttributeGroup class Check attribute exists in DB (there is not a function search by name too) If not exists you must create it by add(); function of Attribute class If you want to use this attribute in a product combination must use $product->addCombinationEntity() (there is no information about parameters and function) Get id from 5. step Assign the combination class with the id use $combination->setAttributes() use StockAvailable::setProductDependsOnStock() (There is not enough information about thşs function too) use StockAvailable::setProductOutOfStock() (There is not enough information about thşs function too) use StockAvailable::setQuantity(); use AttributeGroup::cleanDeadCombinations(); use Product::SetDefaultAttribute(); use Product::save(); ... .. This is just for a product insert without product variables and functions.If you successfully type a code with this crazy methods and run the code, you will see not working as usually. We need a documentation about this class at least more comment lines at codes 4 Link to comment Share on other sites More sharing options...
criacaosites Posted November 21, 2014 Share Posted November 21, 2014 Hello there I agree Aegidius and want to type sometings more about the Prestashop classes as a software developer: Current class is too much complicated and bad (I'll explain) for understand. For example If you want create a php code (by using Prestashop native class and functions) to insert, update or import products with attributes, you have to Check attribute group exists in DB (there is not a function search by name, you must create a great mysql query ) If not exists you must create it add(); function of AttributeGroup class Check attribute exists in DB (there is not a function search by name too) If not exists you must create it by add(); function of Attribute class If you want to use this attribute in a product combination must use $product->addCombinationEntity() (there is no information about parameters and function) Get id from 5. step Assign the combination class with the id use $combination->setAttributes() use StockAvailable::setProductDependsOnStock() (There is not enough information about thşs function too) use StockAvailable::setProductOutOfStock() (There is not enough information about thşs function too) use StockAvailable::setQuantity(); use AttributeGroup::cleanDeadCombinations(); use Product::SetDefaultAttribute(); use Product::save(); ... .. This is just for a product insert without product variables and functions.If you successfully type a code with this crazy methods and run the code, you will see not working as usually. We need a documentation about this class at least more comment lines at codes I have this problem i create a module that import products from amazon to prestasho with all atributes and i can use only classe product-> add, only because the another classes are so complex. Link to comment Share on other sites More sharing options...
tony_mik Posted October 26, 2016 Share Posted October 26, 2016 Hy there. I managed to do a script that creates combinations for my products, with attributes and stuff. It goes like this: function combination($id_product, $arr, $lang_id){ $id_product_attribute = Combination::getIdByReference($id_product, $arr['code']); $comb = new Combination($id_product_attribute); if($id_product_attribute){ StockAvailable::setQuantity($id_product, $id_product_attribute, $arr['quantity']); } else { $id_atribute = array(); if($arr['size_group_id']){ $id_attribute_size = attribute_id($arr['size_group_id'], $arr['sizes'], $lang_id); $id_attribute[] = $id_attribute_size; } if($arr['color_group_id']){ $id_attribute_color = attribute_id($arr['color_group_id'], $arr['color'], $lang_id); $id_attribute[] = $id_attribute_color; } if(count($id_attribute)){ $comb->quantity = $arr['quantity']; $comb->id_product = $id_product; $comb->reference = $arr['code']; $comb->add(); $comb->setAttributes($id_attribute); } if (isset($arr['supplyer']) && $arr['supplyer'] == 'Supplyer') { $id_product_attribute = Combination::getIdByReference($id_product, $arr['code']); $comb = new Combination($id_product_attribute); if ($arr['combination_image'] != '') { $combination_image = $arr['combination_image'][0]; product_img($id_product, $combination_image); } if($id_product_attribute){ StockAvailable::setQuantity($id_product, $id_product_attribute, $arr['quantity']); $comb->default_on = 1; $comb->update(); } } } } The lang_id can be set like this: $defaultLanguage = new Language((int)(Configuration::get('PS_LANG_DEFAULT'))); $languages = Language::getLanguages(); $lang_id = $defaultLanguage->id; Hope this helps. 3 Link to comment Share on other sites More sharing options...
Zolicad Posted July 3, 2017 Share Posted July 3, 2017 Hello, my solution is a following: 1. You need the 'id_attribute' from the 'attribute_lang' table After: $product = new Product( $product->id ); $combinationAttributes = array(); $combinationAttributes[] = 9; //id_attribute $idProductAttribute = $product->addProductAttribute( (float)0, //price (float)0, //weight 0, //unit_impact null , //ecotax (int)0, //quantity "", //id_images "" , //reference strval(""), //suppliers strval(""), //ean13 NULL, //default NULL, //location NULL //upc ); $product->addAttributeCombinaison($idProductAttribute, $combinationAttributes); Link to comment Share on other sites More sharing options...
matrixconsulting Posted September 6, 2017 Share Posted September 6, 2017 I But the function $id_attribute_color = attribute_id($arr['color_group_id'], $arr['color'], $lang_id); where is? Thank You Link to comment Share on other sites More sharing options...
tony_mik Posted September 18, 2017 Share Posted September 18, 2017 I But the function $id_attribute_color = attribute_id($arr['color_group_id'], $arr['color'], $lang_id); where is? Thank You The function is a Prestashop function. To use PS functions, you call like this: include_once 'config/config.inc.php'; include(dirname(__FILE__).'/init.php'); Link to comment Share on other sites More sharing options...
skini82 Posted February 18, 2018 Share Posted February 18, 2018 On 18/9/2017 at 10:04 AM, tony_mik said: The function is a Prestashop function. To use PS functions, you call like this: include_once 'config/config.inc.php'; include(dirname(__FILE__).'/init.php'); I get error on this, telling function not defined. I tried to search in the entire prestashop code but didn't found a reference to that function. Someone can help me? Link to comment Share on other sites More sharing options...
isideas Posted April 23, 2020 Share Posted April 23, 2020 Hi, I use this in Prestashop 1.7.X in the header of the file to access all functions require_once(dirname(__FILE__) . '/../../../config/config.inc.php'); require_once(dirname(__FILE__) . '/../../../init.php'); Link to comment Share on other sites More sharing options...
szaqu0 Posted July 21, 2020 Share Posted July 21, 2020 Hi, if u want import all functions use only: require_once(dirname(__FILE__) . '/../../../config/config.inc.php'); <- have all functions If u have doubts about the folder location use that in header file : ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); Then PHP can show you errors or warnings. 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