本文整理汇总了PHP中Mage_Catalog_Model_Product::getTaxClassId方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Catalog_Model_Product::getTaxClassId方法的具体用法?PHP Mage_Catalog_Model_Product::getTaxClassId怎么用?PHP Mage_Catalog_Model_Product::getTaxClassId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Catalog_Model_Product
的用法示例。
在下文中一共展示了Mage_Catalog_Model_Product::getTaxClassId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertAttribute
/**
* Set current attribute to entry (for specified product)
*
* @param Mage_Catalog_Model_Product $product
* @param Varien_Gdata_Gshopping_Entry $entry
* @return Varien_Gdata_Gshopping_Entry
*/
public function convertAttribute($product, $entry)
{
$entry->cleanTaxes();
if (Mage::helper('tax')->getConfig()->priceIncludesTax()) {
return $entry;
}
$calc = Mage::helper('tax')->getCalculator();
$customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId());
$rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId());
$targetCountry = Mage::getSingleton('googleshopping/config')->getTargetCountry($product->getStoreId());
$ratesTotal = 0;
foreach ($rates as $rate) {
if ($targetCountry == $rate['country']) {
$regions = $this->_parseRegions($rate['state'], $rate['postcode']);
$ratesTotal += count($regions);
if ($ratesTotal > self::RATES_MAX) {
Mage::throwException(Mage::helper('googleshopping')->__("Google shopping only supports %d tax rates per product", self::RATES_MAX));
}
foreach ($regions as $region) {
$entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => $region));
}
}
}
return $entry;
}
示例2: getProductTaxRate
private function getProductTaxRate()
{
/** @var $taxCalculator Mage_Tax_Model_Calculation */
$taxCalculator = Mage::getSingleton('tax/calculation');
$request = $taxCalculator->getRateRequest($this->quoteBuilder->getQuote()->getShippingAddress(), $this->quoteBuilder->getQuote()->getBillingAddress(), $this->quoteBuilder->getQuote()->getCustomerTaxClassId(), $this->quoteBuilder->getQuote()->getStore());
$request->setProductClassId($this->product->getTaxClassId());
return $taxCalculator->getRate($request);
}
示例3: importCatalogProduct
/**
* Import item data from product model object
*
* @param Mage_Catalog_Model_Product $product
* @return Mage_Sales_Model_Quote_Item
*/
public function importCatalogProduct(Mage_Catalog_Model_Product $product)
{
$this->setProductId($product->getId())->setSku($product->getSku())->setName($product->getName())->setWeight($product->getWeight())->setTaxClassId($product->getTaxClassId())->setCost($product->getCost())->setIsQtyDecimal($product->getIsQtyDecimal());
if ($product->getSuperProduct()) {
$this->setSuperProductId($product->getSuperProduct()->getId());
if ($product->getSuperProduct()->isConfigurable()) {
$this->setName($product->getSuperProduct()->getName());
}
}
$this->setProduct($product);
return $this;
}
示例4: getCustomerTaxPercent
/**
* Retrieve current tax percent for customer based on subscription and product
*
* @param Adyen_Subscription_Model_Subscription $subscription
* @param Mage_Catalog_Model_Product $product
* @return int
*/
public function getCustomerTaxPercent(Adyen_Subscription_Model_Subscription $subscription, Mage_Catalog_Model_Product $product)
{
$percent = $product->getTaxPercent();
$includingPercent = null;
$taxClassId = $product->getTaxClassId();
if (is_null($percent)) {
if ($taxClassId) {
$request = Mage::getSingleton('tax/calculation')->getRateRequest($subscription->getShippingAddress(), $subscription->getBillingAddress(), $subscription->getCustomer()->getTaxClassId(), $product->getStore());
$percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
}
return $percent ?: 0;
}
示例5: convertAttribute
/**
* Set current attribute to entry (for specified product)
*
* @param Mage_Catalog_Model_Product $product
* @param Varien_Gdata_Gshopping_Entry $entry
* @return Varien_Gdata_Gshopping_Entry
*/
public function convertAttribute($product, $entry)
{
$entry->cleanTaxes();
if (Mage::helper('Mage_Tax_Helper_Data')->getConfig()->priceIncludesTax()) {
return $entry;
}
$calc = Mage::helper('Mage_Tax_Helper_Data')->getCalculator();
$customerTaxClass = $calc->getDefaultCustomerTaxClass($product->getStoreId());
$rates = $calc->getRatesByCustomerAndProductTaxClasses($customerTaxClass, $product->getTaxClassId());
$targetCountry = Mage::getSingleton('Mage_GoogleShopping_Model_Config')->getTargetCountry($product->getStoreId());
foreach ($rates as $rate) {
if ($targetCountry == $rate['country']) {
$entry->addTax(array('tax_rate' => $rate['value'] * 100, 'tax_country' => empty($rate['country']) ? '*' : $rate['country'], 'tax_region' => empty($rate['state']) ? '*' : $rate['state']));
}
}
return $entry;
}
示例6: getProductTax
/**
* Get the tax info, if this product has a tax class
* This will load a default tax rate (default address, default customer type)
*
* @param Mage_Catalog_Model_Product $product
* @return boolean|array
*/
public function getProductTax(Mage_Catalog_Model_Product $product)
{
$taxId = $product->getTaxClassId();
if (null === $taxId) {
return false;
}
$store = $this->_getStore();
$taxCalculation = Mage::getModel('tax/calculation');
$taxRequest = $taxCalculation->getRateRequest(null, null, null, $store);
//for default address and customer class
$taxRate = $taxCalculation->getRate($taxRequest->setProductClassId($taxId));
//get calculated default rate
//get detailed tax info
$taxRateInfo = $taxCalculation->getResource()->getRateInfo($taxRequest);
$taxLabel = isset($taxRateInfo['process'][0]['id']) ? $taxRateInfo['process'][0]['id'] : '';
$isTaxIncluded = Mage::helper('tax')->priceIncludesTax($store);
$taxInfo = array('rate' => $taxRate, 'label' => $taxLabel, 'taxIncluded' => $isTaxIncluded, 'showLabel' => true);
return $taxInfo;
}
示例7: setTaxClass
/**
* set tax class
*/
public function setTaxClass()
{
if ($this->item->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $this->item->getPriceType() == Mage_Bundle_Model_Product_Price::PRICE_TYPE_DYNAMIC) {
$childIds = $this->item->getTypeInstance()->getChildrenIds($this->item->getId());
$taxRates = array();
foreach ($childIds as $childOption) {
foreach ($childOption as $childId) {
$product = Mage::getModel('catalog/product')->setStoreId($this->_getConfig()->getStoreViewId())->load($childId);
$taxClassId = $product->getTaxClassId();
$taxRates[$taxClassId] = $this->_getTaxRate($product);
}
}
parent::setTaxClass(array_search(max($taxRates), $taxRates));
} else {
if (!($this->item->getTaxClassId() == Shopgate_Framework_Model_Export_Product_Xml::DEFAULT_TAX_CLASS_ID_NONE && $this->_parent)) {
$taxClassId = $this->item->getTaxClassId();
if (!empty($taxClassId)) {
parent::setTaxClass($taxClassId);
}
}
}
}
示例8: getPrice
/**
* 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 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 $store->roundPrice($price);
}
if (is_null($priceIncludesTax)) {
$priceIncludesTax = $this->priceIncludesTax($store);
}
$percent = $product->getTaxPercent();
$includingPercent = null;
$taxClassId = $product->getTaxClassId();
if (is_null($percent)) {
if ($taxClassId) {
$request = Mage::getSingleton('tax/calculation')->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
$percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
}
if ($taxClassId && $priceIncludesTax) {
$request = Mage::getSingleton('tax/calculation')->getRateRequest(false, false, false, $store);
$includingPercent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
if ($percent === false || is_null($percent)) {
if ($priceIncludesTax && !$includingPercent) {
return $price;
}
}
$product->setTaxPercent($percent);
if (!is_null($includingTax)) {
if ($priceIncludesTax) {
if ($includingTax) {
/**
* Recalculate price include tax in case of different rates
*/
if ($includingPercent != $percent) {
$price = $this->_calculatePrice($price, $includingPercent, false);
/**
* Using regular rounding. Ex:
* price incl tax = 52.76
* store tax rate = 19.6%
* customer tax rate= 19%
*
* price excl tax = 52.76 / 1.196 = 44.11371237 ~ 44.11
* tax = 44.11371237 * 0.19 = 8.381605351 ~ 8.38
* price incl tax = 52.49531773 ~ 52.50 != 52.49
*
* that why we need round prices excluding tax before applying tax
* this calculation is used for showing prices on catalog pages
*/
if ($percent != 0) {
$price = $this->getCalculator()->round($price);
$price = $this->_calculatePrice($price, $percent, true);
}
}
} else {
$price = $this->_calculatePrice($price, $includingPercent, false);
}
} else {
if ($includingTax) {
$price = $this->_calculatePrice($price, $percent, true);
}
}
} else {
if ($priceIncludesTax) {
switch ($this->getPriceDisplayType($store)) {
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
$price = $this->_calculatePrice($price, $includingPercent, false);
break;
case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
$price = $this->_calculatePrice($price, $includingPercent, false);
$price = $this->_calculatePrice($price, $percent, true);
break;
}
} else {
switch ($this->getPriceDisplayType($store)) {
case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
$price = $this->_calculatePrice($price, $percent, true);
break;
case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
break;
}
}
//.........这里部分代码省略.........
示例9: _loadTaxCalculationRate
/**
* Gets tax percents for current product
*
* @param Mage_Catalog_Model_Product $product
* @return string
*/
protected function _loadTaxCalculationRate(Mage_Catalog_Model_Product $product)
{
$taxPercent = $product->getTaxPercent();
if (is_null($taxPercent)) {
$taxClassId = $product->getTaxClassId();
if ($taxClassId) {
$request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, null);
$taxPercent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
}
if ($taxPercent) {
return $taxPercent;
}
return 0;
}
示例10: getPrice
/**
* 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 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)
{
$store = AO::app()->getStore($store);
if (!$this->needPriceConversion($store)) {
return $store->roundPrice($price);
}
if (is_null($priceIncludesTax)) {
$priceIncludesTax = $this->priceIncludesTax($store);
}
$percent = $product->getTaxPercent();
$includingPercent = null;
$taxClassId = $product->getTaxClassId();
if (is_null($percent)) {
if ($taxClassId) {
$request = AO::getSingleton('tax/calculation')->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
$percent = AO::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
}
if ($taxClassId && $priceIncludesTax) {
$request = AO::getSingleton('tax/calculation')->getRateRequest(false, false, false, $store);
$includingPercent = AO::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
if ($percent === false || is_null($percent)) {
if ($priceIncludesTax && !$includingPercent) {
return $price;
}
}
$product->setTaxPercent($percent);
if (!is_null($includingTax)) {
if ($priceIncludesTax) {
if ($includingTax) {
$price = $this->_calculatePrice($price, $includingPercent, false);
$price = $this->_calculatePrice($price, $percent, true);
} else {
$price = $this->_calculatePrice($price, $includingPercent, false);
}
} else {
if ($includingTax) {
$price = $this->_calculatePrice($price, $percent, true);
}
}
} else {
if ($priceIncludesTax) {
switch ($this->getPriceDisplayType($store)) {
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
$price = $this->_calculatePrice($price, $includingPercent, false);
break;
case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
$price = $this->_calculatePrice($price, $includingPercent, false);
$price = $this->_calculatePrice($price, $percent, true);
break;
}
} else {
switch ($this->getPriceDisplayType($store)) {
case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
$price = $this->_calculatePrice($price, $percent, true);
break;
case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
break;
}
}
}
return $store->roundPrice($price);
}
示例11: _initProductTaxClassId
protected function _initProductTaxClassId(Mage_Catalog_Model_Product $product)
{
if (!is_null($this->_productTaxClassId)) {
$product->setTaxClassId($this->_productTaxClassId);
return;
}
if ($this->_taxPercent > 0) {
// Getting tax percent for magento product
// -------------------------
$requestTax = new Varien_Object();
$requestTax->setCountryId($this->_quote->getShippingAddress()->getCountryId())->setRegionId($this->_quote->getShippingAddress()->getRegionId())->setPostcode($this->_quote->getShippingAddress()->getPostcode())->setStore($this->_quote->getStore())->setCustomerClassId($this->_quote->getCustomerTaxClassId())->setProductClassId($product->getTaxClassId());
$productTaxPercent = Mage::getSingleton('tax/calculation')->getRate($requestTax);
// -------------------------
// If magento product tax class has other tax percent
// set temp tax class with ebay order tax percent
// -------------------------
if ($this->_taxPercent != (double) $productTaxPercent) {
$product->setTaxClassId($this->_getProductTaxClassId());
} else {
$this->_productTaxClassId = $product->getTaxClassId();
}
// -------------------------
} else {
// If order has no tax - disable magento product tax class
// -------------------------
$product->setTaxClassId(0);
// -------------------------
}
}
示例12: getProductTaxCode
/**
* @param int $taxCodeId
*
* @return string|null
*/
public function getProductTaxCode(Mage_Catalog_Model_Product $product)
{
return $this->getTaxCode($product->getTaxClassId());
}
示例13: _setTaxClass
/**
* export tax class - for USA export only
*
* @param Mage_Catalog_Model_Product $product
*/
protected function _setTaxClass($product)
{
/* @var $taxClass Mage_Tax_Model_Class */
$taxClass = Mage::getModel("tax/class")->load($product->getTaxClassId());
if (!$taxClass->isEmpty()) {
$this->_defaultRow['tax_class'] = "{$taxClass->getId()}=>{$taxClass->getClassName()}";
}
}
示例14: getTaxRequest
protected function getTaxRequest(Mage_Catalog_Model_Product $product)
{
$request = $this->getTaxCalculator()->getRateRequest($this->_magentoQuote->getShippingAddress(), $this->_magentoQuote->getBillingAddress(), $this->_magentoQuote->getCustomerTaxClassId(), $this->_magentoQuote->getStore());
$request->setProductClassId($product->getTaxClassId());
return $request;
}
示例15: getPrice
/**
* 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 = $this->_app->getStore($store);
if (!$this->needPriceConversion($store)) {
return $store->roundPrice($price);
}
if (is_null($priceIncludesTax)) {
$priceIncludesTax = $this->priceIncludesTax($store);
}
$percent = $product->getTaxPercent();
$includingPercent = null;
$taxClassId = $product->getTaxClassId();
if (is_null($percent)) {
if ($taxClassId) {
$request = Mage::getSingleton('tax/calculation')->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
$percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
}
if ($taxClassId && $priceIncludesTax) {
if ($this->isCrossBorderTradeEnabled($store)) {
$includingPercent = $percent;
} else {
$request = Mage::getSingleton('tax/calculation')->getRateOriginRequest($store);
$includingPercent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxClassId));
}
}
if ($percent === false || is_null($percent)) {
if ($priceIncludesTax && !$includingPercent) {
return $price;
}
}
$product->setTaxPercent($percent);
if ($product->getAppliedRates() == null) {
$request = Mage::getSingleton('tax/calculation')->getRateRequest($shippingAddress, $billingAddress, $ctc, $store);
$request->setProductClassId($taxClassId);
$appliedRates = Mage::getSingleton('tax/calculation')->getAppliedRates($request);
$product->setAppliedRates($appliedRates);
}
if (!is_null($includingTax)) {
if ($priceIncludesTax) {
if ($includingTax) {
/**
* Recalculate price include tax in case of different rates. Otherwise price remains the same.
*/
if ($includingPercent != $percent) {
// determine the customer's price that includes tax
$price = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store);
}
} else {
$price = $this->_calculatePrice($price, $includingPercent, false);
}
} else {
if ($includingTax) {
$appliedRates = $product->getAppliedRates();
if (count($appliedRates) > 1) {
$price = $this->_calculatePriceInclTaxWithMultipleRates($price, $appliedRates);
} else {
$price = $this->_calculatePrice($price, $percent, true);
}
}
}
} else {
if ($priceIncludesTax) {
switch ($this->getPriceDisplayType($store)) {
case Mage_Tax_Model_Config::DISPLAY_TYPE_EXCLUDING_TAX:
case Mage_Tax_Model_Config::DISPLAY_TYPE_BOTH:
if ($includingPercent != $percent) {
// determine the customer's price that includes tax
$taxablePrice = $this->_calculatePriceInclTax($price, $includingPercent, $percent, $store);
// determine the customer's tax amount,
// round tax unless $roundPrice is set explicitly to false
$tax = $this->getCalculator()->calcTaxAmount($taxablePrice, $percent, true, $roundPrice);
// determine the customer's price without taxes
$price = $taxablePrice - $tax;
} else {
//round tax first unless $roundPrice is set to false explicitly
$price = $this->_calculatePrice($price, $includingPercent, false, $roundPrice);
}
break;
case Mage_Tax_Model_Config::DISPLAY_TYPE_INCLUDING_TAX:
$price = $this->_calculatePrice($price, $includingPercent, false);
$price = $this->_calculatePrice($price, $percent, true);
break;
}
//.........这里部分代码省略.........