/**
  * 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'));
 }
Пример #2
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'));
 }
Пример #3
0
 /**
  * Retrieve product final price
  * Extended to return subscription price when product is a subscription product
  * When configured that catalog prices are including tax and subscription pricee excluding tax,
  * the subscription item prices of new orders change when tax percentage is changed
  *
  * @param float|null $qty
  * @param Mage_Catalog_Model_Product $product
  * @return float
  */
 public function getFinalPrice($qty = null, $product)
 {
     if ($subscriptionItem = $this->_helper()->getSubscriptionItem($product)) {
         $subscription = $subscriptionItem->getSubscription();
         // @todo Performance
         $store = $product->getStore();
         $configCatalogInclTax = Mage::getModel('tax/config')->priceIncludesTax($store);
         $useSubscriptionPricesIncTax = Mage::helper('adyen_subscription/config')->getPriceIncludesTax($store);
         if ($configCatalogInclTax && $useSubscriptionPricesIncTax) {
             return $subscriptionItem->getPriceInclTax();
         }
         if (!$configCatalogInclTax && !$useSubscriptionPricesIncTax) {
             return $subscriptionItem->getPrice();
         }
         if ($configCatalogInclTax && !$useSubscriptionPricesIncTax) {
             $priceExclTax = $subscriptionItem->getPrice();
             $customerPercent = Mage::helper('adyen_subscription/quote')->getCustomerTaxPercent($subscription, $product);
             $customerTax = Mage::getSingleton('tax/calculation')->calcTaxAmount($priceExclTax, $customerPercent, false, false);
             $customerPriceInclTax = $store->roundPrice($priceExclTax + $customerTax);
             return $customerPriceInclTax;
         }
         if (!$configCatalogInclTax && $useSubscriptionPricesIncTax) {
             $message = 'Please fix the tax settings;' . ' it\'s not possible to set catalog prices to excl. tax and subscription prices to incl. tax';
             Adyen_Subscription_Exception::throwException($message);
         }
     }
     if ($subscription = $this->_helper()->getProductSubscription($product)) {
         return $this->_applyOptionsPrice($product, $qty, $subscription->getPrice());
     }
     return parent::getFinalPrice($qty, $product);
 }
Пример #4
0
 public function testGetFinalPrice()
 {
     $product = new Mage_Catalog_Model_Product();
     $product->load(1);
     // fixture
     // regular & tier prices
     $this->assertEquals(10.0, $this->_model->getFinalPrice(1, $product));
     $this->assertEquals(8.0, $this->_model->getFinalPrice(2, $product));
     $this->assertEquals(5.0, $this->_model->getFinalPrice(5, $product));
     // with options
     $product->addCustomOption('option_ids', implode(',', array_keys($product->getOptions())));
     foreach ($product->getOptions() as $id => $option) {
         $product->addCustomOption("option_{$id}", $option->getValue());
     }
     $this->assertEquals(13.0, $this->_model->getFinalPrice(1, $product));
 }
Пример #5
0
 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;
 }
 /**
  * Retrieve product final price
  * Extended to return subscription price when product is a subscription product
  *
  * @param float|null $qty
  * @param Mage_Catalog_Model_Product $product
  * @return float
  */
 public function getFinalPrice($qty = null, $product)
 {
     if ($subscriptionItem = $this->_helper()->getSubscriptionItem($product)) {
         return $subscriptionItem->getPriceInclTax();
     }
     if ($subscription = $this->_helper()->getProductSubscription($product)) {
         return $subscription->getPrice();
     }
     return parent::getFinalPrice($qty, $product);
 }
Пример #7
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);
 }
Пример #8
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;
 }
Пример #9
0
 /**
  * @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'));
 }
Пример #10
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'));
 }
Пример #11
0
 public function getFinalPrice($qty = null, $product)
 {
     try {
         $baseProduct = Mage::getModel('catalog/product')->setStoreId($product->getStoreId())->load($product->getId());
         if ($this->getPriceModel()->isSubscriptionPriceSet($baseProduct)) {
             if ($product->getCustomOption('aw_sarp_subscription_type') && ($typeId = $product->getCustomOption('aw_sarp_subscription_type')->getValue()) && $baseProduct->getAwSarpEnabled()) {
                 if ($typeId == AW_Sarp_Model_Period::PERIOD_TYPE_NONE) {
                     return parent::getFinalPrice($qty, $product);
                 } else {
                     if ($this->isOrderedFirstTime($baseProduct) && is_numeric($baseProduct->getAwSarpFirstPeriodPrice()) && $baseProduct->getAwSarpFirstPeriodPrice() >= 0 && !Mage::helper('sarp')->isReordered($product->getId())) {
                         //return $this->calculateFinalPrice($product, $qty, $baseProduct->getAwSarpFirstPeriodPrice());
                         return $this->calculateFinalPrice($product, $qty, Mage::helper('sarp')->getSarpFirstPeriodPrice($baseProduct));
                     } else {
                         return $this->calculateFinalPrice($product, $qty, Mage::helper('sarp')->getSarpSubscriptionPrice($baseProduct, true));
                     }
                 }
             }
         }
     } catch (Exception $e) {
         echo $e->getMessage();
         die;
     }
     return parent::getFinalPrice($qty, $product);
 }