本文整理汇总了PHP中Tax::getTaxIdByRate方法的典型用法代码示例。如果您正苦于以下问题:PHP Tax::getTaxIdByRate方法的具体用法?PHP Tax::getTaxIdByRate怎么用?PHP Tax::getTaxIdByRate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tax
的用法示例。
在下文中一共展示了Tax::getTaxIdByRate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createDejalaCarrier
/**
* creates of a dejala carrier corresponding to $dejalaProduct
*/
public static function createDejalaCarrier($dejalaConfig, $dejalaProduct)
{
// MFR091130 - get id zone from the country used in the module (if the store zones were customized) - default is 1 (Europe)
$id_zone = 1;
$moduleCountryIsoCode = strtoupper($dejalaConfig->country);
$countryID = Country::getByIso($moduleCountryIsoCode);
if (intval($countryID)) {
$id_zone = Country::getIdZone($countryID);
}
$vatRate = floatval($dejalaProduct['vat']);
// MFR091130 - get or create the tax & attach it to our zone if needed
$id_tax = Tax::getTaxIdByRate($vatRate);
if (!$id_tax) {
$tax = new Tax();
$tax->rate = $vatRate;
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
$tax->name[$defaultLanguage] = $tax->rate . '%';
$tax->add();
$id_tax = Tax::getTaxIdByRate($vatRate);
}
if (!Tax::zoneHasTax($id_tax, $id_zone)) {
// MFR : direct call because $tax->addZone($id_zone) causes errors when called
Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'tax_zone` (`id_tax` , `id_zone`) VALUES (' . intval($id_tax) . ', ' . intval($id_zone) . ')');
}
$carrier = new Carrier();
$carrier->name = 'dejala';
$carrier->id_tax = $id_tax;
$carrier->url = 'http://tracking.dejala.' . $dejalaConfig->country . '/tracker/@';
$carrier->active = true;
$carrier->deleted = 0;
$carrier->shipping_handling = false;
$carrier->range_behavior = 0;
$carrier->is_module = 1;
$languages = Language::getLanguages(true);
foreach ($languages as $language) {
if ($language['iso_code'] == 'fr') {
$carrier->delay[$language['id_lang']] = utf8_encode('Quand vous voulez... Par coursier, ' . $dejalaProduct['timelimit'] . 'H');
}
if ($language['iso_code'] == 'en') {
$carrier->delay[$language['id_lang']] = utf8_encode('When you want... Dispatch rider, ' . $dejalaProduct['timelimit'] . 'H range');
}
if ($language['iso_code'] == 'es') {
$carrier->delay[$language['id_lang']] = utf8_encode('Cuando quiera... Por mensajero, ' . $dejalaProduct['timelimit'] . 'H');
}
}
$carrier->add();
$sql = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` (`id_carrier` , `id_zone`) VALUES (' . intval($carrier->id) . ', ' . intval($id_zone) . ')';
Db::getInstance()->Execute($sql);
$rangeW = new RangeWeight();
$rangeW->id_carrier = $carrier->id;
$rangeW->delimiter1 = 0;
$rangeW->delimiter2 = $dejalaProduct['max_weight'];
$rangeW->add();
$vat_factor = 1 + $dejalaProduct['vat'] / 100;
$priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2);
$priceHT = round($priceTTC / $vat_factor, 2);
$priceList = '(NULL' . ',' . $rangeW->id . ',' . $carrier->id . ',' . $id_zone . ',' . $priceHT . ')';
$carrier->addDeliveryPrice($priceList);
return new Carrier($carrier->id);
}
示例2: productImport
public function productImport()
{
global $cookie;
$this->receiveTab();
$handle = $this->openCsvFile();
$defaultLanguageId = intval(Configuration::get('PS_LANG_DEFAULT'));
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
if (Tools::getValue('convert')) {
$this->utf8_encode_array($line);
}
$info = self::getMaskedRow($line);
if (array_key_exists('id', $info) and intval($info['id']) and Product::existsInDatabase(intval($info['id']))) {
$product = new Product(intval($info['id']));
if ($product->reduction_from == '0000-00-00') {
$product->reduction_from = date('Y-m-d');
}
if ($product->reduction_to == '0000-00-00') {
$product->reduction_to = date('Y-m-d');
}
$categoryData = Product::getIndexedCategories(intval($product->id));
foreach ($categoryData as $tmp) {
$product->category[] = $tmp['id_category'];
}
} else {
$product = new Product();
}
self::setEntityDefaultValues($product);
self::array_walk($info, array('AdminImport', 'fillInfo'), $product);
// Find id_tax corresponding to given values for product taxe
if (isset($product->tax_rate)) {
$product->id_tax = intval(Tax::getTaxIdByRate(floatval($product->tax_rate)));
}
if (isset($product->tax_rate) and !$product->id_tax) {
$tax = new Tax();
$tax->rate = floatval($product->tax_rate);
$tax->name = self::createMultiLangField(strval($product->tax_rate));
if (($fieldError = $tax->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $tax->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $tax->add()) {
$product->id_tax = intval($tax->id);
} else {
$this->_errors[] = 'TAX ' . $tax->name[$defaultLanguageId] . ' ' . Tools::displayError('cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
if (isset($product->manufacturer) and is_numeric($product->manufacturer) and Manufacturer::manufacturerExists(intval($product->manufacturer))) {
$product->id_manufacturer = intval($product->manufacturer);
} elseif (isset($product->manufacturer) and is_string($product->manufacturer) and !empty($product->manufacturer)) {
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
$product->id_manufacturer = intval($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 = intval($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(intval($product->supplier))) {
$product->id_supplier = intval($product->supplier);
} elseif (isset($product->supplier) and is_string($product->supplier) and !empty($product->supplier)) {
if ($supplier = Supplier::getIdByName($product->supplier)) {
$product->id_supplier = intval($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 = intval($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 = floatval(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(intval($value))) {
$product->id_category[] = intval($value);
} else {
$categoryToCreate = new Category();
$categoryToCreate->id = intval($value);
$categoryToCreate->name = self::createMultiLangField($value);
$categoryToCreate->active = 1;
$categoryToCreate->id_parent = 1;
// Default parent is home for unknown category to create
//.........这里部分代码省略.........
示例3: getDataByProductId
public static function getDataByProductId($id_product)
{
Tools::displayAsDeprecated();
$tax_rate = Tax::getProductTaxRate((int) $id_product);
$id_tax = Tax::getTaxIdByRate($tax_rate);
return array('id_tax' => $id_tax, 'rate' => $tax_rate);
}