From eeeaaa8e08110f6ed7963b0ad99b19a9eff215da Mon Sep 17 00:00:00 2001 From: lLefevre Date: Tue, 28 Aug 2012 08:27:46 +0000 Subject: [PATCH] [-] MO : loyalty : #PSCFV-3764 : display points of default attribute git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@17038 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Product.php | 16 ++++++++++++++++ modules/loyalty/LoyaltyModule.php | 4 ++-- modules/loyalty/loyalty.php | 20 +++++++++++++------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index ef452762f..6c5ac6f07 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -2638,6 +2638,22 @@ class ProductCore extends ObjectModel return (isset($row['id_product_attribute']) && $row['id_product_attribute']) ? (int)$row['id_product_attribute'] : 0; } + public function getDefaultIdProductAttribute() + { + if (!Combination::isFeatureActive()) + return 0; + + $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' + SELECT pa.`id_product_attribute` + FROM `'._DB_PREFIX_.'product_attribute` pa + '.Shop::addSqlAssociation('product_attribute', 'pa').' + WHERE pa.`id_product` = '.(int)$this->id.' + AND pa.`default_on` = 1' + ); + + return (isset($row['id_product_attribute']) && $row['id_product_attribute']) ? (int)$row['id_product_attribute'] : 0; + } + public function getPriceWithoutReduct($notax = false, $id_product_attribute = false) { return Product::getPriceStatic((int)$this->id, !$notax, $id_product_attribute, 6, null, false, false); diff --git a/modules/loyalty/LoyaltyModule.php b/modules/loyalty/LoyaltyModule.php index 40fafaf87..73dfbd66d 100644 --- a/modules/loyalty/LoyaltyModule.php +++ b/modules/loyalty/LoyaltyModule.php @@ -92,9 +92,9 @@ class LoyaltyModule extends ObjectModel { $cartProductsNew['id_product'] = (int)$newProduct->id; if ($taxesEnabled == PS_TAX_EXC) - $cartProductsNew['price'] = number_format($newProduct->getPrice(false, (int)($newProduct->getIdProductAttributeMostExpensive())), 2, '.', ''); + $cartProductsNew['price'] = number_format($newProduct->getPrice(false, (int)$newProduct->getDefaultIdProductAttribute()), 2, '.', ''); else - $cartProductsNew['price_wt'] = number_format($newProduct->getPrice(true, (int)($newProduct->getIdProductAttributeMostExpensive())), 2, '.', ''); + $cartProductsNew['price_wt'] = number_format($newProduct->getPrice(true, (int)$newProduct->getDefaultIdProductAttribute()), 2, '.', ''); $cartProductsNew['cart_quantity'] = 1; $cartProducts[] = $cartProductsNew; } diff --git a/modules/loyalty/loyalty.php b/modules/loyalty/loyalty.php index 749fba646..07147551d 100644 --- a/modules/loyalty/loyalty.php +++ b/modules/loyalty/loyalty.php @@ -432,15 +432,15 @@ class Loyalty extends Module public function hookExtraRight($params) { include_once(dirname(__FILE__).'/LoyaltyModule.php'); - + $product = new Product((int)Tools::getValue('id_product')); if (Validate::isLoadedObject($product)) { if (Validate::isLoadedObject($params['cart'])) { - $pointsBefore = (int)(LoyaltyModule::getCartNbPoints($params['cart'])); - $pointsAfter = (int)(LoyaltyModule::getCartNbPoints($params['cart'], $product)); - $points = (int)(LoyaltyModule::getNbPointsByPrice($product->getPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? false : true, (int)($product->getIdProductAttributeMostExpensive())))); + $pointsBefore = (int)LoyaltyModule::getCartNbPoints($params['cart']); + $pointsAfter = (int)LoyaltyModule::getCartNbPoints($params['cart'], $product); + $points = (int)($pointsAfter - $pointsBefore); } else { @@ -450,13 +450,19 @@ class Loyalty extends Module $this->smarty->assign('no_pts_discounted', 1); } else - $points = (int)(LoyaltyModule::getNbPointsByPrice($product->getPrice(Product::getTaxCalculationMethod() == PS_TAX_EXC ? false : true, (int)($product->getIdProductAttributeMostExpensive())))); + $points = (int)LoyaltyModule::getNbPointsByPrice( + $product->getPrice( + Product::getTaxCalculationMethod() == PS_TAX_EXC ? false : true, + (int)$product->getDefaultIdProductAttribute() + ) + ); + $pointsAfter = $points; $pointsBefore = 0; } $this->smarty->assign(array( - 'points' => (int)($points), - 'total_points' => (int)($pointsAfter), + 'points' => (int)$points, + 'total_points' => (int)$pointsAfter, 'point_rate' => Configuration::get('PS_LOYALTY_POINT_RATE'), 'point_value' => Configuration::get('PS_LOYALTY_POINT_VALUE'), 'points_in_cart' => (int)$pointsBefore,