Martino00 Posted December 12, 2014 Share Posted December 12, 2014 Can anyone help me? I have already added an extra field to my product table and this is working very well. But now i want to add an extra field to the ps_product_attribute table and display it below the price depending on the attribute that is selected by the customer. when the customer selects an attribute, in the product info you can see the reference name is changing depending on the selected attribute. Just like this i want to display that extra field below the price. I have already added the extra field to the database table but i do not know how i can display this on on the product page and how the value is refreshed (or changed) when the customer selecets another combination. I hope you understand my question. Link to comment Share on other sites More sharing options...
Martino00 Posted December 14, 2014 Author Share Posted December 14, 2014 somebody a clue? Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted December 15, 2014 Share Posted December 15, 2014 Your extra fields won't be recognized by Prestashop Combination class because it doesn't defined as a class properties $your_extra_field Your extra fields won't be recognized by Prestashop Product class method getAttributesGroups() because it doesn't selected in DB query : SELECT pa.`your_extra_field` .... bla ... bla... bla... Eventhough both procedure above has been done, you still have to define your extra fields on ProductController file so it will be available in smarty var $combinationsFinally you will need to modify product.tpl file to place your extra fields so it can be displayed later at the time your customer select combination, and then modify product.js file so it will be displayed and updated when selected combination being changedI suggest to develop custom module to achieve this, so you don't have to override prestashop classes and controller files also to prevent modifying product_attribute DB table structure and easily to add or to update value of your exta fields.How you add/update value for the extra fields anyway ... injecting the value directly to the database table product_attribute ?I can't imagine if you have a lot of products with combinations ... 1 Link to comment Share on other sites More sharing options...
Martino00 Posted December 16, 2014 Author Share Posted December 16, 2014 Gonebedg don't give up. Your info is very valuable to me You asked me how i will update this extra field. --> no problem. I have created a script that can change all the prices of the products or of the attributes directly in the database. The script is using a csv file that i export from excel. And in my massive excel i can change all my prices. This is working fine now so it's not so hard to add an extra field to my csv to update the extra field directly in the database So now back to my problem and your information So i added a column to the ps_product_attribute with the name "attrib_stukprijs" (decimal 20,5) and i added already values in the column. i added public $attrib_stukprijs; and 'attrib_stukprijs' => array('type' => self::TYPE_INT), in the classes/combination.php so it bacame like this here below public $default_on; public $available_date = '0000-00-00'; public $attrib_stukprijs; /** * @see ObjectModel::$definition */ public static $definition = array( 'table' => 'product_attribute', 'primary' => 'id_product_attribute', 'fields' => array( 'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'location' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64), 'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13), 'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12), 'quantity' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'size' => 10), 'reference' => array('type' => self::TYPE_STRING, 'size' => 32), 'supplier_reference' => array('type' => self::TYPE_STRING, 'size' => 32), 'attrib_stukprijs' => array('type' => self::TYPE_INT), Then i added pa.`attrib_stukprijs`, in the public function getAttributesGroups of the classes\product.php file you can see it here below public function getAttributesGroups($id_lang) { if (!Combination::isFeatureActive()) return array(); $sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, product_attribute_shop.`id_product_attribute`, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`price`, product_attribute_shop.`ecotax`, product_attribute_shop.`weight`, product_attribute_shop.`default_on`, pa.`reference`, pa.`attrib_stukprijs`, product_attribute_shop.`unit_price_impact`, product_attribute_shop.`minimal_quantity`, product_attribute_shop.`available_date`, ag.`group_type`, FROM `'._DB_PREFIX_.'product_attribute` pa After that i changed the front\productcontroller.php file i added $combinations[$row['id_product_attribute']]['attrib_stukprijs'] = $row['attrib_stukprijs']; so it became like here below // Call getPriceStatic in order to set $combination_specific_price if (!isset($combination_prices_set[(int)$row['id_product_attribute']])) { Product::getPriceStatic((int)$this->product->id, false, $row['id_product_attribute'], 6, null, false, true, 1, false, null, null, null, $combination_specific_price); $combination_prices_set[(int)$row['id_product_attribute']] = true; $combinations[$row['id_product_attribute']]['specific_price'] = $combination_specific_price; } $combinations[$row['id_product_attribute']]['ecotax'] = (float)$row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (float)$row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int)$row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['attrib_stukprijs'] = $row['attrib_stukprijs']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; if ($row['available_date'] != '0000-00-00') { $combinations[$row['id_product_attribute']]['available_date'] = $row['available_date']; $combinations[$row['id_product_attribute']]['date_formatted'] = Tools::displayDate($row['available_date']); } else after that i added {$product->attrib_stukprijs} to the product.tpl page just to check if it is showing something. But no result. I think i'm almost there now. Is this use of {$product->attrib_stukprijs} ok in product.tpl? Do i need to adjust some other things? Any help is gratefull ofcourse. Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted December 16, 2014 Share Posted December 16, 2014 (edited) You already on the right track But the smarty var {$product->attrib_stukprijs} is incorrect, because attrib_stukprijs is a properties of product combination object. So if you do debugging, for example on ProductController.php : $id_product_attribute = 1; $combination = New Combination($id_product_attribute); // print object combination p($combination->attrib_stukprijs); . OR do debugging like this on your theme file product.tpl . <pre> {$combinations|@print_r:1} </pre> . Then You will see it ... Therefore you should modify your theme file product.tpl to add a html wrapper to display this variable value on select/update product combination For example : <p id="attrib_stukprijs" style="display: none;"> <span></span> </p> And then modify product.js In here i'm giving you an example to add JS script inside function updatePrice() function updatePrice() { // Original JS script goes here // and here ... // and here ... ... ... // Start our modification // Make sure the selected combination have a variable value attrib_stukprijs if (combination.attrib_stukprijs) { // Show the html paragraph which will wrap this var $('#attrib_stukprijs').show(); // Display the value of this var inside the html wrapper $('#attrib_stukprijs span').text(combination.attrib_stukprijs); } } Finnally if you or your customer select/update product combination, then this variable attrib_stukprijs will be displayed Edited December 17, 2014 by gonebdg - webindoshop.com (see edit history) 1 Link to comment Share on other sites More sharing options...
Martino00 Posted December 17, 2014 Author Share Posted December 17, 2014 Allright solved !! With great thanks to gonebdg. Here a little bit extra info. 1. I added an extra column to the product_attribute table and populated it. The name off the extra column is "attrib_stukprijs" 2. i added in combination.php public $attrib_stukprijs; as the variable name 'attrib_stukprijs' => array('type' => self::TYPE_INT), to the public static $definition array 3. I added pa.`attrib_stukprijs` in the public function getAttributesGroups($id_lang) of the product.php so the result is public function getAttributesGroups($id_lang) { if (!Combination::isFeatureActive()) return array(); $sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, product_attribute_shop.`id_product_attribute`, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`price`, product_attribute_shop.`ecotax`, product_attribute_shop.`weight`, product_attribute_shop.`default_on`, pa.`reference`, pa.`attrib_stukprijs`, product_attribute_shop.`unit_price_impact`, product_attribute_shop.`minimal_quantity`, product_attribute_shop.`available_date`, ag.`group_type`, FROM `'._DB_PREFIX_.'product_attribute` pa '.Shop::addSqlAssociation('product_attribute', 'pa').' Then with the GREAT HELP of Gonebdg I added at the end of the function update price in product.js if (combination.attrib_stukprijs) { // Show the html paragraph which will wrap this var $('#attrib_stukprijs').show(); // Display the value of this var inside the html wrapper $('#attrib_stukprijs span').text(combination.attrib_stukprijs); } And finaly i added to product.tpl <p id="attrib_stukprijs" style="display: none;"> <span></span> </p> to display the field Some remarks. - I had some difficulties in the beginning because i was working in the wrong files. First check if the files that needs to be adapted are not in the override folder. - If everything is working, i think it's best to create override files for this. remarks on the help of gonebdg: - i was not able to do a test debugging in productcontroller.php -- i got an error message but this can be my fault because i do not know exactly how to do the testing there. - i was able to display the whole array with the <pre> {$combinations|@print_r:1} </pre> in the product.tpl but there was a typo in. behind the variable you need to type | instead of a double dot. That's all. I hope somebody else can use this. And if you want to thank somebody, then thank this forum and ofcourse gonebdg - webindoshop.com 1 Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted December 17, 2014 Share Posted December 17, 2014 Ah yes ... there is a typo on my previous post, not just in the smarty var {$combinations|@print_r:1} But also in the php script for debugging on ProductController.php >>> missing semi-colon at the end of this line : $combination = New Combination($id_product_attribute); Glad to hear that your problem has been solved Link to comment Share on other sites More sharing options...
juanpax47 Posted March 4, 2015 Share Posted March 4, 2015 Sorry, one question: Where I put this code in ProductController.php : $id_product_attribute = 1; $combination = New Combination($id_product_attribute); // print object combination p($combination->attrib_stukprijs); Thanks!! 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