Keyosh Posted June 13, 2016 Share Posted June 13, 2016 (edited) Bonjour à tous !! J'essaye actuellement d'afficher les prix spécifiques de chaque produit en fonction des quantités (vendu par unité/3/5/10/etc) J'ai tenté d'adapter un petit peu le code (product.php et product-list.tpl) proposé par Nemo sur son site : http://blog.belvg.com/how-to-display-special-prices-according-to-quantity-at-the-product-list-category-in-prestashop.html Je ne vous montre pas encore le mien, c'est en chantier et autant repartir sur une bonne base. Le problème c'est que je n'obtiens qu'un seul prix spécifique (surement lié à $product.quantity_discounts[0]) Sauriez-vous m'aiguillez afin de realiser une boucle qui récupère chacune des quantités et leur prix spécifique pour les afficher? Dans mon tableau Smarty Debug j'obtiens : ->scope = "file:./product-list.tpl" $product Smarty_Variable Object (6)->value = Array (85) id_product => "44" id_supplier => "0" id_manufacturer => "0" id_category_default => "440" id_shop_default => "1" id_tax_rules_group => "1" on_sale => "0" online_only => "0" ean13 => "" upc => "" ecotax => "0.000000" quantity => 0 minimal_quantity => "1" price => 12 wholesale_price => "0.000000" unity => "" unit_price_ratio => "0.000000" additional_shipping_cost => "0.00" reference => "HUM-MANSAPHFEM" supplier_reference => "" location => "" width => "0.000000" height => "0.000000" depth => "0.000000" weight => "0.000000" out_of_stock => "2" quantity_discount => "0" customizable => "0" uploadable_files => "0" text_fields => "0" active => "1" redirect_type => "404" id_product_redirected => "0" available_for_order => "1" available_date => "0000-00-00" condition => "new" show_price => "1" indexed => "1" visibility => "both" cache_is_pack => "0" cache_has_attachments => "0" is_virtual => "0" cache_default_attribute => "0" date_add => "2016-06-09 11:58:44" date_upd => "2016-06-12 23:23:47" advanced_stock_management => "1" pack_stock_type => "3" id_shop => "1" id_product_attribute => "0" product_attribute_minimal_quantity => null description => "" description_short => "" available_now => "" available_later => "" link_rewrite => "mango" meta_description => "" meta_keywords => "" meta_title => "" name => "Mango " id_image => "fr-default" legend => null manufacturer_name => null category_default => "à collectionner" new => "1" orderprice => "10.000000" allow_oosp => 1 category => "-a-collectionner" link => "http://multin." attribute_price => 0 price_tax_exc => 10 price_without_reduction => 12 reduction => 0 specific_prices => false quantity_all_versions => 0 features => Array (0) attachments => Array (0) virtual => 0 pack => 0 packItems => Array (0) nopackprice => 0 customization_required => false rate => 20 tax_name => "TVA FR 20%" quantity_discounts => Array (2) 0 => Array (19) id_specific_price => "4" id_specific_price_rule => "0" id_cart => "0" id_product => "44" id_shop => "0" id_shop_group => "0" id_currency => "0" id_country => "0" id_group => "0" id_customer => "0" id_product_attribute => "0" price => "-1.000000" from_quantity => "3" reduction => "2.000000" reduction_tax => "1" reduction_type => "amount" from => "0000-00-00 00:00:00" to => "0000-00-00 00:00:00" score => "14" 1 => Array (19) id_specific_price => "5" id_specific_price_rule => "0" id_cart => "0" id_product => "44" id_shop => "0" id_shop_group => "0" id_currency => "0" id_country => "0" id_group => "0" id_customer => "0" id_product_attribute => "0" price => "-1.000000" from_quantity => "5" reduction => "3.000000" reduction_tax => "1" reduction_type => "amount" from => "0000-00-00 00:00:00" to => "0000-00-00 00:00:00" score => "14" color_list => ""->nocache = false->scope = "file:./product-list.tpl"->_loop = true->total = 1->key = 0 Je ne sais pas si c'est avec ça que je dois jouer mais toujours est-il que je ne suis pas encore assez bon niveau syntaxe pour m'en sortir à tous les coups.. Merci à ceux qui prendront le temps de me répondre, et merci à ceux qui aurait voulu mais sont aussi perdu que moi ! Edited June 13, 2016 by Keyosh (see edit history) Link to comment Share on other sites More sharing options...
Keyosh Posted June 13, 2016 Author Share Posted June 13, 2016 (edited) Re ! Du coup j'ai utilisé l'overide sur product.php : <?php class Product extends ProductCore { /* new function */ public static function getQtyDiscount($id_product, $id_shop, $id_currency, $id_country, $id_group){ //logic from ProductController::assignPriceAndTax() $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true, (int)Context::getContext()->customer->id); foreach ($quantity_discounts as &$quantity_discount) { if (isset($quantity_discount['id_product_attribute'])) { $combination = new Combination((int)$quantity_discount['id_product_attribute']); $attributes = $combination->getAttributesName((int)Context::getContext()->language->id); foreach ($attributes as $attribute) $quantity_discount['attributes'] = $attribute['name'].' - '; $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - '); } if ((int)$quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') $quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency); } unset($quantity_discount); return $quantity_discounts; } // override reason: quantity_discounts row public static function getProductProperties($id_lang, $row, Context $context = null) { $row = parent::getProductProperties($id_lang, $row, $context); $row['quantity_discounts'] = self::getQtyDiscount($row['id_product'], Context::getContext()->shop->id, $row['specific_prices']['id_currency'], $row['specific_prices']['id_country'], $row['specific_prices']['id_group'] ); //override reason return $row; } } Et ajouté ceci à mon product.tpl : <span itemprop="price" class="price product-price"> {if !$priceDisplay} {$productPrice=$product.price} {else} {$productPrice=$product.price} {/if} {if isset($product.quantity_discounts[0])} {if $product.quantity_discounts[0].price >= 0 || $product.quantity_discounts[0].reduction_type == 'amount'} {$discountPrice=$productPrice-$product.quantity_discounts[0].reduction|floatval} {else} {$discountPrice=$productPrice-($productPrice*$product.quantity_discounts[0].reduction)|floatval} {/if} {$discountPrice=$discountPrice*$product.quantity_discounts[0].from_quantity} {$product.quantity_discounts[0].from_quantity} {l s='pour'} {convertPrice price=$discountPrice} {else} {convertPrice price=$productPrice} {/if} J'essaye toujours de récupérer tous les prix spécifiques. Actuellement j'obtiens toujours le premier prix spécifique mais pas les suivants (manque la boucle). J'essaye de jouer avec [int] et les foreach un peu partout mais pas de résultats satisfaisant. Si quelqu'un a une idée ? Je vous tiens au jus ! Edited June 13, 2016 by Keyosh (see edit history) 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