示例#1
0
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($amount = $product->getCustomOption('credit_price_amount')) {
         $finalPrice = $amount->getValue();
     }
     return parent::_applyOptionsPrice($product, $qty, $finalPrice);
 }
示例#2
0
 public function getPrice($product)
 {
     $product->load($product->getId());
     //       Mage::log($product->debug(), null, 'test.log');
     $data = $product->getData();
     $total = $this->getCartTotal();
     # Fixed price
     $price = (double) parent::getPrice($product);
     # Percent price
     if ($price_percent = $data['cartproducts_price_percent']) {
         $price_percent = $total * (double) $price_percent / 100;
     }
     # Range price
     if ($price_range = $data['cartproducts_price_range']) {
         $range = explode(',', $price_range);
         foreach ($range as $pair) {
             $pair = explode('=', $pair);
             if ($total <= $pair[0]) {
                 return $price_range = (double) $pair[1];
             }
         }
     }
     $price = max($price, $price_percent);
     return $price;
 }
示例#3
0
 /**
  * @param Mage_Catalog_Model_Product $product
  * @param float                      $productQty
  * @param Mage_Catalog_Model_Product $childProduct
  * @param float                      $childProductQty
  *
  * @return float
  */
 public function getChildFinalPrice($product, $productQty, $childProduct, $childProductQty)
 {
     // Bail if the parameters are unexpected and let the core code handle (or fail)
     if (!$product instanceof Mage_Catalog_Model_Product || !$childProduct instanceof Mage_Catalog_Model_Product) {
         return parent::getChildFinalPrice($product, $productQty, $childProduct, $childProductQty);
     }
     // If the parent product type is unexpected then bail and let core handle
     $type = $product->getTypeInstance(true);
     if (!$type instanceof OpenMage_KittedProduct_Model_Product_Type) {
         return parent::getChildFinalPrice($product, $productQty, $childProduct, $childProductQty);
     }
     // Calculate the normal, unadjusted linked items total
     $calculatedTotal = 0.0;
     foreach ($type->getAssociatedProducts($product, false) as $associatedProduct) {
         $calculatedTotal += $associatedProduct->getPrice() * $associatedProduct->getQty();
     }
     // Generate a child price multiplier
     $priceMultiplier = $calculatedTotal > 0.0 ? $product->getPrice() / $calculatedTotal : 1.0;
     // Generate the normal final price
     $finalPrice = $childProduct->getFinalPrice($childProductQty);
     // Multiply the final price by the multiplier to get the adjusted final price
     $finalPrice *= $priceMultiplier;
     // Round the final price
     $finalPrice = $product->getStore()->roundPrice($finalPrice);
     return $finalPrice;
 }
示例#4
0
 /**
  * Returns product final price depending on options chosen
  *
  * @param   double $qty
  * @param   Mage_Catalog_Model_Product $product
  * @return  double
  */
 public function getFinalPrice($qty = null, $product)
 {
     if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
         return $product->getCalculatedFinalPrice();
     }
     $finalPrice = parent::getFinalPrice($qty, $product);
     if ($product->hasCustomOptions()) {
         /* @var $typeInstance Mage_Catalog_Model_Product_Type_Grouped */
         $typeInstance = $product->getTypeInstance(true);
         $associatedProducts = $typeInstance->setStoreFilter($product->getStore(), $product)->getAssociatedProducts($product);
         foreach ($associatedProducts as $childProduct) {
             /* @var $childProduct Mage_Catalog_Model_Product */
             $option = $product->getCustomOption('associated_product_' . $childProduct->getId());
             if (!$option) {
                 continue;
             }
             $childQty = $option->getValue();
             if (!$childQty) {
                 continue;
             }
             $finalPrice += $childProduct->getFinalPrice($childQty) * $childQty;
         }
     }
     $product->setFinalPrice($finalPrice);
     Mage::dispatchEvent('catalog_product_type_grouped_price', array('product' => $product));
     return max(0, $product->getData('final_price'));
 }
 /**
  * Get product final price
  *
  * @param   double $qty
  * @param   Mage_Catalog_Model_Product $product
  * @return  double
  */
 public function getFinalPrice($qty = null, $product)
 {
     if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
         return $product->getCalculatedFinalPrice();
     }
     $finalPrice = parent::getFinalPrice($qty, $product);
     $product->getTypeInstance(true)->setStoreFilter($product->getStore(), $product);
     $attributes = $product->getTypeInstance(true)->getConfigurableAttributes($product);
     $selectedAttributes = array();
     if ($product->getCustomOption('attributes')) {
         $selectedAttributes = unserialize($product->getCustomOption('attributes')->getValue());
     }
     $basePrice = $finalPrice;
     foreach ($attributes as $attribute) {
         $attributeId = $attribute->getProductAttribute()->getId();
         $value = $this->_getValueByIndex($attribute->getPrices() ? $attribute->getPrices() : array(), isset($selectedAttributes[$attributeId]) ? $selectedAttributes[$attributeId] : null);
         if ($value) {
             if ($value['pricing_value'] != 0) {
                 $finalPrice += $this->_calcSelectionPrice($value, $basePrice);
             }
         }
     }
     $product->setFinalPrice($finalPrice);
     return max(0, $product->getData('final_price'));
 }
 /**
  * Get product tier price by qty
  * Extended to hide tier pricing when product is a subscription product
  *
  * @param   float $qty
  * @param   Mage_Catalog_Model_Product $product
  * @return  float
  */
 public function getTierPrice($qty = null, $product)
 {
     if ($subscription = $this->_helper()->getProductSubscription($product)) {
         return array();
     }
     return parent::getTierPrice($qty, $product);
 }
 public function getFinalPrice($qty = null, $product)
 {
     if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
         return $product->getCalculatedFinalPrice();
     }
     $finalPrice = parent::getFinalPrice($qty, $product);
     $finalPrice = $finalPrice - $finalPrice / 10;
     return $finalPrice;
 }
