/** * 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 getFinalPrice($qty = null, $product) { if (ITwebexperts_Payperrentals_Helper_Data::isReservationAndRental($product)) { $resPrice = $this->getPrice($product, $qty); $optPrice = $this->getOptionsPrice($product, 0); if ($product->getPayperrentalsHasMultiply() && !is_null($qty)) { $resPrice += $optPrice * $qty; } else { $resPrice += $optPrice; } return $resPrice; } else { return parent::getFinalPrice($qty, $product); } }
/** * @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 getFinalPrice($qty, $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()) + Mage::getModel('sarp/product_price')->getShippingCost($product); } else { return $this->calculateFinalPrice($product, $qty, $baseProduct->getAwSarpSubscriptionPrice()) + Mage::getModel('sarp/product_price')->getShippingCost($product); } } } } } catch (Exception $e) { echo $e->getMessage(); die; } return parent::getFinalPrice($qty, $product); }