Example #1
0
 public static function getCartNbPoints($cart, $newProduct = NULL)
 {
     $total = 0;
     if (Validate::isLoadedObject($cart)) {
         $cartProducts = $cart->getProducts();
         $taxesEnabled = Product::getTaxCalculationMethod();
         if (isset($newProduct) and !empty($newProduct)) {
             $cartProductsNew['id_product'] = (int) $newProduct->id;
             if ($taxesEnabled == PS_TAX_EXC) {
                 $cartProductsNew['price'] = number_format($newProduct->getPrice(false, (int) $newProduct->getDefaultIdProductAttribute()), 2, '.', '');
             } else {
                 $cartProductsNew['price_wt'] = number_format($newProduct->getPrice(true, (int) $newProduct->getDefaultIdProductAttribute()), 2, '.', '');
             }
             $cartProductsNew['cart_quantity'] = 1;
             $cartProducts[] = $cartProductsNew;
         }
         foreach ($cartProducts as $product) {
             if (!(int) Configuration::get('PS_LOYALTY_NONE_AWARD') and Product::isDiscounted((int) $product['id_product'])) {
                 if (isset(Context::getContext()->smarty) and is_object($newProduct) and $product['id_product'] == $newProduct->id) {
                     Context::getContext()->smarty->assign('no_pts_discounted', 1);
                 }
                 continue;
             }
             $total += ($taxesEnabled == PS_TAX_EXC ? $product['price'] : $product['price_wt']) * (int) $product['cart_quantity'];
         }
         foreach ($cart->getCartRules(false) as $cart_rule) {
             $total -= $cart_rule['value_real'];
         }
     }
     return self::getNbPointsByPrice($total);
 }
