SonnyBoyII Posted July 28, 2011 Share Posted July 28, 2011 Hi, Im editing classes/product.php file. How Can I get a value stored in product feature called lets say xyz and value name abc?? I can use very easly 'depth' field : $product['depth'] $product->depth but how can I call a value stored in value "abc" form "xyz" feature? Link to comment Share on other sites More sharing options...
SonnyBoyII Posted July 29, 2011 Author Share Posted July 29, 2011 any ideas, guys? Link to comment Share on other sites More sharing options...
rocky Posted July 29, 2011 Share Posted July 29, 2011 So you are trying to get a specific feature in classes/Product.php? I can only see a function there to get all features. You could use it and then use a loop to find the right feature. For example: $features = self::getFrontFeatures($id_lang); $featureValue = null; foreach ($features as $feature) if ($feature['name'] == 'xyz') $featureValue = $feature['value']; 1 Link to comment Share on other sites More sharing options...
SonnyBoyII Posted July 29, 2011 Author Share Posted July 29, 2011 So you are trying to get a specific feature in classes/Product.php? I can only see a function there to get all features. You could use it and then use a loop to find the right feature. For example: $features = self::getFrontFeatures($id_lang); $featureValue = null; foreach ($features as $feature) if ($feature.name == 'xyz') $featureValue = $feature.value; briliant! So I need to add this funcion to classes/product.php somewhere and I will be able to use $featureValue to play with other functions?? Link to comment Share on other sites More sharing options...
rocky Posted July 29, 2011 Share Posted July 29, 2011 The getFrontFeatures() function should already exist in classes/Product.php. You can put the above code in a function to get a feature value, assuming the $id_lang variable exists. If it doesn't, you will need to add global $cookie; to the top of the function and then use (int)$cookie->id_lang instead of $id_lang. 1 Link to comment Share on other sites More sharing options...
SonnyBoyII Posted July 29, 2011 Author Share Posted July 29, 2011 The getFrontFeatures() function should already exist in classes/Product.php. You can put the above code in a function to get a feature value, assuming the $id_lang variable exists. If it doesn't, you will need to add global $cookie; to the top of the function and then use (int)$cookie->id_lang instead of $id_lang. Thank you so much, but it doesnt work... im trying to override updateQuantity function and I need feature value to do this: return $productObj->addStockMvt(-(int)($product['cart_quantity'])*($featureValue), (int)_STOCK_MOVEMENT_ORDER_REASON_, (int)$product['id_product_attribute'], (int)$id_order, NULL); That is my whole function: public static function updateQuantity($product, $id_order = NULL) { global $cookie; $features = self::getFrontFeatures((int)$cookie->id_lang); $featureValue = null; foreach ($features as $feature) { if ($feature.name == 'xyz') $featureValue = $feature.value; } if (!is_array($product)) die (Tools::displayError()); if (!Configuration::get('PS_STOCK_MANAGEMENT')) return true; if (Pack::isPack((int)($product['id_product']))) { $products_pack = Pack::getItems((int)($product['id_product']), (int)(Configuration::get('PS_LANG_DEFAULT'))); foreach($products_pack AS $product_pack) { $tab_product_pack['id_product'] = (int)($product_pack->id); $tab_product_pack['id_product_attribute'] = self::getDefaultAttribute($tab_product_pack['id_product'], 1); $tab_product_pack['cart_quantity'] = (int)($product_pack->pack_quantity * $product['cart_quantity']); self::updateQuantity($tab_product_pack); } } $productObj = new Product((int)$product['id_product'], false, (int)Configuration::get('PS_LANG_DEFAULT')); return $productObj->addStockMvt(-(int)($product['cart_quantity'])*($featureValue), (int)_STOCK_MOVEMENT_ORDER_REASON_, (int)$product['id_product_attribute'], (int)$id_order, NULL); } I have checked, the code and idea are right. I get what I wanted using $depth field to store integer but I might to need this field in the future. Thats why I decided to use feature field instead.. unfortunately it seems to be tricky ... Link to comment Share on other sites More sharing options...
rocky Posted July 29, 2011 Share Posted July 29, 2011 Oops, I've correctly a mistake in my code above. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted July 29, 2011 Author Share Posted July 29, 2011 Rocky, the loop stil doesnt work properly for some reason .. public static function updateQuantity($product, $id_order = NULL) { global $cookie; $features = self::getFrontFeatures((int)$cookie->id_lang); $featureValue = null; foreach ($features as $feature) { if ($feature['name'] == 'xyz') $featureValue = $feature['value']; } if (!is_array($product)) die (Tools::displayError()); if (!Configuration::get('PS_STOCK_MANAGEMENT')) return true; if (Pack::isPack((int)($product['id_product']))) { $products_pack = Pack::getItems((int)($product['id_product']), (int)(Configuration::get('PS_LANG_DEFAULT'))); foreach($products_pack AS $product_pack) { $tab_product_pack['id_product'] = (int)($product_pack->id); $tab_product_pack['id_product_attribute'] = self::getDefaultAttribute($tab_product_pack['id_product'], 1); $tab_product_pack['cart_quantity'] = (int)($product_pack->pack_quantity * $product['cart_quantity']); self::updateQuantity($tab_product_pack); } } $productObj = new Product((int)$product['id_product'], false, (int)Configuration::get('PS_LANG_DEFAULT')); return $productObj->addStockMvt(-(int)($product['cart_quantity'])*($featureValue), (int)_STOCK_MOVEMENT_ORDER_REASON_, (int)$product['id_product_attribute'], (int)$id_order, NULL); } Link to comment Share on other sites More sharing options...
SonnyBoyII Posted July 29, 2011 Author Share Posted July 29, 2011 any idea what is wrong, Rocky? Link to comment Share on other sites More sharing options...
rocky Posted July 29, 2011 Share Posted July 29, 2011 No, I'd have to actually test the code to figure that out, which takes longer. It's bed time for me though, so I'll have to look at it tomorrow. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted July 29, 2011 Author Share Posted July 29, 2011 No, I'd have to actually test the code to figure that out, which takes longer. It's bed time for me though, so I'll have to look at it tomorrow. bed time? its 4pm Thank you so much Rocky for your time! regards, SonnyBoy Link to comment Share on other sites More sharing options...
rocky Posted July 30, 2011 Share Posted July 30, 2011 Try: public static function updateQuantity($product, $id_order = NULL) { global $cookie; if (!is_array($product)) die (Tools::displayError()); if (!Configuration::get('PS_STOCK_MANAGEMENT')) return true; if (Pack::isPack((int)($product['id_product']))) { $products_pack = Pack::getItems((int)($product['id_product']), (int)(Configuration::get('PS_LANG_DEFAULT'))); foreach($products_pack AS $product_pack) { $tab_product_pack['id_product'] = (int)($product_pack->id); $tab_product_pack['id_product_attribute'] = self::getDefaultAttribute($tab_product_pack['id_product'], 1); $tab_product_pack['cart_quantity'] = (int)($product_pack->pack_quantity * $product['cart_quantity']); self::updateQuantity($tab_product_pack); } } $productObj = new Product((int)$product['id_product'], false, (int)Configuration::get('PS_LANG_DEFAULT')); $features = $productObj->getFrontFeatures((int)$cookie->id_lang); $featureValue = null; foreach ($features as $feature) if ($feature['name'] == 'xyz') $featureValue = $feature['value']; return $productObj->addStockMvt(-(int)($product['cart_quantity'])*($featureValue), (int)_STOCK_MOVEMENT_ORDER_REASON_, (int)$product['id_product_attribute'], (int)$id_order, NULL); } Link to comment Share on other sites More sharing options...
SonnyBoyII Posted July 31, 2011 Author Share Posted July 31, 2011 Its working !! Thanks Rocky! Now, I have the same problem with another function from the same class which I trying override... I have tried to do exactly the same. The modyfication is working if I use $depth field for instance. If I refound a product in "order" section the loop will crash the page. Here is my code: public static function reinjectQuantities(&$orderDetail, $quantity) { global $cookie; if (!Validate::isLoadedObject($orderDetail)) die(Tools::displayError()); if (Pack::isPack((int)($orderDetail->product_id))) { $products_pack = Pack::getItems((int)($orderDetail->product_id), (int)(Configuration::get('PS_LANG_DEFAULT'))); foreach($products_pack AS $product_pack) if (!$product_pack->addStockMvt((int)($product_pack->pack_quantity * $quantity), _STOCK_MOVEMENT_ORDER_REASON_, (int)$product_pack->id_product_attribute, (int)$orderDetail->id_order, (int)$cookie->id_employee)) return false; } $features = $productObj->getFrontFeatures((int)$cookie->id_lang); $featureValue = null; foreach ($features as $feature) if ($feature['name'] == 'multi') $featureValue = $feature['value']; $product = new Product((int)$orderDetail->product_id); if (!$product->addStockMvt((int)$quantity*($featureValue), _STOCK_MOVEMENT_ORDER_REASON_, (int)$orderDetail->product_attribute_id, (int)$orderDetail->id_order, (int)$cookie->id_employee)) return false; $orderDetail->product_quantity_reinjected += (int)($quantity); return true; } Link to comment Share on other sites More sharing options...
rocky Posted August 1, 2011 Share Posted August 1, 2011 You're trying to use the $product object before it's created! Try: public static function reinjectQuantities(&$orderDetail, $quantity) { global $cookie; if (!Validate::isLoadedObject($orderDetail)) die(Tools::displayError()); if (Pack::isPack((int)($orderDetail->product_id))) { $products_pack = Pack::getItems((int)($orderDetail->product_id), (int)(Configuration::get('PS_LANG_DEFAULT'))); foreach($products_pack AS $product_pack) if (!$product_pack->addStockMvt((int)($product_pack->pack_quantity * $quantity), _STOCK_MOVEMENT_ORDER_REASON_, (int)$product_pack->id_product_attribute, (int)$orderDetail->id_order, (int)$cookie->id_employee)) return false; } $product = new Product((int)$orderDetail->product_id, (int)$cookie->id_lang); $features = $product->getFrontFeatures((int)$cookie->id_lang); $featureValue = null; foreach ($features as $feature) if ($feature['name'] == 'multi') $featureValue = $feature['value']; if (!$product->addStockMvt((int)$quantity*($featureValue), _STOCK_MOVEMENT_ORDER_REASON_, (int)$orderDetail->product_attribute_id, (int)$orderDetail->id_order, (int)$cookie->id_employee)) return false; $orderDetail->product_quantity_reinjected += (int)($quantity); return true; } Link to comment Share on other sites More sharing options...
SonnyBoyII Posted August 1, 2011 Author Share Posted August 1, 2011 THANKS ROCKY!! Thank this, that topic could be solved: http://www.prestashop.com/forums/topic/121072-quantity-multiply-by-a-variable-how/page__gopid__599174?do=findComment&comment=599174 I think a guide about playing with presta variables and doing customisation like this might be a good idea. Link to comment Share on other sites More sharing options...
SonnyBoyII Posted September 6, 2011 Author Share Posted September 6, 2011 Hi guys, Now, I would like to use feature values in shopping-cart.tpl. This code doesnt work .... {assign var="features" value=$product.features} {foreach from=$features item=feature} {feature.name} {/foreach} Link to comment Share on other sites More sharing options...
JulianM Posted November 8, 2011 Share Posted November 8, 2011 The code above worked for me on product-list.php Link to comment Share on other sites More sharing options...
Qberon Posted March 12, 2012 Share Posted March 12, 2012 {assign var="features" value=$product.features} {foreach from=$features item=feature} {feature.name} {/foreach} This code works perfect in product.tpl But how can I get features values in shopping-cart.tpl shopping-cart-product-line.tpl blockcart.tpl blockcart-json.tpl When I try parse features array in this blocks nothing happen. 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