本文整理汇总了PHP中Tax::validateFieldsLang方法的典型用法代码示例。如果您正苦于以下问题:PHP Tax::validateFieldsLang方法的具体用法?PHP Tax::validateFieldsLang怎么用?PHP Tax::validateFieldsLang使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tax
的用法示例。
在下文中一共展示了Tax::validateFieldsLang方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _installTaxes
/**
* @param SimpleXMLElement $xml
* @return bool
* @throws PrestaShopException
*/
protected function _installTaxes($xml)
{
if (isset($xml->taxes->tax)) {
$assoc_taxes = array();
foreach ($xml->taxes->tax as $taxData) {
/** @var SimpleXMLElement $taxData */
$attributes = $taxData->attributes();
if ($id_tax = Tax::getTaxIdByName($attributes['name'])) {
$assoc_taxes[(int) $attributes['id']] = $id_tax;
continue;
}
$tax = new Tax();
$tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $attributes['name'];
$tax->rate = (double) $attributes['rate'];
$tax->active = 1;
if (($error = $tax->validateFields(false, true)) !== true || ($error = $tax->validateFieldsLang(false, true)) !== true) {
$this->_errors[] = Tools::displayError('Invalid tax properties.') . ' ' . $error;
return false;
}
if (!$tax->add()) {
$this->_errors[] = Tools::displayError('An error occurred while importing the tax: ') . (string) $attributes['name'];
return false;
}
$assoc_taxes[(int) $attributes['id']] = $tax->id;
}
foreach ($xml->taxes->taxRulesGroup as $group) {
/** @var SimpleXMLElement $group */
$group_attributes = $group->attributes();
if (!Validate::isGenericName($group_attributes['name'])) {
continue;
}
if (TaxRulesGroup::getIdByName($group['name'])) {
continue;
}
$trg = new TaxRulesGroup();
$trg->name = $group['name'];
$trg->active = 1;
if (!$trg->save()) {
$this->_errors[] = Tools::displayError('This tax rule cannot be saved.');
return false;
}
foreach ($group->taxRule as $rule) {
/** @var SimpleXMLElement $rule */
$rule_attributes = $rule->attributes();
// Validation
if (!isset($rule_attributes['iso_code_country'])) {
continue;
}
$id_country = (int) Country::getByIso(strtoupper($rule_attributes['iso_code_country']));
if (!$id_country) {
continue;
}
if (!isset($rule_attributes['id_tax']) || !array_key_exists(strval($rule_attributes['id_tax']), $assoc_taxes)) {
continue;
}
// Default values
$id_state = (int) isset($rule_attributes['iso_code_state']) ? State::getIdByIso(strtoupper($rule_attributes['iso_code_state'])) : 0;
$id_county = 0;
$zipcode_from = 0;
$zipcode_to = 0;
$behavior = $rule_attributes['behavior'];
if (isset($rule_attributes['zipcode_from'])) {
$zipcode_from = $rule_attributes['zipcode_from'];
if (isset($rule_attributes['zipcode_to'])) {
$zipcode_to = $rule_attributes['zipcode_to'];
}
}
// Creation
$tr = new TaxRule();
$tr->id_tax_rules_group = $trg->id;
$tr->id_country = $id_country;
$tr->id_state = $id_state;
$tr->id_county = $id_county;
$tr->zipcode_from = $zipcode_from;
$tr->zipcode_to = $zipcode_to;
$tr->behavior = $behavior;
$tr->description = '';
$tr->id_tax = $assoc_taxes[strval($rule_attributes['id_tax'])];
$tr->save();
}
}
}
return true;
}
示例2: generateEuropeTaxRule
private function generateEuropeTaxRule()
{
$euro_vat_array = self::$europe_vat_array;
$euro_tax_rule_grp_id = TaxRulesGroup::getIdByName((string) $this->european_vat_name);
if (!$euro_tax_rule_grp_id) {
// Create it
$trg = new TaxRulesGroup();
$trg->name = (string) $this->european_vat_name;
$trg->active = 1;
if (!$trg->save()) {
$this->_errors[] = Tools::displayError('Tax rule cannot be saved.');
return false;
}
$euro_tax_rule_grp_id = (int) $trg->id;
}
$tax_rules_euro_group = TaxRule::getTaxRulesByGroupId((int) Context::getContext()->language->id, (int) $euro_tax_rule_grp_id);
$euro_group_taxes_rules = array();
foreach ($tax_rules_euro_group as $tax_rule) {
$euro_group_taxes_rules[] = $tax_rule;
}
foreach ($euro_vat_array as $euro_vat_name => $euro_vat_details) {
$posted_euro_vat = 'euro_vat_' . (string) $euro_vat_details['iso_country'];
$posted_available_vat = 'available_vat_' . (string) $euro_vat_details['iso_country'];
$country_id = Country::getByIso((string) $euro_vat_details['iso_country']);
if (Tools::isSubmit($posted_euro_vat)) {
if (!Tools::isSubmit($posted_available_vat)) {
$id_tax_found = Tax::getTaxIdByName((string) $euro_vat_name);
if ($id_tax_found !== false) {
$tax = new Tax((int) $id_tax_found);
} else {
$tax = new Tax();
}
$tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $euro_vat_name;
$tax->rate = (double) $euro_vat_details['rate'];
$tax->active = 1;
if ($tax->validateFields(false, true) !== true || $tax->validateFieldsLang(false, true) !== true) {
$this->_errors[] = Tools::displayError('Invalid tax properties.');
continue;
}
if (!$tax->save()) {
$this->_errors[] = Tools::displayError('An error occurred while saving the tax: ');
continue;
}
$id_tax_rule = $this->getTaxRuleIdFromUnique($euro_tax_rule_grp_id, $country_id, $id_tax_found);
if ($id_tax_rule !== false) {
$tr = new TaxRule((int) $id_tax_rule);
} else {
$tr = new TaxRule();
}
$tr->id_tax_rules_group = (int) $euro_tax_rule_grp_id;
$tr->id_country = (int) $country_id;
$tr->id_state = 0;
$tr->id_county = 0;
$tr->zipcode_from = 0;
$tr->zipcode_to = 0;
$tr->behavior = 0;
$tr->description = '';
$tr->id_tax = (int) $tax->id;
$tr->save();
} else {
$assoc_id_tax = (int) Tools::getValue($posted_available_vat);
$id_tax_rule = $this->getTaxRuleIdFromUnique($euro_tax_rule_grp_id, $country_id, $assoc_id_tax);
if ($id_tax_rule !== false) {
$tr = new TaxRule((int) $id_tax_rule);
} else {
$tr = new TaxRule();
}
$tr->id_tax_rules_group = (int) $euro_tax_rule_grp_id;
$tr->id_country = (int) $country_id;
$tr->id_state = 0;
$tr->id_county = 0;
$tr->zipcode_from = 0;
$tr->zipcode_to = 0;
$tr->behavior = 0;
$tr->description = '';
$tr->id_tax = (int) $assoc_id_tax;
$tr->save();
}
} else {
$this->_errors[] = Tools::displayError('Invalid parameters received');
}
}
}
示例3: taxamoCreateParams
public static function taxamoCreateParams()
{
$res_craete_params = array('error' => null, 'success' => false);
$product_types = array();
$public_token = Tools::getValue('TAXAMOEUVAT_TOKENPUBLIC', Configuration::get('TAXAMOEUVAT_TOKENPUBLIC'));
$res_api_product_types = self::getResApi('https://api.taxamo.com/api/v1/dictionaries/product_types', 'GET', array('public_token' => $public_token));
if ($res_api_product_types && isset($res_api_product_types['dictionary'])) {
$res_product_types_dictionary = $res_api_product_types['dictionary'];
foreach ($res_product_types_dictionary as $product_type) {
if (isset($product_type['code'])) {
$product_types[] = $product_type['code'];
}
}
if (count($product_types) <= 0) {
$res_craete_params['error'] = 'Error In Product Types Dictionary';
return $res_craete_params;
}
} else {
$res_craete_params['error'] = 'Error In API Product Types Dictionary';
return $res_craete_params;
}
@set_time_limit(0);
$generic_name = Tools::getValue('TAXAMOEUVAT_GENERICNAME', Configuration::get('TAXAMOEUVAT_GENERICNAME'));
$params_tax = array();
$res_api_countries = self::getResApi('https://api.taxamo.com/api/v1/dictionaries/countries', 'GET', array('tax_supported' => 'true', 'public_token' => $public_token));
if ($res_api_countries && isset($res_api_countries['dictionary'])) {
$res_countries_dictionary = $res_api_countries['dictionary'];
foreach ($res_countries_dictionary as $country) {
if (isset($country['tax_supported'], $country['cca2']) && (bool) $country['tax_supported']) {
$id_country = Country::getByIso($country['cca2']);
if (!$id_country) {
// continue;
$res_craete_params['error'] = 'Error In Procedure Countries';
return $res_craete_params;
}
foreach ($product_types as $product_type) {
$res_api_calculate = self::getResApi('https://api.taxamo.com/api/v1/tax/calculate', 'GET', array('public_token' => $public_token, 'currency_code' => 'EUR', 'force_country_code' => $country['cca2'], 'buyer_tax_number' => null, 'product_type' => $product_type, 'amount' => 100));
if ($res_api_calculate && isset($res_api_calculate['transaction']['transaction_lines'][0])) {
$res_tax = $res_api_calculate['transaction']['transaction_lines'][0];
$tax_name = $generic_name . ' ' . $country['cca2'] . ' ' . $product_type . ' ' . trim((string) $res_tax['tax_rate']) . '%';
$params_tax[] = array('name' => $tax_name, 'rate' => $res_tax['tax_rate'], 'active' => 1, 'product_type' => $product_type, 'id_country' => $id_country);
} else {
$res_craete_params['error'] = 'Error In API Tax Calculate';
return $res_craete_params;
}
}
}
}
if (count($params_tax) <= 0) {
$res_craete_params['error'] = 'Error In Countries Dictionary';
return $res_craete_params;
}
} else {
$res_craete_params['error'] = 'Error In API Countries Dictionary';
return $res_craete_params;
}
foreach ($params_tax as $key => $tax_values) {
if (!Validate::isGenericName($tax_values['name'])) {
// continue;
$res_craete_params['error'] = 'Error In Procedure Tax';
return $res_craete_params;
}
if (!($id_tax = Tax::getTaxIdByName($tax_values['name'], 1))) {
$id_tax = Tax::getTaxIdByName($tax_values['name'], 0);
}
if ($id_tax) {
$tax = new Tax($id_tax);
if ($tax->rate != (double) $tax_values['rate'] || $tax->active != 1) {
$tax->rate = (double) $tax_values['rate'];
$tax->active = 1;
if (($error = $tax->validateFields(false, true)) !== true || ($error = $tax->validateFieldsLang(false, true)) !== true) {
$res_craete_params['error'] = 'Invalid tax properties (update). ' . $error;
return $res_craete_params;
}
if (!$tax->update()) {
$res_craete_params['error'] = 'An error occurred while updating the tax: ' . (string) $tax_values['name'];
return $res_craete_params;
}
}
$params_tax[$key]['id_tax'] = $id_tax;
} else {
$tax = new Tax();
$tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $tax_values['name'];
$tax->rate = (double) $tax_values['rate'];
$tax->active = 1;
if (($error = $tax->validateFields(false, true)) !== true || ($error = $tax->validateFieldsLang(false, true)) !== true) {
$res_craete_params['error'] = 'Invalid tax properties (add). ' . $error;
return $res_craete_params;
}
if (!$tax->add()) {
$res_craete_params['error'] = 'An error occurred while importing the tax: ' . (string) $tax_values['name'];
return $res_craete_params;
}
$params_tax[$key]['id_tax'] = $tax->id;
}
}
foreach ($product_types as $product_type) {
$tax_group_name = $generic_name . ' - ' . $product_type;
if (!Validate::isGenericName($tax_group_name)) {
// continue;
//.........这里部分代码省略.........
示例4: 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
//.........这里部分代码省略.........
示例5: createParams
private function createParams()
{
$product_types = array();
$public_token = Tools::getValue('TAXAMOEUVAT_TOKENPUBLIC', Configuration::get('TAXAMOEUVAT_TOKENPUBLIC'));
$res_api_product_types = $this->getResApi('https://api.taxamo.com/api/v1/dictionaries/product_types', 'GET', array('public_token' => $public_token));
if ($res_api_product_types && isset($res_api_product_types['dictionary'])) {
$res_product_types_dictionary = $res_api_product_types['dictionary'];
foreach ($res_product_types_dictionary as $product_type) {
if (isset($product_type['code'])) {
$product_types[] = $product_type['code'];
}
}
if (count($product_types) <= 0) {
$this->_html .= $this->displayError($this->l('Error In Product Types Dictionary'));
return false;
}
} else {
return false;
}
@set_time_limit(0);
$generic_name = Tools::getValue('TAXAMOEUVAT_GENERICNAME', Configuration::get('TAXAMOEUVAT_GENERICNAME'));
$params_tax = array();
$res_api_countries = $this->getResApi('https://api.taxamo.com/api/v1/dictionaries/countries', 'GET', array('tax_supported' => 'true', 'public_token' => $public_token));
if ($res_api_countries && isset($res_api_countries['dictionary'])) {
$res_countries_dictionary = $res_api_countries['dictionary'];
foreach ($res_countries_dictionary as $country) {
if (isset($country['tax_supported'], $country['cca2']) && (bool) $country['tax_supported']) {
$id_country = Country::getByIso($country['cca2']);
if (!$id_country) {
continue;
}
foreach ($product_types as $product_type) {
$res_api_calculate = $this->getResApi('https://api.taxamo.com/api/v1/tax/calculate', 'GET', array('public_token' => $public_token, 'currency_code' => 'EUR', 'force_country_code' => $country['cca2'], 'buyer_tax_number' => null, 'product_type' => $product_type, 'amount' => 100));
if ($res_api_calculate && isset($res_api_calculate['transaction']['transaction_lines'][0])) {
$res_tax = $res_api_calculate['transaction']['transaction_lines'][0];
$tax_name = $generic_name . ' ' . $country['cca2'] . ' ' . $product_type . ' ' . trim((string) $res_tax['tax_rate']) . '%';
$params_tax[] = array('name' => $tax_name, 'rate' => $res_tax['tax_rate'], 'active' => 1, 'product_type' => $product_type, 'id_country' => $id_country);
}
}
}
}
}
foreach ($params_tax as $key => $tax_values) {
if (!Validate::isGenericName($tax_values['name'])) {
continue;
}
if ($id_tax = Tax::getTaxIdByName($tax_values['name'])) {
$params_tax[$key]['id_tax'] = $id_tax;
continue;
}
$tax = new Tax();
$tax->name[(int) Configuration::get('PS_LANG_DEFAULT')] = (string) $tax_values['name'];
$tax->rate = (double) $tax_values['rate'];
$tax->active = 1;
if (($error = $tax->validateFields(false, true)) !== true || ($error = $tax->validateFieldsLang(false, true)) !== true) {
$this->_html .= $this->displayError('Invalid tax properties.') . ' ' . $error;
return false;
}
if (!$tax->add()) {
$this->_html .= $this->displayError('An error occurred while importing the tax: ') . (string) $tax_values['name'];
return false;
}
$params_tax[$key]['id_tax'] = $tax->id;
}
foreach ($product_types as $product_type) {
$tax_group_name = $generic_name . ' - ' . $product_type;
if (!Validate::isGenericName($tax_group_name)) {
continue;
}
if (TaxRulesGroup::getIdByName($tax_group_name)) {
$this->_html .= $this->displayError('This tax rule group cannot be saved, exists.');
return false;
}
$trg = new TaxRulesGroup();
$trg->name = $tax_group_name;
$trg->active = 1;
if (!$trg->save()) {
$this->_html .= $this->displayError('This tax rule group cannot be saved.');
return false;
}
foreach ($params_tax as $tax_values) {
if ($tax_values['product_type'] == $product_type) {
// Creation
$tr = new TaxRule();
$tr->id_tax_rules_group = $trg->id;
$tr->id_country = $tax_values['id_country'];
$tr->id_state = 0;
$tr->id_county = 0;
$tr->zipcode_from = 0;
$tr->zipcode_to = 0;
$tr->behavior = 0;
$tr->description = '';
$tr->id_tax = $tax_values['id_tax'];
$tr->save();
}
}
}
return true;
}