/** * Get 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)) { $basePrice = $subscription->getPrice(); $finalPrice = $basePrice; $finalPrice += $this->getTotalConfigurableItemsPrice($product, $finalPrice); $finalPrice += $this->_applyOptionsPrice($product, $qty, $basePrice) - $basePrice; return $finalPrice; } return parent::getFinalPrice($qty, $product); }
/** * @magentoDataFixture Mage/Catalog/_files/product_configurable.php */ public function testGetFinalPrice() { $product = new Mage_Catalog_Model_Product(); $product->load(1); // fixture $model = new Mage_Catalog_Model_Product_Type_Configurable_Price(); // without configurable options $this->assertEquals(100.0, $model->getFinalPrice(1, $product)); // with configurable options $attributes = $product->getTypeInstance()->getConfigurableAttributes($product); foreach ($attributes as $attribute) { $prices = $attribute->getPrices(); $product->addCustomOption('attributes', serialize(array($attribute->getProductAttribute()->getId() => $prices[0]['value_index']))); break; } $this->assertEquals(105.0, $model->getFinalPrice(1, $product)); }
/** * Get 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); }
public function getOptionsPrice($product, $price) { if (ITwebexperts_Payperrentals_Helper_Data::isReservationAndRental($product)) { $optprice = 0; if ($optionIds = $product->getCustomOption('option_ids')) { $basePrice = $price; foreach (explode(',', $optionIds->getValue()) as $optionId) { if ($option = $product->getOptionById($optionId)) { $quoteItemOption = $product->getCustomOption('option_' . $option->getId()); $group = $option->groupFactory($option->getType())->setOption($option)->setQuoteItemOption($quoteItemOption); $optprice += $group->getOptionPrice($quoteItemOption->getValue(), $basePrice); } } } return $optprice; } else { return parent::getOptionsPrice($product, $price); } }
/** * @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')); }
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); }