示例#8
0
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($amount = $product->getCustomOption('amount')) {
         $store = Mage::app()->getStore();
         $finalPrice = $amount->getValue();
         $finalPrice /= $store->convertPrice(1);
     }
     return parent::_applyOptionsPrice($product, $qty, $finalPrice);
 }
示例#9
0
 public function getFinalPrice($qty = null, $product)
 {
     // if product was added to cart, get the price from user input, otherwise returns the price was set in admin
     if ($product->getCustomOption('info_buyRequest')) {
         $price = 0.0;
         $buyRequest = unserialize($product->getCustomOption('info_buyRequest')->getValue());
         if (is_array($buyRequest) && isset($buyRequest['service_price'])) {
             $price += $buyRequest['service_price'];
         }
         return $price;
     }
     return parent::getFinalPrice($qty, $product);
 }
示例#10
0
 protected function _applyOptionsPrice($product, $qty, $finalPrice)
 {
     if ($option = $product->getCustomOption('giftcard_value')) {
         $optionValue = $option->getValue();
         if (is_numeric($optionValue)) {
             $series = Mage::getModel('giftcard/series');
             $price = $series->getProductPrice($product, $optionValue);
             if ($price) {
                 $finalPrice = $price;
             }
         }
     }
     return parent::_applyOptionsPrice($product, $qty, $finalPrice);
 }
示例#11
0
 public function getFinalPrice($qty = null, $product)
 {
     if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
         return $product->getCalculatedFinalPrice();
     }
     $finalPrice = parent::getFinalPrice($qty, $product);
     $product->setFinalPrice($finalPrice);
     Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
     $finalPrice = $product->getData('final_price');
     $finalPrice = $this->_applyTierPrice($product, $qty, $finalPrice);
     $finalPrice = $this->_applySpecialPrice($product, $finalPrice);
     $finalPrice = $this->_applyCustomTierPrice($product, $qty, $finalPrice);
     $finalPrice = $this->_applyOptionsPrice($product, $qty, $finalPrice);
     return $finalPrice;
 }
示例#12
0
文件: Price.php 项目: rcclaudrey/dev
 /**
  * @param float $qty
  * @param Mage_Catalog_Model_Product $product
  * @return float
  */
 public function getFinalPrice($qty = null, $product)
 {
     if (!(Mage::helper('amconf')->getConfigUseSimplePrice() == 2 || (Mage::helper('amconf')->getConfigUseSimplePrice() == 1 and $product->getData('amconf_simple_price')))) {
         return parent::getFinalPrice($qty, $product);
     }
     if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
         return $product->getCalculatedFinalPrice();
     }
     if (version_compare(Mage::getVersion(), '1.7', '<')) {
         // based on 1.6.2.0 version
         // get configurable's own price,
         // apply its tier and special prices,
         // dispatch 'catalog_product_get_final_price'
         // at last apply its custom options price
         $finalPrice = Mage_Catalog_Model_Product_Type_Price::getFinalPrice($qty, $product);
         // skip native configurable price calculation
         // ...
         // get child simple product, calculate its price with tier and special prices applied
         // and that's the only we need, we ignore all above ))
         $finalPrice = $this->_calcAmConfigurablePrice($qty, $product, $finalPrice);
     } else {
         // based on 1.7.0.2 version
         // get configurable's own price,
         // apply its group, tier and special prices,
         $basePrice = $this->getBasePrice($product, $qty);
         // dispatch 'catalog_product_get_final_price'
         $finalPrice = $basePrice;
         $product->setFinalPrice($finalPrice);
         Mage::dispatchEvent('catalog_product_get_final_price', array('product' => $product, 'qty' => $qty));
         $finalPrice = $product->getData('final_price');
         // skip native configurable price calculation
         // $finalPrice += $this->getTotalConfigurableItemsPrice($product, $finalPrice);
         // at last apply its custom options price
         $finalPrice += $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice;
         // get child simple product, calculate its price with tier and special prices applied
         // and that's the only we need, we ignore all above ))
         $finalPrice = $this->_calcAmConfigurablePrice($qty, $product, $finalPrice);
     }
     $product->setFinalPrice($finalPrice);
     return max(0, $product->getData('final_price'));
 }
