本文整理汇总了PHP中TaxRulesGroup::getTaxesRate方法的典型用法代码示例。如果您正苦于以下问题:PHP TaxRulesGroup::getTaxesRate方法的具体用法?PHP TaxRulesGroup::getTaxesRate怎么用?PHP TaxRulesGroup::getTaxesRate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaxRulesGroup
的用法示例。
在下文中一共展示了TaxRulesGroup::getTaxesRate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: priceCalculation
//.........这里部分代码省略.........
public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $id_county, $id_currency, $id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_groupReduction)
{
// Caching
if ($id_product_attribute === NULL) {
$product_attribute_label = 'NULL';
} else {
$product_attribute_label = $id_product_attribute === false ? 'false' : $id_product_attribute;
}
$cacheId = $id_product . '-' . $id_shop . '-' . $id_currency . '-' . $id_country . '-' . $id_state . '-' . $id_county . '-' . $id_group . '-' . $quantity . '-' . $product_attribute_label . '-' . ($use_tax ? '1' : '0') . '-' . $decimals . '-' . ($only_reduc ? '1' : '0') . '-' . ($use_reduc ? '1' : '0') . '-' . $with_ecotax;
// reference parameter is filled before any returns
$specific_price = SpecificPrice::getSpecificPrice((int) $id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity);
if (isset(self::$_prices[$cacheId])) {
return self::$_prices[$cacheId];
}
// fetch price & attribute price
$cacheId2 = $id_product . '-' . $id_product_attribute;
if (!isset(self::$_pricesLevel2[$cacheId2])) {
self::$_pricesLevel2[$cacheId2] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT p.`price`,
' . ($id_product_attribute ? 'pa.`price`' : 'IFNULL((SELECT pa.price FROM `' . _DB_PREFIX_ . 'product_attribute` pa WHERE id_product = ' . (int) $id_product . ' AND default_on = 1), 0)') . ' AS attribute_price,
p.`ecotax`
' . ($id_product_attribute ? ', pa.`ecotax` AS attribute_ecotax' : '') . '
FROM `' . _DB_PREFIX_ . 'product` p
' . ($id_product_attribute ? 'LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON pa.`id_product_attribute` = ' . (int) $id_product_attribute : '') . '
WHERE p.`id_product` = ' . (int) $id_product);
}
$result = self::$_pricesLevel2[$cacheId2];
$price = (double) (!$specific_price or $specific_price['price'] == 0) ? $result['price'] : $specific_price['price'];
// convert only if the specific price is in the default currency (id_currency = 0)
if (!$specific_price or !($specific_price['price'] > 0 and $specific_price['id_currency'])) {
$price = Tools::convertPrice($price, $id_currency);
}
// Attribute price
$attribute_price = Tools::convertPrice(array_key_exists('attribute_price', $result) ? (double) $result['attribute_price'] : 0, $id_currency);
if ($id_product_attribute !== false) {
// If you want the default combination, please use NULL value instead
$price += $attribute_price;
}
// TaxRate calculation
$tax_rate = Tax::getProductTaxRateViaRules((int) $id_product, (int) $id_country, (int) $id_state, (int) $id_county);
if ($tax_rate === false) {
$tax_rate = 0;
}
// Add Tax
if ($use_tax) {
$price = $price * (1 + $tax_rate / 100);
}
$price = Tools::ps_round($price, $decimals);
// Reduction
$reduc = 0;
if (($only_reduc or $use_reduc) and $specific_price) {
if ($specific_price['reduction_type'] == 'amount') {
$reduction_amount = $specific_price['reduction'];
if (!$specific_price['id_currency']) {
$reduction_amount = Tools::convertPrice($reduction_amount, $id_currency);
}
$reduc = Tools::ps_round(!$use_tax ? $reduction_amount / (1 + $tax_rate / 100) : $reduction_amount, $decimals);
} else {
$reduc = Tools::ps_round($price * $specific_price['reduction'], $decimals);
}
}
if ($only_reduc) {
return $reduc;
}
if ($use_reduc) {
$price -= $reduc;
}
// Group reduction
if ($use_groupReduction) {
if ($reductionFromCategory = (double) GroupReduction::getValueForProduct($id_product, $id_group)) {
$price -= $price * $reductionFromCategory;
} else {
// apply group reduction if there is no group reduction for this category
$price *= (100 - Group::getReductionByIdGroup($id_group)) / 100;
}
}
$price = Tools::ps_round($price, $decimals);
// Eco Tax
if (($result['ecotax'] or isset($result['attribute_ecotax'])) and $with_ecotax) {
$ecotax = $result['ecotax'];
if (isset($result['attribute_ecotax']) && $result['attribute_ecotax'] > 0) {
$ecotax = $result['attribute_ecotax'];
}
if ($id_currency) {
$ecotax = Tools::convertPrice($ecotax, $id_currency);
}
if ($use_tax) {
$taxRate = TaxRulesGroup::getTaxesRate((int) Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID'), (int) $id_country, (int) $id_state, (int) $id_county);
$price += $ecotax * (1 + $taxRate / 100);
} else {
$price += $ecotax;
}
}
$price = Tools::ps_round($price, $decimals);
if ($price < 0) {
$price = 0;
}
self::$_prices[$cacheId] = $price;
return self::$_prices[$cacheId];
}
示例2: productImport
public function productImport()
{
global $cookie;
$this->receiveTab();
$handle = $this->openCsvFile();
$defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
self::setLocale();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
if (Tools::getValue('convert')) {
$line = $this->utf8_encode_array($line);
}
$info = self::getMaskedRow($line);
if (array_key_exists('id', $info) and (int) $info['id'] and Product::existsInDatabase((int) $info['id'], 'product')) {
$product = new Product((int) $info['id']);
$categoryData = Product::getProductCategories((int) $product->id);
foreach ($categoryData as $tmp) {
$product->category[] = $tmp;
}
} else {
$product = new Product();
}
self::setEntityDefaultValues($product);
self::array_walk($info, array('AdminImport', 'fillInfo'), $product);
if ((int) $product->id_tax_rules_group != 0) {
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
$product->tax_rate = TaxRulesGroup::getTaxesRate((int) $product->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0);
} else {
$this->_addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID, you first need a group with this ID.'));
}
}
if (isset($product->manufacturer) and is_numeric($product->manufacturer) and Manufacturer::manufacturerExists((int) $product->manufacturer)) {
$product->id_manufacturer = (int) $product->manufacturer;
} elseif (isset($product->manufacturer) and is_string($product->manufacturer) and !empty($product->manufacturer)) {
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
$product->id_manufacturer = (int) $manufacturer;
} else {
$manufacturer = new Manufacturer();
$manufacturer->name = $product->manufacturer;
if (($fieldError = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $manufacturer->add()) {
$product->id_manufacturer = (int) $manufacturer->id;
} else {
$this->_errors[] = $manufacturer->name . (isset($manufacturer->id) ? ' (' . $manufacturer->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
}
if (isset($product->supplier) and is_numeric($product->supplier) and Supplier::supplierExists((int) $product->supplier)) {
$product->id_supplier = (int) $product->supplier;
} elseif (isset($product->supplier) and is_string($product->supplier) and !empty($product->supplier)) {
if ($supplier = Supplier::getIdByName($product->supplier)) {
$product->id_supplier = (int) $supplier;
} else {
$supplier = new Supplier();
$supplier->name = $product->supplier;
if (($fieldError = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $supplier->add()) {
$product->id_supplier = (int) $supplier->id;
} else {
$this->_errors[] = $supplier->name . (isset($supplier->id) ? ' (' . $supplier->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
}
if (isset($product->price_tex) and !isset($product->price_tin)) {
$product->price = $product->price_tex;
} elseif (isset($product->price_tin) and !isset($product->price_tex)) {
$product->price = $product->price_tin;
// If a tax is already included in price, withdraw it from price
if ($product->tax_rate) {
$product->price = (double) number_format($product->price / (1 + $product->tax_rate / 100), 6, '.', '');
}
} elseif (isset($product->price_tin) and isset($product->price_tex)) {
$product->price = $product->price_tex;
}
if (isset($product->category) and is_array($product->category) and sizeof($product->category)) {
$product->id_category = array();
// Reset default values array
foreach ($product->category as $value) {
if (is_numeric($value)) {
if (Category::categoryExists((int) $value)) {
$product->id_category[] = (int) $value;
} else {
$categoryToCreate = new Category();
$categoryToCreate->id = (int) $value;
$categoryToCreate->name = self::createMultiLangField($value);
$categoryToCreate->active = 1;
$categoryToCreate->id_parent = 1;
// Default parent is home for unknown category to create
if (($fieldError = $categoryToCreate->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $categoryToCreate->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $categoryToCreate->add()) {
$product->id_category[] = (int) $categoryToCreate->id;
} else {
$this->_errors[] = $categoryToCreate->name[$defaultLanguageId] . (isset($categoryToCreate->id) ? ' (' . $categoryToCreate->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
} elseif (is_string($value) and !empty($value)) {
$category = Category::searchByName($defaultLanguageId, $value, true);
if ($category['id_category']) {
$product->id_category[] = (int) $category['id_category'];
} else {
$categoryToCreate = new Category();
//.........这里部分代码省略.........
示例3: getProductTaxRateViaRules
/**
* Return the product tax rate using the tax rules system
*
* @param integer $id_product
* @param integer $id_country
* @return Tax
*
* @deprecated since 1.5
*/
public static function getProductTaxRateViaRules($id_product, $id_country, $id_state, $zipcode)
{
Tools::displayAsDeprecated();
if (!isset(self::$_product_tax_via_rules[$id_product . '-' . $id_country . '-' . $id_state . '-' . $zipcode])) {
$tax_rate = TaxRulesGroup::getTaxesRate((int) Product::getIdTaxRulesGroupByIdProduct((int) $id_product), (int) $id_country, (int) $id_state, $zipcode);
self::$_product_tax_via_rules[$id_product . '-' . $id_country . '-' . $zipcode] = $tax_rate;
}
return self::$_product_tax_via_rules[$id_product . '-' . $id_country . '-' . $zipcode];
}
示例4: _displaySpecificPriceModificationForm
protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups)
{
global $currentIndex;
if (!($obj = $this->loadObject())) {
return;
}
$specificPrices = SpecificPrice::getByProductId((int) $obj->id);
$specificPricePriorities = SpecificPrice::getPriority((int) $obj->id);
$default_country = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT'));
$taxRate = TaxRulesGroup::getTaxesRate($obj->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0);
$tmp = array();
foreach ($shops as $shop) {
$tmp[$shop['id_shop']] = $shop;
}
$shops = $tmp;
$tmp = array();
foreach ($currencies as $currency) {
$tmp[$currency['id_currency']] = $currency;
}
$currencies = $tmp;
$tmp = array();
foreach ($countries as $country) {
$tmp[$country['id_country']] = $country;
}
$countries = $tmp;
$tmp = array();
foreach ($groups as $group) {
$tmp[$group['id_group']] = $group;
}
$groups = $tmp;
echo '
<h4>' . $this->l('Current specific prices') . '</h4>
<table style="text-align: center;width:100%" class="table" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="cell border" style="width: 12%;">' . $this->l('Currency') . '</th>
<th class="cell border" style="width: 11%;">' . $this->l('Country') . '</th>
<th class="cell border" style="width: 13%;">' . $this->l('Group') . '</th>
<th class="cell border" style="width: 12%;">' . $this->l('Price') . ' ' . ($default_country->display_tax_label ? $this->l('(tax excl.)') : '') . '</th>
<th class="cell border" style="width: 10%;">' . $this->l('Reduction') . '</th>
<th class="cell border" style="width: 15%;">' . $this->l('Period') . '</th>
<th class="cell border" style="width: 10%;">' . $this->l('From (quantity)') . '</th>
<th class="cell border" style="width: 15%;">' . $this->l('Final price') . ' ' . ($default_country->display_tax_label ? $this->l('(tax excl.)') : '') . '</th>
<th class="cell border" style="width: 2%;">' . $this->l('Action') . '</th>
</tr>
</thead>
<tbody>';
if (!is_array($specificPrices) or !sizeof($specificPrices)) {
echo '
<tr>
<td colspan="9">' . $this->l('No specific prices') . '</td>
</tr>';
} else {
$i = 0;
foreach ($specificPrices as $specificPrice) {
$current_specific_currency = $currencies[$specificPrice['id_currency'] ? $specificPrice['id_currency'] : $defaultCurrency->id];
if ($specificPrice['reduction_type'] == 'percentage') {
$reduction = $specificPrice['reduction'] * 100 . ' %';
} else {
$reduction = Tools::displayPrice(Tools::ps_round($specificPrice['reduction'], 2), $current_specific_currency);
}
if ($specificPrice['from'] == '0000-00-00 00:00:00' and $specificPrice['to'] == '0000-00-00 00:00:00') {
$period = $this->l('Unlimited');
} else {
$period = $this->l('From') . ' ' . ($specificPrice['from'] != '0000-00-00 00:00:00' ? $specificPrice['from'] : '0000-00-00 00:00:00') . '<br />' . $this->l('To') . ' ' . ($specificPrice['to'] != '0000-00-00 00:00:00' ? $specificPrice['to'] : '0000-00-00 00:00:00');
}
echo '
<tr ' . ($i % 2 ? 'class="alt_row"' : '') . '>
<td class="cell border">' . ($specificPrice['id_currency'] ? $currencies[$specificPrice['id_currency']]['name'] : $this->l('All currencies')) . '</td>
<td class="cell border">' . ($specificPrice['id_country'] ? $countries[$specificPrice['id_country']]['name'] : $this->l('All countries')) . '</td>
<td class="cell border">' . ($specificPrice['id_group'] ? $groups[$specificPrice['id_group']]['name'] : $this->l('All groups')) . '</td>
<td class="cell border">' . Tools::displayPrice((double) $specificPrice['price'], $current_specific_currency) . '</td>
<td class="cell border">' . $reduction . '</td>
<td class="cell border">' . $period . '</td>
<td class="cell border">' . $specificPrice['from_quantity'] . '</th>
<td class="cell border"><b>' . Tools::displayPrice(Tools::ps_round((double) $this->_getFinalPrice($specificPrice, (double) $obj->price, $taxRate), 2), $current_specific_currency) . '</b></td>
<td class="cell border"><a href="' . $currentIndex . (Tools::getValue('id_category') ? '&id_category=' . Tools::getValue('id_category') : '') . '&id_product=' . (int) Tools::getValue('id_product') . '&updateproduct&deleteSpecificPrice&id_specific_price=' . (int) $specificPrice['id_specific_price'] . '&token=' . Tools::getValue('token') . '"><img src="../img/admin/delete.gif" alt="' . $this->l('Delete') . '" /></a></td>
</tr>';
$i++;
}
}
echo '
</tbody>
</table>';
echo '
<script type="text/javascript">
var currencies = new Array();
currencies[0] = new Array();
currencies[0]["sign"] = "' . $defaultCurrency->sign . '";
currencies[0]["format"] = ' . $defaultCurrency->format . ';
';
foreach ($currencies as $currency) {
echo '
currencies[' . $currency['id_currency'] . '] = new Array();
currencies[' . $currency['id_currency'] . ']["sign"] = "' . $currency['sign'] . '";
currencies[' . $currency['id_currency'] . ']["format"] = ' . $currency['format'] . ';
';
}
echo '
//.........这里部分代码省略.........
示例5: handleConfirm
//.........这里部分代码省略.........
$vendor_code = substr($reference, 0, 6);
$sql = "select id_supplier from ps_supplier where code = '{$vendor_code}'";
$row = Db::getInstance()->getRow($sql);
if (!isset($row['id_supplier'])) {
$error = "Vendor Details not found for : " . trim($reference);
} else {
$id_supplier = $row['id_supplier'];
}
//For sudarshan, supplier_code (vendor product code) is mandatory
if (false) {
//(int) $id_supplier === 2 ) {
if (empty($supplier_code)) {
$error = "Reference: {$reference} -- Supplier Code is Mandatory for Vendor {$vendor_code}";
} else {
if (strpos("::", ${$supplier_code}) === false) {
$error = "Reference: {$reference} -- Supplier Code:{$supplier_code} is not in DESIGN_NO::ITEM_CODE format for Vendor {$vendor_code}";
}
}
}
if (!$error) {
if ($update && !empty($id_product)) {
$product = new Product((int) $id_product);
if (!Validate::isLoadedObject($product)) {
$error = "Error loading the product: " . $id_product;
return;
}
} elseif (!$update) {
$product = new Product();
}
$product->id_tax_rules_group = $tax_rule;
$product->reference = $reference;
$product->id_supplier = $id_supplier;
$product->location = $location;
$product->tax_rate = TaxRulesGroup::getTaxesRate((int) $product->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0);
if (isset($manufacturer) and is_numeric($manufacturer) and Manufacturer::manufacturerExists((int) $manufacturer)) {
$product->id_manufacturer = $manufacturer;
}
$product->price = (double) $mrp;
$product->price = (double) number_format($product->price / (1 + $product->tax_rate / 100), 6, '.', '');
$product->id_category = $importCategories;
$product->id_category_default = 1;
$product->name = array();
$product->name[$defaultLanguageId] = $product_name;
$product->description_short = array();
$product->description_short[$defaultLanguageId] = $style_tips;
$product->description = array();
$product->description[$defaultLanguageId] = $description;
$link_rewrite = Tools::link_rewrite($product->name[$defaultLanguageId]);
$product->link_rewrite = array();
$product->link_rewrite[$defaultLanguageId] = $link_rewrite;
$product->quantity = $quantity ? intval($quantity) : 0;
if ($discount && is_numeric($discount)) {
$product->discount = $discount;
}
if (!empty($tags)) {
$product->tags = $tags;
}
$product->weight = is_numeric($weight) ? $weight : 0;
$product->width = is_numeric($width) ? $width : 0;
$product->height = is_numeric($length) ? $length : 0;
$product->supplier_reference = $supplier_code;
$product->wholesale_price = $supplier_price ? (double) $supplier_price : 0;
$product->active = $active == 1 ? 1 : 0;
$product->images = $images;
$product->fabric = $fabric;
$product->color = $color;
示例6: getCarrierTaxRate
public static function getCarrierTaxRate($id_carrier, $id_address = null)
{
global $cookie, $defaultCountry;
$id_country = (int) Country::getDefaultCountryId();
if ($id_country == _PS_COUNTRY_DEFAULT_ && isset($cookie->id_country) && $cookie->id_country != (int) _PS_COUNTRY_DEFAULT_) {
$country = new Country((int) $cookie->id_country, $cookie->id_lang);
if (ValidaTe::isLoadedObject($country) && $country->active) {
$id_country = (int) $country->id;
$defaultCountry = $country;
}
}
$id_state = 0;
$id_county = 0;
if (!empty($id_address)) {
$address_infos = Address::getCountryAndState($id_address);
if ($address_infos['id_country']) {
$id_country = (int) $address_infos['id_country'];
$id_state = (int) $address_infos['id_state'];
$id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
}
if (!empty($address_infos['vat_number']) && $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') && Configuration::get('VATNUMBER_MANAGEMENT')) {
return 0;
}
}
return TaxRulesGroup::getTaxesRate((int) Carrier::getIdTaxRulesGroupByIdCarrier((int) $id_carrier), (int) $id_country, (int) $id_state, (int) $id_county);
}
示例7: getCarrierTaxRate
public static function getCarrierTaxRate($id_carrier, $id_address = NULL)
{
$id_country = (int) Country::getDefaultCountryId();
$id_state = 0;
$id_county = 0;
if (!empty($id_address)) {
$address_infos = Address::getCountryAndState($id_address);
if ($address_infos['id_country']) {
$id_country = (int) $address_infos['id_country'];
$id_state = (int) $address_infos['id_state'];
$id_county = (int) County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
}
if (!empty($address_infos['vat_number']) and $address_infos['id_country'] != Configuration::get('VATNUMBER_COUNTRY') and Configuration::get('VATNUMBER_MANAGEMENT')) {
return 0;
}
}
return TaxRulesGroup::getTaxesRate((int) Carrier::getIdTaxRulesGroupByIdCarrier((int) $id_carrier), (int) $id_country, (int) $id_state, (int) $id_county);
}