public function __construct(array $args) { $this->_product = $args['product']; $this->_store = $args['store']; $this->_coreHelper = $args['core']; $this->_weeeHelper = $args['weee']; $this->_taxHelper = $args['tax']; $this->_product = Mage::getModel("catalog/product")->getCollection()->addAttributeToSelect(Mage::getSingleton("catalog/config")->getProductAttributes())->addAttributeToFilter("entity_id", $this->_product->getEntityId())->setPage(1, 1)->addMinimalPrice()->addFinalPrice()->addTaxPercents()->load()->getFirstItem(); $this->_simplePricesTax = $this->_taxHelper->displayPriceIncludingTax() || $this->_taxHelper->displayBothPrices(); $this->_minimalPriceValue = $this->_product->getMinimalPrice(); $this->_minimalPrice = $this->_taxHelper->getPrice($this->_product, $this->_minimalPriceValue, $this->_simplePricesTax); $this->_setPrices(); }
public function getPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true) { $price = parent::getPrice($product, $price, $includingTax, $shippingAddress, $billingAddress, $ctc, $store, $priceIncludesTax, $roundPrice); if (Mage::app()->getFrontController()->getRequest()->getModuleName() == 'catalog' && Mage::getStoreConfig('dc_charge_extension/dccharge/consolidated-price')) { $product->load($product->getId()); $dcHelper = Mage::helper('dccharge'); $params = array('classify_by' => 'cat desc', 'cat[0]' => $product->getDcProductId(), 'desc[0]' => $product->getName(), 'value[0]' => $price, 'qty[0]' => 1, 'from' => Mage::getStoreConfig('shipping/origin/country_id') ? Mage::getStoreConfig('shipping/origin/country_id') : Mage::getStoreConfig('general/country/default'), 'to' => Mage::getStoreConfig('dc_charge_extension/dccharge/consolidated-price-country'), 'currency' => Mage::app()->getStore()->getBaseCurrency()->getCode(), 'output_currency' => Mage::app()->getStore()->getBaseCurrency()->getCode(), 'insurance' => 0, 'shipping' => 0, 'is_consolidated_request' => 1); if ($product->getCountryOfManufacture()) { $params['origin[0]'] = $product->getCountryOfManufacture(); } $params['use_defaults'] = 1; if ($product->getWeight()) { $weigthUnit = Mage::getStoreConfig('dc_charge_extension/dccharge/weight-unit'); $weight = Mage::getStoreConfig('dc_charge_extension/dccharge/allow-override-products-weight') ? Mage::getStoreConfig('dc_charge_extension/dccharge/overridden-products-weight') : $product->getWeight(); if ($weigthUnit == 'lb') { $itemWeightInKG = round($weight * 0.45359237, 2); } else { $itemWeightInKG = $weight; } $params['wt[0]'] = (double) $itemWeightInKG; } $rawXml = $dcHelper->sendRequest('calculation', $params); if (stripos($rawXml, '<?xml') === false) { return $price; } $answer = new SimpleXMLElement($rawXml); $totals = current($answer->xpath('total-charges')); $totalCharges = (double) $totals->total->amount; $price += $totalCharges; } return $price; }
/** * Always apply tax on custom price (not original) * * @param null|bool|int|Mage_Core_Model_Store $store * @return bool */ public function applyTaxOnOriginalPrice($store = null) { if (Mage::helper('avatax')->isServiceEnabled($store)) { return false; } return parent::applyTaxOnOriginalPrice($store); }
/** * Get product price with all tax settings processing CM wrapper * * @param Mage_Catalog_Model_Product $product * @param float $price inputed product price * @param bool $includingTax return price include tax flag * @param null|Mage_Customer_Model_Address $shippingAddress * @param null|Mage_Customer_Model_Address $billingAddress * @param null|int $ctc customer tax class * @param mixed $store * @param bool $priceIncludesTax flag what price parameter contain tax * @return float */ public function getPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null) { if (!$price) { return $price; } $store = Mage::app()->getStore($store); if (!$this->needPriceConversion($store)) { return $price; } return parent::getPrice($product, $price, $includingTax, $shippingAddress, $billingAddress, $ctc, $store, $priceIncludesTax); }
/** * Process model configuration array. * This method can be used for changing totals collect sort order * * @param array $config * @param store $store * @return array */ public function processConfigArray($config, $store) { $calculationSequence = $this->_helper->getCalculationSequence($store); switch ($calculationSequence) { case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL: $config['before'][] = 'discount'; break; default: $config['after'][] = 'discount'; break; } return $config; }
/** * Check Product Tax Class and if it is empty - use defaults * * @return int|array|null */ public function getProductTaxClassWithDefault() { $productClasses = $this->getAllOptionsForClass(Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT); if (empty($productClasses)) { return null; } $configValue = $this->_helper->getDefaultProductTaxClass(); if (!empty($configValue)) { return $configValue; } $firstClass = array_shift($productClasses); return isset($firstClass['value']) ? $firstClass['value'] : null; }
public function priceIncludesTax($store = null) { $bid_id = Mage::getSingleton('core/session')->getData('bid_id'); if (!$bid_id) { return parent::priceIncludesTax($store); } else { if ((int) Mage::getStoreConfig('auction/tax/is_included_tax') == 1) { return true; } else { return false; } } }
/** * Get product price with all tax settings processing * * @param Mage_Catalog_Model_Product $product * @param float $price inputed product price * @param bool $includingTax return price include tax flag * @param null|Mage_Customer_Model_Address $shippingAddress * @param null|Mage_Customer_Model_Address $billingAddress * @param null|int $ctc customer tax class * @param null|Mage_Core_Model_Store $store * @param bool $priceIncludesTax flag what price parameter contain tax * @return float */ public function getPrice($product, $price, $includingTax = null, $shippingAddress = null, $billingAddress = null, $ctc = null, $store = null, $priceIncludesTax = null, $roundPrice = true) { if (!$price) { return $price; } $store = Mage::app()->getStore($store); if (!$this->needPriceConversion($store)) { return $price; } Mage::app()->getStore($store)->setDoNotRoundET(true); $result = parent::getPrice($product, $price, $includingTax, $shippingAddress, $billingAddress, $ctc, $store, $priceIncludesTax, $roundPrice); Mage::app()->getStore($store)->setDoNotRoundET(false); return $result; }
/** * Get Weee amounts associated with a product * * @param Mage_Catalog_Model_Product $product * @param Mage_Customer_Model_Address_Abstract $shipping * @param Mage_Customer_Model_Address_Abstract $billing * @param mixed $website * @param boolean $calculateTax * @param boolean $ignoreDiscount * @return array|\Varien_Object */ public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTax = null, $ignoreDiscount = false) { $result = array(); $allWeee = $this->getWeeeTaxAttributeCodes(); if (!$allWeee) { return $result; } $websiteId = Mage::app()->getWebsite($website)->getId(); $store = Mage::app()->getWebsite($website)->getDefaultGroup()->getDefaultStore(); $customer = null; if ($shipping) { $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId(); $customer = $shipping->getQuote()->getCustomer(); } else { $customerTaxClass = null; } $calculator = Mage::getModel('tax/calculation'); if ($customer) { $calculator->setCustomer($customer); } $rateRequest = $calculator->getRateRequest($shipping, $billing, $customerTaxClass, $store); $currentPercent = $product->getTaxPercent(); if (!$currentPercent) { $currentPercent = Mage::getSingleton('tax/calculation')->getRate($rateRequest->setProductClassId($product->getTaxClassId())); } $discountPercent = 0; if (!$ignoreDiscount && Mage::helper('weee')->isDiscounted($store)) { $discountPercent = $this->_getDiscountPercentForProduct($product); } $productAttributes = $product->getTypeInstance(true)->getSetAttributes($product); foreach ($productAttributes as $code => $attribute) { if (in_array($code, $allWeee)) { $attributeSelect = $this->getResource()->getReadConnection()->select(); $attributeSelect->from($this->getResource()->getTable('weee/tax'), 'value')->where('attribute_id = ?', (int) $attribute->getId())->where('website_id IN(?)', array($websiteId, 0))->where('country = ?', $rateRequest->getCountryId())->where('state IN(?)', array($rateRequest->getRegionId(), '*'))->where('entity_id = ?', (int) $product->getId())->limit(1); $order = array('state ' . Varien_Db_Select::SQL_DESC, 'website_id ' . Varien_Db_Select::SQL_DESC); $attributeSelect->order($order); $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect); if ($value) { if ($discountPercent) { $value = Mage::app()->getStore()->roundPrice($value - $value * $discountPercent / 100); } $taxAmount = 0; $amount = $value; if ($calculateTax && Mage::helper('weee')->isTaxable($store)) { if ($this->_taxHelper->isCrossBorderTradeEnabled($store)) { $defaultPercent = $currentPercent; } else { $defaultRateRequest = $calculator->getDefaultRateRequest($store); $defaultPercent = Mage::getModel('tax/calculation')->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId())); } if (Mage::helper('weee')->isTaxIncluded($store)) { $taxAmount = Mage::app()->getStore()->roundPrice($value / (100 + $defaultPercent) * $currentPercent); $amount = $amount - $taxAmount; } else { $appliedRates = Mage::getModel('tax/calculation')->getAppliedRates($rateRequest); if (count($appliedRates) > 1) { $taxAmount = 0; foreach ($appliedRates as $appliedRate) { $taxRate = $appliedRate['percent']; $taxAmount += Mage::app()->getStore()->roundPrice($value * $taxRate / 100); } } else { $taxAmount = Mage::app()->getStore()->roundPrice($value * $currentPercent / 100); } } } $one = new Varien_Object(); $one->setName(Mage::helper('catalog')->__($attribute->getFrontend()->getLabel()))->setAmount($amount)->setTaxAmount($taxAmount)->setCode($attribute->getAttributeCode()); $result[] = $one; } } } return $result; }
/** * Recollect item price and row total using after taxes subtract. * Declare item price including tax attributes * * @deprecated after 1.4.1 * * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote_Item_Abstract $item * * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _recollectItem($address, Mage_Sales_Model_Quote_Item_Abstract $item) { $store = $address->getQuote()->getStore(); $request = $this->_getStoreTaxRequest($address); $request->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($request); $qty = $item->getTotalQty(); $price = $taxPrice = $item->getCalculationPriceOriginal(); $basePrice = $baseTaxPrice = $item->getBaseCalculationPriceOriginal(); $subtotal = $taxSubtotal = $item->getRowTotal(); $baseSubtotal = $baseTaxSubtotal = $item->getBaseRowTotal(); if ($this->_config->discountTax($store)) { $item->setDiscountCalculationPrice($price); $item->setBaseDiscountCalculationPrice($basePrice); } /** * Use original price for tax calculation */ if ($item->hasCustomPrice() && !$this->_helper->applyTaxOnCustomPrice($store)) { $taxPrice = $item->getOriginalPrice(); $baseTaxPrice = $item->getBaseOriginalPrice(); $taxSubtotal = $taxPrice * $qty; $baseTaxSubtotal = $baseTaxPrice * $qty; } if ($this->_areTaxRequestsSimilar) { $item->setRowTotalInclTax($subtotal); $item->setBaseRowTotalInclTax($baseSubtotal); $item->setPriceInclTax($price); $item->setBasePriceInclTax($basePrice); $item->setTaxCalcPrice($taxPrice); $item->setBaseTaxCalcPrice($baseTaxPrice); $item->setTaxCalcRowTotal($taxSubtotal); $item->setBaseTaxCalcRowTotal($baseTaxSubtotal); } $this->_subtotalInclTax += $subtotal; $this->_baseSubtotalInclTax += $baseSubtotal; if ($this->_config->getAlgorithm($store) == Mage_Tax_Model_Calculation::CALC_UNIT_BASE) { $taxAmount = $this->_calculator->calcTaxAmount($taxPrice, $rate, true); $baseTaxAmount = $this->_calculator->calcTaxAmount($baseTaxPrice, $rate, true); $unitPrice = $this->_calculator->round($price - $taxAmount); $baseUnitPrice = $this->_calculator->round($basePrice - $baseTaxAmount); $subtotal = $this->_calculator->round($unitPrice * $qty); $baseSubtotal = $this->_calculator->round($baseUnitPrice * $qty); } else { $taxAmount = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, true, false); $baseTaxAmount = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, true, false); $unitPrice = ($subtotal - $taxAmount) / $qty; $baseUnitPrice = ($baseSubtotal - $baseTaxAmount) / $qty; $subtotal = $this->_calculator->round($subtotal - $taxAmount); $baseSubtotal = $this->_calculator->round($baseSubtotal - $baseTaxAmount); } if ($item->hasCustomPrice()) { $item->setCustomPrice($unitPrice); $item->setBaseCustomPrice($baseUnitPrice); } $item->setPrice($baseUnitPrice); $item->setOriginalPrice($unitPrice); $item->setBasePrice($baseUnitPrice); $item->setRowTotal($subtotal); $item->setBaseRowTotal($baseSubtotal); return $this; }
/** * Return the default rate request. It can be either based on store address or customer address * * @param type $store * @return \Varien_Object */ public function getDefaultRateRequest($store = null) { if ($this->_taxHelper->isCrossBorderTradeEnabled($store)) { //If cross border trade is enabled, we will use customer tax rate as store tax rate return $this->getRateRequest(null, null, null, $store); } else { return $this->getRateOriginRequest($store); } }
/** * Collect totals information about shipping * * @param Mage_Sales_Model_Quote_Address $address * @return Mage_Sales_Model_Quote_Address_Total_Shipping */ public function collect(Mage_Sales_Model_Quote_Address $address) { parent::collect($address); $calc = $this->_calculator; $store = $address->getQuote()->getStore(); $storeTaxRequest = $calc->getRateOriginRequest($store); $addressTaxRequest = $calc->getRateRequest($address, $address->getQuote()->getBillingAddress(), $address->getQuote()->getCustomerTaxClassId(), $store); $shippingTaxClass = $this->_config->getShippingTaxClass($store); $storeTaxRequest->setProductClassId($shippingTaxClass); $addressTaxRequest->setProductClassId($shippingTaxClass); $priceIncludesTax = $this->_config->shippingPriceIncludesTax($store); if ($priceIncludesTax) { if ($this->_helper->isCrossBorderTradeEnabled($store)) { $this->_areTaxRequestsSimilar = true; } else { $this->_areTaxRequestsSimilar = $this->_calculator->compareRequests($storeTaxRequest, $addressTaxRequest); } } $shipping = $taxShipping = $address->getShippingAmount(); $baseShipping = $baseTaxShipping = $address->getBaseShippingAmount(); $rate = $calc->getRate($addressTaxRequest); if ($priceIncludesTax) { if ($this->_areTaxRequestsSimilar) { $tax = $this->_round($calc->calcTaxAmount($shipping, $rate, true, false), $rate, true); $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, true, false), $rate, true, 'base'); $taxShipping = $shipping; $baseTaxShipping = $baseShipping; $shipping = $shipping - $tax; $baseShipping = $baseShipping - $baseTax; $taxable = $taxShipping; $baseTaxable = $baseTaxShipping; $isPriceInclTax = true; $address->setTotalAmount('shipping', $shipping); $address->setBaseTotalAmount('shipping', $baseShipping); } else { $storeRate = $calc->getStoreRate($addressTaxRequest, $store); $storeTax = $calc->calcTaxAmount($shipping, $storeRate, true, false); $baseStoreTax = $calc->calcTaxAmount($baseShipping, $storeRate, true, false); $shipping = $calc->round($shipping - $storeTax); $baseShipping = $calc->round($baseShipping - $baseStoreTax); $tax = $this->_round($calc->calcTaxAmount($shipping, $rate, false, false), $rate, true); $baseTax = $this->_round($calc->calcTaxAmount($baseShipping, $rate, false, false), $rate, true, 'base'); $taxShipping = $shipping + $tax; $baseTaxShipping = $baseShipping + $baseTax; $taxable = $taxShipping; $baseTaxable = $baseTaxShipping; $isPriceInclTax = true; $address->setTotalAmount('shipping', $shipping); $address->setBaseTotalAmount('shipping', $baseShipping); } } else { $appliedRates = $calc->getAppliedRates($addressTaxRequest); $taxes = array(); $baseTaxes = array(); foreach ($appliedRates as $appliedRate) { $taxRate = $appliedRate['percent']; $taxId = $appliedRate['id']; $taxes[] = $this->_round($calc->calcTaxAmount($shipping, $taxRate, false, false), $taxId, false); $baseTaxes[] = $this->_round($calc->calcTaxAmount($baseShipping, $taxRate, false, false), $taxId, false, 'base'); } $tax = array_sum($taxes); $baseTax = array_sum($baseTaxes); $taxShipping = $shipping + $tax; $baseTaxShipping = $baseShipping + $baseTax; $taxable = $shipping; $baseTaxable = $baseShipping; $isPriceInclTax = false; $address->setTotalAmount('shipping', $shipping); $address->setBaseTotalAmount('shipping', $baseShipping); } $address->setShippingInclTax($taxShipping); $address->setBaseShippingInclTax($baseTaxShipping); $address->setShippingTaxable($taxable); $address->setBaseShippingTaxable($baseTaxable); $address->setIsShippingInclTax($isPriceInclTax); if ($this->_config->discountTax($store)) { $address->setShippingAmountForDiscount($taxShipping); $address->setBaseShippingAmountForDiscount($baseTaxShipping); } return $this; }
/** * Always apply discount first since AvaTax doesn't support line-level item discount amounts * * @param null|bool|int|Mage_Core_Model_Store $store * @return bool */ public function applyTaxAfterDiscount($store = null) { if (Mage::helper('avatax')->isAvataxEnabled($store)) { return true; } return parent::applyTaxAfterDiscount($store); }
/** * @magentoConfigFixture default_store tax/classes/default_product_tax_class 1 */ public function testGetDefaultProductTaxClass() { $helper = new Mage_Tax_Helper_Data(); $this->assertEquals(1, $helper->getDefaultProductTaxClass()); }