在我的代码中,我从当前国家获得了当前的用户国家 /地区,我想获得税率。这样我就可以将该税率相应地应用于当前公司。有人可以帮忙吗?

有帮助吗?

解决方案

以下代码将:

  1. 加载客户地址并获得国家ID,例如“ US”或“ DE”
  2. 加载给定国家的所有税率的集合

请注意,$ customer_id应该是相关的客户ID,您可以使用已登录的当前客户ID。另请注意,GetDefaultBillingAddress并不总是为客户设置。

$oCustomer = Mage::getModel('customer/customer')->load($customer_id);
$oAddress = $oCustomer->getDefaultBillingAddress();

/* @var $oTaxRateCollection Mage_Tax_Model_Resource_Calculation_Rate_Collection */
$oTaxRateCollection = Mage::getResourceModel('tax/calculation_rate_collection');
$oTaxRateCollection->addFieldToFilter('tax_country_id', $oAddress->getCountryId());
许可以下: CC-BY-SA归因
scroll top