示例#13
0
 /**
  * Retrieve product final price
  *
  * @param integer $qty
  * @param Mage_Catalog_Model_Product $product
  * @return float
  */
 public function getFinalPrice($qty = null, $product)
 {
     if (is_null($qty) && !is_null($product->getCalculatedFinalPrice())) {
         return $product->getCalculatedFinalPrice();
     }
     $finalPrice = parent::getFinalPrice($qty, $product);
     /**
      * links prices are added to base product price only if they can be purchased separately
      */
     if ($product->getLinksPurchasedSeparately()) {
         if ($linksIds = $product->getCustomOption('downloadable_link_ids')) {
             $linkPrice = 0;
             $links = $product->getTypeInstance(true)->getLinks($product);
             foreach (explode(',', $linksIds->getValue()) as $linkId) {
                 if (isset($links[$linkId])) {
                     $linkPrice += $links[$linkId]->getPrice();
                 }
             }
             $finalPrice += $linkPrice;
         }
     }
     $product->setData('final_price', $finalPrice);
     return max(0, $product->getData('final_price'));
 }
示例#14
0
 /**
  * Whether tier price value fixed or percent of original price
  *
  * @param Mage_Catalog_Model_Product_Type_Price $priceObject
  * @return bool
  */
 protected function _isPriceFixed($priceObject)
 {
     return $priceObject->isTierPriceFixed();
 }
示例#15
0
 public function testIsTierPriceFixed()
 {
     $this->assertTrue($this->_model->isTierPriceFixed());
 }
示例#16
0
 /**
  * @param null $product
  * @return mixed
  */
 public function getPriceByCatalogRules($product = null)
 {
     if (is_null($product)) {
         $product = $this->getProduct();
     }
     if (!$this->getConfigVar('apply_catalog_price_rules', 'columns')) {
         // Commented to avoid loops: return $this->getPrice($product);
         return $product->getPrice();
     }
     if (!isset($this->_cache_price_by_catalog_rules[$product->getId()])) {
         $this->_cache_price_by_catalog_rules[$product->getId()] = Mage_Catalog_Model_Product_Type_Price::calculatePrice($product->getPrice(), false, false, false, false, $this->getWebsiteId(), Mage_Customer_Model_Group::NOT_LOGGED_IN_ID, $product->getId());
         if ($this->_cache_price_by_catalog_rules[$product->getId()] <= 0) {
             // Commented to avoid loops: $this->_cache_price_by_catalog_rules[$product->getId()] = $this->getPrice($product);
             $this->_cache_price_by_catalog_rules[$product->getId()] = $product->getPrice();
         }
     }
     return $this->_cache_price_by_catalog_rules[$product->getId()];
 }
 /**
  * @param null $product
  * @return mixed
  */
 public function getPriceByCatalogRules($product = null)
 {
     if (is_null($product)) {
         $product = $this->getProduct();
     }
     if (!$this->getConfigVar('apply_catalog_price_rules', 'columns')) {
         // Commented to avoid loops: return $this->getPrice($product);
         return $product->getPrice();
     }
     if (!isset($this->_cache_price_by_catalog_rules[$product->getId()])) {
         $this->_cache_price_by_catalog_rules[$product->getId()] = Mage_Catalog_Model_Product_Type_Price::calculatePrice($product->getPrice(), false, false, false, false, $this->getWebsiteId(), Mage::getStoreConfig('customer/create_account/default_group', $this->getStoreId()), $product->getId());
         if ($this->_cache_price_by_catalog_rules[$product->getId()] <= 0) {
             // Commented to avoid loops: $this->_cache_price_by_catalog_rules[$product->getId()] = $this->getPrice($product);
             $this->_cache_price_by_catalog_rules[$product->getId()] = $product->getPrice();
         }
     }
     return $this->_cache_price_by_catalog_rules[$product->getId()];
 }
示例#18
0
 public function getPrice($product)
 {
     if ($this->getPriceModel()->isSubscriptionPriceSet($product) && $product->getAwSarpEnabled()) {
         $priceWithShippingCost = Mage::helper('sarp')->getSarpSubscriptionPrice($product);
         if ($product->getCustomOption('aw_sarp_subscription_type') && ($typeId = $product->getCustomOption('aw_sarp_subscription_type')->getValue())) {
             if ($typeId == AW_Sarp_Model_Period::PERIOD_TYPE_NONE) {
                 return parent::getPrice($product);
             } else {
                 return $priceWithShippingCost;
             }
         } elseif ($product->getTypeInstance()->getDefaultSubscriptionPeriodId() != AW_Sarp_Model_Period::PERIOD_TYPE_NONE) {
             return $priceWithShippingCost;
         }
     } else {
         // Probably category page
         $_product = Mage::getModel('catalog/product')->load($product->getId());
         $priceWithShippingCost = Mage::helper('sarp')->getSarpSubscriptionPrice($_product);
         if ($_product->getTypeInstance()->requiresSubscriptionOptions($_product)) {
             if ($priceWithShippingCost) {
                 $price = $priceWithShippingCost;
                 $product->setData('final_price', $price);
                 return $price;
             }
         }
     }
     return parent::getPrice($product);
 }