Example #2
0
 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) ($pointsAfter - $pointsBefore);
         } else {
             if (!(int) Configuration::get('PS_LOYALTY_NONE_AWARD') && Product::isDiscounted((int) $product->id)) {
                 $points = 0;
                 $this->smarty->assign('no_pts_discounted', 1);
             } else {
                 $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, 'point_rate' => Configuration::get('PS_LOYALTY_POINT_RATE'), 'point_value' => Configuration::get('PS_LOYALTY_POINT_VALUE'), 'points_in_cart' => (int) $pointsBefore, 'voucher' => LoyaltyModule::getVoucherValue((int) $pointsAfter), 'none_award' => Configuration::get('PS_LOYALTY_NONE_AWARD')));
         return $this->display(__FILE__, 'product.tpl');
     }
     return false;
 }
 public static function getCartNbPoints($cart, $newProduct = NULL)
 {
     $total = 0;
     if (Validate::isLoadedObject($cart)) {
         $currentContext = Context::getContext();
         $context = clone $currentContext;
         $context->cart = $cart;
         // if customer is logged we do not recreate it
         if (!$context->customer->isLogged(true)) {
             $context->customer = new Customer($context->cart->id_customer);
         }
         $context->language = new Language($context->cart->id_lang);
         $context->shop = new Shop($context->cart->id_shop);
         $context->currency = new Currency($context->cart->id_currency, null, $context->shop->id);
         $cartProducts = $cart->getProducts();
         $taxesEnabled = Product::getTaxCalculationMethod();
         if (isset($newProduct) and !empty($newProduct)) {
             $cartProductsNew['id_product'] = (int) $newProduct->id;
             if ($taxesEnabled == PS_TAX_EXC) {
                 $cartProductsNew['price'] = number_format($newProduct->getPrice(false, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', '');
             } else {
                 $cartProductsNew['price_wt'] = number_format($newProduct->getPrice(true, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', '');
             }
             $cartProductsNew['cart_quantity'] = 1;
             $cartProducts[] = $cartProductsNew;
         }
         foreach ($cartProducts as $product) {
             if (!(int) Configuration::get('PS_LOYALTY_NONE_AWARD') and Product::isDiscounted((int) $product['id_product'])) {
                 if (isset(Context::getContext()->smarty) and is_object($newProduct) and $product['id_product'] == $newProduct->id) {
                     Context::getContext()->smarty->assign('no_pts_discounted', 1);
                 }
                 continue;
             }
             $total += ($taxesEnabled == PS_TAX_EXC ? $product['price'] : $product['price_wt']) * (int) $product['cart_quantity'];
         }
         foreach ($cart->getCartRules(false) as $cart_rule) {
             if ($taxesEnabled == PS_TAX_EXC) {
                 $total -= $cart_rule['value_tax_exc'];
             } else {
                 $total -= $cart_rule['value_real'];
             }
         }
     }
     return self::getNbPointsByPrice($total);
 }
 public static function getCartNbPoints($cart, $newProduct = null)
 {
     $total = 0;
     if (Validate::isLoadedObject($cart)) {
         $cartProducts = $cart->getProducts();
         $taxesEnabled = Product::getTaxCalculationMethod();
         if (isset($newProduct) && !empty($newProduct)) {
             $cartProductsNew['id_product'] = (int) $newProduct->id;
             if ($taxesEnabled == PS_TAX_EXC) {
                 $cartProductsNew['price'] = number_format($newProduct->getPrice(false, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', '');
             } else {
                 $cartProductsNew['price_wt'] = number_format($newProduct->getPrice(true, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', '');
             }
             $cartProductsNew['cart_quantity'] = 1;
             $cartProducts[] = $cartProductsNew;
         }
         foreach ($cartProducts as $product) {
             if (!(int) Configuration::get('PS_LOYALTY_NONE_AWARD') && Product::isDiscounted((int) $product['id_product'])) {
                 global $smarty;
                 if (isset($smarty) && is_object($newProduct) && $product['id_product'] == $newProduct->id) {
                     $smarty->assign('no_pts_discounted', 1);
                 }
                 continue;
             }
             $price = $taxesEnabled == PS_TAX_EXC ? $product['price'] : $product['price_wt'];
             $total += self::getNbPointsByPrice($price, isset($cart->id_currency) ? (int) $cart->id_currency : 0) * (int) $product['cart_quantity'];
         }
         foreach ($cart->getDiscounts(false) as $discount) {
             $total -= self::getNbPointsByPrice($discount['value_real'], isset($cart->id_currency) ? (int) $cart->id_currency : 0);
         }
     }
     return $total;
 }
Example #5
0
 public static function getCartNbPoints($cart, $newProduct = NULL)
 {
     $total = 0;
     if (Validate::isLoadedObject($cart)) {
         $currentContext = Context::getContext();
         $context = clone $currentContext;
         $context->cart = $cart;
         // if customer is logged we do not recreate it
         if (!$context->customer->isLogged(true)) {
             $context->customer = new Customer($context->cart->id_customer);
         }
         $context->language = new Language($context->cart->id_lang);
         $context->shop = new Shop($context->cart->id_shop);
         $context->currency = new Currency($context->cart->id_currency, null, $context->shop->id);
         $categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY_SOURCE');
         if ($categories != '' && $categories != 0) {
             $categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY_SOURCE'));
         } else {
             die(Tools::displayError());
         }
         $categories_array = array();
         foreach ($categories as $id_category) {
             array_push($categories_array, array('id_category' => $id_category));
         }
         $cartProducts = $cart->getProducts();
         $taxesEnabled = Product::getTaxCalculationMethod();
         if (isset($newProduct) and !empty($newProduct)) {
             $cartProductsNew['id_product'] = (int) $newProduct->id;
             if ($taxesEnabled == PS_TAX_EXC) {
                 $cartProductsNew['price'] = number_format($newProduct->getPrice(false, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', '');
             } else {
                 $cartProductsNew['price_wt'] = number_format($newProduct->getPrice(true, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', '');
             }
             $cartProductsNew['cart_quantity'] = 1;
             $cartProducts[] = $cartProductsNew;
         }
         foreach ($cartProducts as $product) {
             if (!(int) Configuration::get('PS_LOYALTY_NONE_AWARD') and Product::isDiscounted((int) $product['id_product'])) {
                 if (isset(Context::getContext()->smarty) and is_object($newProduct) and $product['id_product'] == $newProduct->id) {
                     Context::getContext()->smarty->assign('no_pts_discounted', 1);
                 }
                 continue;
             }
             /* Avoid generate points for product is not in source category */
             if (!Product::idIsOnCategoryId((int) $product['id_product'], $categories_array)) {
                 continue;
             }
             $total += ($taxesEnabled == PS_TAX_EXC ? $product['price'] : $product['price_wt']) * (int) $product['cart_quantity'];
         }
         foreach ($cart->getCartRules(false) as $cart_rule) {
             if ($taxesEnabled == PS_TAX_EXC) {
                 $total -= $cart_rule['value_tax_exc'];
             } else {
                 $total -= $cart_rule['value_real'];
             }
         }
     }
     return self::getNbPointsByPrice($total);
 }