Advertisement
Guest User

Untitled

a guest
Mar 20th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.75 KB | None | 0 0
  1. <?php
  2. /*
  3. * 2007-2012 PrestaShop
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.or...ses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@prestashop.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
  18. * versions in the future. If you wish to customize PrestaShop for your
  19. * needs please refer to http://www.prestashop.com for more information.
  20. *
  21. * @author PrestaShop SA <contact@prestashop.com-->
  22. * @copyright 2007-2012 PrestaShop SA
  23. * @version Release: $Revision: 14944 $
  24. * @license http://opensource.or...ses/osl-3.0.php Open Software License (OSL 3.0)
  25. * International Registered Trademark &amp; Property of PrestaShop SA
  26. */
  27.  
  28. class Product extends ProductCore
  29. {
  30. /**
  31. * Get product price
  32. *
  33. * @param integer $id_product Product id
  34. * @param boolean $usetax With taxes or not (optional)
  35. * @param integer $id_product_attribute Product attribute id (optional).
  36. * If set to false, do not apply the combination price impact. NULL does apply the default combination price impact.
  37. * @param integer $decimals Number of decimals (optional)
  38. * @param integer $divisor Useful when paying many time without fees (optional)
  39. * @param boolean $only_reduc Returns only the reduction amount
  40. * @param boolean $usereduc Set if the returned amount will include reduction
  41. * @param integer $quantity Required for quantity discount application (default value: 1)
  42. * @param boolean $forceAssociatedTax DEPRECATED - NOT USED Force to apply the associated tax. Only works when the parameter $usetax is true
  43. * @param integer $id_customer Customer ID (for customer group reduction)
  44. * @param integer $id_cart Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...)
  45. * @param integer $id_address Customer address ID. Required for price (tax included) calculation regarding the guest localization
  46. * @param variable_reference $specificPriceOutput.
  47. * If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object
  48. * @param boolean $with_ecotax insert ecotax in price output.
  49. * @return float Product price
  50. */
  51. public static function getPriceStatic($id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null,
  52. $only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null,
  53. $id_address = null, $specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null,
  54. $use_customer_price = true)
  55. {
  56.     if (!$context)
  57.     $context = Context::getContext();
  58.  
  59.     $cur_cart = $context->cart;
  60.  
  61.     if ($divisor !== null)
  62.     Tools::displayParameterAsDeprecated('divisor');
  63.  
  64.     if (!Validate::isBool($usetax) || !Validate::isUnsignedId($id_product))
  65.     die(Tools::displayError());
  66.     // Initializations
  67.     $id_group = (isset($context->customer) ? $context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_);
  68.  
  69.     // If there is cart in context or if the specified id_cart is different from the context cart id
  70.     if (!is_object($cur_cart) || (Validate::isUnsignedInt($id_cart) && $id_cart && $cur_cart->id != $id_cart))
  71.     {
  72.     /*
  73.     * When a user (e.g., guest, customer, Google...) is on PrestaShop, he has already its cart as the global (see /init.php)
  74.     * When a non-user calls directly this method (e.g., payment module...) is on PrestaShop, he does not have already it BUT knows the cart ID
  75.     * When called from the back office, cart ID can be inexistant
  76.     */
  77.     if (!$id_cart && !isset($context->employee))
  78.     die(Tools::displayError());
  79.     $cur_cart = new Cart($id_cart);
  80.     // Store cart in context to avoid multiple instantiations in BO
  81.     if (!Validate::isLoadedObject($context->cart))
  82.     $context->cart = $cur_cart;
  83.     }
  84.  
  85.     $cart_quantity = 0;
  86.     if ((int)$id_cart)
  87.     {
  88.     $condition = '';
  89.     $cache_name = (int)$id_cart.'_'.(int)$id_product;
  90.     if (!isset(self::$_cart_quantity[$cache_name]) || self::$_cart_quantity[$cache_name] != (int)$quantity)
  91.     self::$_cart_quantity[$cache_name] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
  92.    SELECT SUM(`quantity`)
  93.    FROM `'._DB_PREFIX_.'cart_product`
  94.    WHERE `id_product` = '.(int)$id_product.'
  95.    AND `id_cart` = '.(int)$id_cart);
  96.     $cart_quantity = self::$_cart_quantity[$cache_name];
  97.     }
  98.  
  99.     $id_currency = (int)Validate::isLoadedObject($context->currency) ? $context->currency->id : Configuration::get('PS_CURRENCY_DEFAULT');
  100.  
  101.     // retrieve address informations
  102.     $id_country = (int)$context->country->id;
  103.     $id_state = 0;
  104.     $zipcode = 0;
  105.  
  106.     if (!$id_address)
  107.     $id_address = $cur_cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
  108.  
  109.     if ($id_address)
  110.     {
  111.     $address_infos = Address::getCountryAndState($id_address);
  112.     if ($address_infos['id_country'])
  113.     {
  114.     $id_country = (int)$address_infos['id_country'];
  115.     $id_state = (int)$address_infos['id_state'];
  116.     $zipcode = $address_infos['postcode'];
  117.     }
  118.     }
  119.     else if (isset($context->customer->geoloc_id_country))
  120.     {
  121.     $id_country = (int)$context->customer->geoloc_id_country;
  122.     $id_state = (int)$context->customer->id_state;
  123.     $zipcode = (int)$context->customer->postcode;
  124.     }
  125.  
  126.     if (Tax::excludeTaxeOption())
  127.     $usetax = false;
  128.  
  129.     if ($usetax != false
  130.     && !empty($address_infos['vat_number'])
  131.     && $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY')
  132.     && Configuration::get('VATNUMBER_MANAGEMENT'))
  133.     $usetax = false;
  134.  
  135.     if (is_null($id_customer) && Validate::isLoadedObject($context->customer))
  136.     $id_customer = $context->customer->id;
  137.  
  138.     include_once(dirname(__FILE__).'../../../modules/categoryquantitydiscount/categoryquantitydiscount.php');
  139.     $cqd = new CategoryQuantityDiscount();
  140.  
  141.     return Product::priceCalculation(
  142.         $context->shop->id,
  143.         $id_product,
  144.         $id_product_attribute,
  145.         $id_country,
  146.         $id_state,
  147.         $zipcode,
  148.         $id_currency,
  149.         $id_group,
  150.         //$cart_quantity,
  151.         $cqd->getRealQuantity($id_product,
  152.         $id_cart,
  153.         $quantity),
  154.         $usetax,
  155.         $decimals,
  156.         $only_reduc,
  157.         $usereduc,
  158.         $with_ecotax,
  159.         $specific_price_output,
  160.         $use_group_reduction,
  161.         $id_customer,
  162.         $use_customer_price,
  163.         $id_cart,
  164.         $cqd->getRealQuantity($id_product,
  165.         $id_cart,
  166.         $quantity)
  167.     );
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement