本文整理汇总了PHP中Supplier::supplierExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Supplier::supplierExists方法的具体用法?PHP Supplier::supplierExists怎么用?PHP Supplier::supplierExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Supplier
的用法示例。
在下文中一共展示了Supplier::supplierExists方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addressImport
public function addressImport()
{
$this->receiveTab();
$defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
$handle = $this->openCsvFile();
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);
self::setDefaultValues($info);
$address = new Address();
self::array_walk($info, array('AdminImport', 'fillInfo'), $address);
if (isset($address->country) and is_numeric($address->country)) {
if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
$address->id_country = (int) $address->country;
}
} elseif (isset($address->country) and is_string($address->country) and !empty($address->country)) {
if ($id_country = Country::getIdByName(NULL, $address->country)) {
$address->id_country = (int) $id_country;
} else {
$country = new Country();
$country->active = 1;
$country->name = self::createMultiLangField($address->country);
$country->id_zone = 0;
// Default zone for country to create
$country->iso_code = strtoupper(substr($address->country, 0, 2));
// Default iso for country to create
$country->contains_states = 0;
// Default value for country to create
$langFieldError = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
if (($fieldError = $country->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $country->add()) {
$address->id_country = (int) $country->id;
} else {
$this->_errors[] = $country->name[$defaultLanguageId] . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
}
if (isset($address->state) and is_numeric($address->state)) {
if (State::getNameById((int) $address->state)) {
$address->id_state = (int) $address->state;
}
} elseif (isset($address->state) and is_string($address->state) and !empty($address->state)) {
if ($id_state = State::getIdByName($address->state)) {
$address->id_state = (int) $id_state;
} else {
$state = new State();
$state->active = 1;
$state->name = $address->state;
$state->id_country = isset($country->id) ? (int) $country->id : 0;
$state->id_zone = 0;
// Default zone for state to create
$state->iso_code = strtoupper(substr($address->state, 0, 2));
// Default iso for state to create
$state->tax_behavior = 0;
if (($fieldError = $state->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $state->add()) {
$address->id_state = (int) $state->id;
} else {
$this->_errors[] = $state->name . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
}
if (isset($address->customer_email) and !empty($address->customer_email)) {
if (Validate::isEmail($address->customer_email)) {
$customer = Customer::customerExists($address->customer_email, true);
if ($customer) {
$address->id_customer = (int) $customer;
} else {
$this->_errors[] = mysql_error() . ' ' . $address->customer_email . ' ' . Tools::displayError('does not exist in database') . ' ' . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
}
} else {
$this->_errors[] = '"' . $address->customer_email . '" :' . Tools::displayError('Is not a valid Email');
}
}
if (isset($address->manufacturer) and is_numeric($address->manufacturer) and Manufacturer::manufacturerExists((int) $address->manufacturer)) {
$address->id_manufacturer = (int) $address->manufacturer;
} elseif (isset($address->manufacturer) and is_string($address->manufacturer) and !empty($address->manufacturer)) {
$manufacturer = new Manufacturer();
$manufacturer->name = $address->manufacturer;
if (($fieldError = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $manufacturer->add()) {
$address->id_manufacturer = (int) $manufacturer->id;
} else {
$this->_errors[] = mysql_error() . ' ' . $manufacturer->name . (isset($manufacturer->id) ? ' (' . $manufacturer->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
}
if (isset($address->supplier) and is_numeric($address->supplier) and Supplier::supplierExists((int) $address->supplier)) {
$address->id_supplier = (int) $address->supplier;
} elseif (isset($address->supplier) and is_string($address->supplier) and !empty($address->supplier)) {
$supplier = new Supplier();
$supplier->name = $address->supplier;
if (($fieldError = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $supplier->add()) {
$address->id_supplier = (int) $supplier->id;
} else {
$this->_errors[] = mysql_error() . ' ' . $supplier->name . (isset($supplier->id) ? ' (' . $supplier->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
$this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
}
//.........这里部分代码省略.........
示例2: supplyOrdersImportOne
protected function supplyOrdersImportOne($info, $force_ids, $current_line, $validateOnly = false)
{
// sets default values if needed
AdminImportController::setDefaultValues($info);
// if an id is set, instanciates a supply order with this id if possible
if (array_key_exists('id', $info) && (int) $info['id'] && SupplyOrder::exists((int) $info['id'])) {
$supply_order = new SupplyOrder((int) $info['id']);
} elseif (array_key_exists('reference', $info) && $info['reference'] && SupplyOrder::exists(pSQL($info['reference']))) {
$supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['reference']));
} else {
// new supply order
$supply_order = new SupplyOrder();
}
// gets parameters
$id_supplier = (int) $info['id_supplier'];
$id_lang = (int) $info['id_lang'];
$id_warehouse = (int) $info['id_warehouse'];
$id_currency = (int) $info['id_currency'];
$reference = pSQL($info['reference']);
$date_delivery_expected = pSQL($info['date_delivery_expected']);
$discount_rate = (double) $info['discount_rate'];
$is_template = (bool) $info['is_template'];
$error = '';
// checks parameters
if (!Supplier::supplierExists($id_supplier)) {
$error = sprintf($this->l('Supplier ID (%d) is not valid (at line %d).'), $id_supplier, $current_line + 1);
}
if (!Language::getLanguage($id_lang)) {
$error = sprintf($this->l('Lang ID (%d) is not valid (at line %d).'), $id_lang, $current_line + 1);
}
if (!Warehouse::exists($id_warehouse)) {
$error = sprintf($this->l('Warehouse ID (%d) is not valid (at line %d).'), $id_warehouse, $current_line + 1);
}
if (!Currency::getCurrency($id_currency)) {
$error = sprintf($this->l('Currency ID (%d) is not valid (at line %d).'), $id_currency, $current_line + 1);
}
if (empty($supply_order->reference) && SupplyOrder::exists($reference)) {
$error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1);
}
if (!empty($supply_order->reference) && ($supply_order->reference != $reference && SupplyOrder::exists($reference))) {
$error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1);
}
if (!Validate::isDateFormat($date_delivery_expected)) {
$error = sprintf($this->l('Date format (%s) is not valid (at line %d). It should be: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD'));
} elseif (new DateTime($date_delivery_expected) <= new DateTime('yesterday')) {
$error = sprintf($this->l('Date (%s) cannot be in the past (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD'));
}
if ($discount_rate < 0 || $discount_rate > 100) {
$error = sprintf($this->l('Discount rate (%d) is not valid (at line %d). %s.'), $discount_rate, $current_line + 1, $this->l('Format: Between 0 and 100'));
}
if ($supply_order->id > 0 && !$supply_order->isEditable()) {
$error = sprintf($this->l('Supply Order (%d) is not editable (at line %d).'), $supply_order->id, $current_line + 1);
}
// if no errors, sets supply order
if (empty($error)) {
// adds parameters
$info['id_ref_currency'] = (int) Currency::getDefaultCurrency()->id;
$info['supplier_name'] = pSQL(Supplier::getNameById($id_supplier));
if ($supply_order->id > 0) {
$info['id_supply_order_state'] = (int) $supply_order->id_supply_order_state;
$info['id'] = (int) $supply_order->id;
} else {
$info['id_supply_order_state'] = 1;
}
// sets parameters
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $supply_order);
// updatesd($supply_order);
$res = false;
if ((int) $supply_order->id && ($supply_order->exists((int) $supply_order->id) || $supply_order->exists($supply_order->reference))) {
$res = $validateOnly || $supply_order->update();
} else {
$supply_order->force_id = (bool) $force_ids;
$res = $validateOnly || $supply_order->add();
}
// errors
if (!$res) {
$this->errors[] = sprintf($this->l('Supply Order could not be saved (at line %d).'), $current_line + 1);
}
} else {
$this->errors[] = $error;
}
}
示例3: postProcess
/**
* AdminController::postProcess() override
* @see AdminController::postProcess()
*/
public function postProcess()
{
$this->is_editing_order = false;
// Checks access
if (Tools::isSubmit('submitAddsupply_order') && !($this->tabAccess['add'] === '1')) {
$this->errors[] = Tools::displayError('You do not have permission to add a supply order.');
}
if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && !($this->tabAccess['edit'] === '1')) {
$this->errors[] = Tools::displayError('You do not have permission to edit an order.');
}
// Trick to use both Supply Order as template and actual orders
if (Tools::isSubmit('is_template')) {
$_GET['mod'] = 'template';
}
// checks if supply order reference is unique
if (Tools::isSubmit('reference')) {
// gets the reference
$ref = pSQL(Tools::getValue('reference'));
if (Tools::getValue('id_supply_order') != 0 && SupplyOrder::getReferenceById((int) Tools::getValue('id_supply_order')) != $ref) {
if ((int) SupplyOrder::exists($ref) != 0) {
$this->errors[] = Tools::displayError('The reference has to be unique.');
}
} elseif (Tools::getValue('id_supply_order') == 0 && (int) SupplyOrder::exists($ref) != 0) {
$this->errors[] = Tools::displayError('The reference has to be unique.');
}
}
if ($this->errors) {
return;
}
// Global checks when add / update a supply order
if (Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitAddsupply_orderAndStay')) {
$this->action = 'save';
$this->is_editing_order = true;
// get supplier ID
$id_supplier = (int) Tools::getValue('id_supplier', 0);
if ($id_supplier <= 0 || !Supplier::supplierExists($id_supplier)) {
$this->errors[] = Tools::displayError('The selected supplier is not valid.');
}
// get warehouse id
$id_warehouse = (int) Tools::getValue('id_warehouse', 0);
if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) {
$this->errors[] = Tools::displayError('The selected warehouse is not valid.');
}
// get currency id
$id_currency = (int) Tools::getValue('id_currency', 0);
if ($id_currency <= 0 || (!($result = Currency::getCurrency($id_currency)) || empty($result))) {
$this->errors[] = Tools::displayError('The selected currency is not valid.');
}
// get delivery date
if (Tools::getValue('mod') != 'template' && strtotime(Tools::getValue('date_delivery_expected')) <= strtotime('-1 day')) {
$this->errors[] = Tools::displayError('The specified date cannot be in the past.');
}
// gets threshold
$quantity_threshold = Tools::getValue('load_products');
if (is_numeric($quantity_threshold)) {
$quantity_threshold = (int) $quantity_threshold;
} else {
$quantity_threshold = null;
}
if (!count($this->errors)) {
// forces date for templates
if (Tools::isSubmit('is_template') && !Tools::getValue('date_delivery_expected')) {
$_POST['date_delivery_expected'] = date('Y-m-d h:i:s');
}
// specify initial state
$_POST['id_supply_order_state'] = 1;
//defaut creation state
// specify global reference currency
$_POST['id_ref_currency'] = Currency::getDefaultCurrency()->id;
// specify supplier name
$_POST['supplier_name'] = Supplier::getNameById($id_supplier);
//specific discount check
$_POST['discount_rate'] = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('discount_rate', 0));
}
// manage each associated product
$this->manageOrderProducts();
// if the threshold is defined and we are saving the order
if (Tools::isSubmit('submitAddsupply_order') && Validate::isInt($quantity_threshold)) {
$this->loadProducts((int) $quantity_threshold);
}
}
// Manage state change
if (Tools::isSubmit('submitChangestate') && Tools::isSubmit('id_supply_order') && Tools::isSubmit('id_supply_order_state')) {
if ($this->tabAccess['edit'] != '1') {
$this->errors[] = Tools::displayError('You do not have permission to change the order status.');
}
// get state ID
$id_state = (int) Tools::getValue('id_supply_order_state', 0);
if ($id_state <= 0) {
$this->errors[] = Tools::displayError('The selected supply order status is not valid.');
}
// get supply order ID
$id_supply_order = (int) Tools::getValue('id_supply_order', 0);
if ($id_supply_order <= 0) {
$this->errors[] = Tools::displayError('The supply order ID is not valid.');
}
//.........这里部分代码省略.........
示例4: supplyOrdersImport
/**
* @since 1.5.0
*/
public function supplyOrdersImport()
{
// opens CSV & sets locale
$this->receiveTab();
$handle = $this->openCsvFile();
AdminImportController::setLocale();
// main loop, for each supply orders to import
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); ++$current_line) {
// if convert requested
if (Tools::getValue('convert')) {
$line = $this->utf8EncodeArray($line);
}
$info = AdminImportController::getMaskedRow($line);
// sets default values if needed
AdminImportController::setDefaultValues($info);
// if an id is set, instanciates a supply order with this id if possible
if (array_key_exists('id', $info) && (int) $info['id'] && SupplyOrder::exists((int) $info['id'])) {
$supply_order = new SupplyOrder((int) $info['id']);
} elseif (array_key_exists('reference', $info) && $info['reference'] && SupplyOrder::exists(pSQL($info['reference']))) {
$supply_order = SupplyOrder::getSupplyOrderByReference(pSQL($info['reference']));
} else {
// new supply order
$supply_order = new SupplyOrder();
}
// gets parameters
$id_supplier = (int) $info['id_supplier'];
$id_lang = (int) $info['id_lang'];
$id_warehouse = (int) $info['id_warehouse'];
$id_currency = (int) $info['id_currency'];
$reference = pSQL($info['reference']);
$date_delivery_expected = pSQL($info['date_delivery_expected']);
$discount_rate = (double) $info['discount_rate'];
$is_template = (bool) $info['is_template'];
$error = '';
// checks parameters
if (!Supplier::supplierExists($id_supplier)) {
$error = sprintf($this->l('Supplier ID (%d) is not valid (at line %d).'), $id_supplier, $current_line + 1);
}
if (!Language::getLanguage($id_lang)) {
$error = sprintf($this->l('Lang ID (%d) is not valid (at line %d).'), $id_lang, $current_line + 1);
}
if (!Warehouse::exists($id_warehouse)) {
$error = sprintf($this->l('Warehouse ID (%d) is not valid (at line %d).'), $id_warehouse, $current_line + 1);
}
if (!Currency::getCurrency($id_currency)) {
$error = sprintf($this->l('Currency ID (%d) is not valid (at line %d).'), $id_currency, $current_line + 1);
}
if (empty($supply_order->reference) && SupplyOrder::exists($reference)) {
$error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1);
}
if (!empty($supply_order->reference) && ($supply_order->reference != $reference && SupplyOrder::exists($reference))) {
$error = sprintf($this->l('Reference (%s) already exists (at line %d).'), $reference, $current_line + 1);
}
if (!Validate::isDateFormat($date_delivery_expected)) {
$error = sprintf($this->l('Date (%s) is not valid (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD'));
} elseif (new DateTime($date_delivery_expected) <= new DateTime('yesterday')) {
$error = sprintf($this->l('Date (%s) cannot be in the past (at line %d). Format: %s.'), $date_delivery_expected, $current_line + 1, $this->l('YYYY-MM-DD'));
}
if ($discount_rate < 0 || $discount_rate > 100) {
$error = sprintf($this->l('Discount rate (%d) is not valid (at line %d). %s.'), $discount_rate, $current_line + 1, $this->l('Format: Between 0 and 100'));
}
if ($supply_order->id > 0 && !$supply_order->isEditable()) {
$error = sprintf($this->l('Supply Order (%d) is not editable (at line %d).'), $supply_order->id, $current_line + 1);
}
// if no errors, sets supply order
if (empty($error)) {
// adds parameters
$info['id_ref_currency'] = (int) Currency::getDefaultCurrency()->id;
$info['supplier_name'] = pSQL(Supplier::getNameById($id_supplier));
if ($supply_order->id > 0) {
$info['id_supply_order_state'] = (int) $supply_order->id_supply_order_state;
$info['id'] = (int) $supply_order->id;
} else {
$info['id_supply_order_state'] = 1;
}
// sets parameters
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $supply_order);
// updatesd($supply_order);
$res = true;
if ((int) $supply_order->id && ($supply_order->exists((int) $supply_order->id) || $supply_order->exists($supply_order->reference))) {
$res &= $supply_order->update();
} else {
$supply_order->force_id = (bool) Tools::getValue('forceIDs');
$res &= $supply_order->add();
}
// errors
if (!$res) {
$this->errors[] = sprintf($this->l('Supply Order could not be saved (at line %d).'), $current_line + 1);
}
} else {
$this->errors[] = $error;
}
}
// closes
$this->closeCsvFile($handle);
}
示例5: productImport
//.........这里部分代码省略.........
foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
if (!empty($shop) && !is_numeric($shop)) {
$product->id_shop_list[] = Shop::getIdByName($shop);
} elseif (!empty($shop)) {
$product->id_shop_list[] = $shop;
}
}
if ((int) $product->id_tax_rules_group != 0) {
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
$address = $this->context->shop->getAddress();
$tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product->tax_rate = $product_tax_calculator->getTotalRate();
} else {
$this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID. You first need to create a group with this ID.'));
}
}
if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
$product->id_manufacturer = (int) $product->manufacturer;
} elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
$product->id_manufacturer = (int) $manufacturer;
} else {
$manufacturer = new Manufacturer();
$manufacturer->name = $product->manufacturer;
if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
$product->id_manufacturer = (int) $manufacturer->id;
} else {
$this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
if (isset($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int) $product->supplier)) {
$product->id_supplier = (int) $product->supplier;
} elseif (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) {
if ($supplier = Supplier::getIdByName($product->supplier)) {
$product->id_supplier = (int) $supplier;
} else {
$supplier = new Supplier();
$supplier->name = $product->supplier;
$supplier->active = true;
if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $supplier->add()) {
$product->id_supplier = (int) $supplier->id;
$supplier->associateTo($product->id_shop_list);
} else {
$this->errors[] = sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $supplier->name, isset($supplier->id) && !empty($supplier->id) ? $supplier->id : 'null');
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
if (isset($product->price_tex) && !isset($product->price_tin)) {
$product->price = $product->price_tex;
} elseif (isset($product->price_tin) && !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) && isset($product->price_tex)) {
$product->price = $product->price_tex;
}
if (!Configuration::get('PS_USE_ECOTAX')) {
$product->ecotax = 0;
}
$properties = $product->productProperties();
示例6: postProcess
/**
* AdminController::postProcess() override
* @see AdminController::postProcess()
*/
public function postProcess()
{
$this->is_editing_order = false;
// Checks access
if (Tools::isSubmit('submitAddsupply_order') && !($this->tabAccess['add'] === '1')) {
$this->errors[] = Tools::displayError($this->l('You do not have permission to add a supply order.'));
}
if (Tools::isSubmit('submitBulkUpdatesupply_order_detail') && !($this->tabAccess['edit'] === '1')) {
$this->errors[] = Tools::displayError($this->l('You do not have permission to edit an order.'));
}
// Trick to use both Supply Order as template and actual orders
if (Tools::isSubmit('is_template')) {
$_GET['mod'] = 'template';
}
// checks if supply order reference is unique
if (Tools::isSubmit('reference')) {
// gets the reference
$ref = pSQL(Tools::getValue('reference'));
if (Tools::getValue('id_supply_order') != 0 && SupplyOrder::getReferenceById((int) Tools::getValue('id_supply_order')) != $ref) {
if ((int) SupplyOrder::exists($ref) != 0) {
$this->errors[] = Tools::displayError($this->l('The reference has to be unique.'));
}
} else {
if (Tools::getValue('id_supply_order') == 0 && (int) SupplyOrder::exists($ref) != 0) {
$this->errors[] = Tools::displayError($this->l('The reference has to be unique.'));
}
}
}
if ($this->errors) {
return;
}
// Global checks when add / update a supply order
if (Tools::isSubmit('submitAddsupply_order') || Tools::isSubmit('submitAddsupply_orderAndStay')) {
$this->action = 'save';
$this->is_editing_order = true;
// get supplier ID
$id_supplier = (int) Tools::getValue('id_supplier', 0);
if ($id_supplier <= 0 || !Supplier::supplierExists($id_supplier)) {
$this->errors[] = Tools::displayError($this->l('The selected supplier is not valid.'));
}
// get warehouse id
$id_warehouse = (int) Tools::getValue('id_warehouse', 0);
if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) {
$this->errors[] = Tools::displayError($this->l('The selected warehouse is not valid.'));
}
// get currency id
$id_currency = (int) Tools::getValue('id_currency', 0);
if ($id_currency <= 0 || (!($result = Currency::getCurrency($id_currency)) || empty($result))) {
$this->errors[] = Tools::displayError($this->l('The selected currency is not valid.'));
}
// get delivery date
$delivery_expected = new DateTime(pSQL(Tools::getValue('date_delivery_expected')));
// converts date to timestamp
if ($delivery_expected <= new DateTime('yesterday')) {
$this->errors[] = Tools::displayError($this->l('The date you specified cannot be in the past.'));
}
// gets threshold
$quantity_threshold = Tools::getValue('load_products');
if (is_numeric($quantity_threshold)) {
$quantity_threshold = (int) $quantity_threshold;
} else {
$quantity_threshold = null;
}
if (!count($this->errors)) {
// forces date for templates
if (Tools::isSubmit('is_template') && !Tools::getValue('date_delivery_expected')) {
$_POST['date_delivery_expected'] = date('Y-m-d h:i:s');
}
// specify initial state
$_POST['id_supply_order_state'] = 1;
//defaut creation state
// specify global reference currency
$_POST['id_ref_currency'] = Currency::getDefaultCurrency()->id;
// specify supplier name
$_POST['supplier_name'] = Supplier::getNameById($id_supplier);
//specific discount check
$_POST['discount_rate'] = (double) str_replace(array(' ', ','), array('', '.'), Tools::getValue('discount_rate', 0));
}
// manage each associated product
$this->manageOrderProducts();
// if the threshold is defined and we are saving the order
if (Tools::isSubmit('submitAddsupply_order') && Validate::isInt($quantity_threshold)) {
$this->loadProducts((int) $quantity_threshold);
}
//--ERP informations
// updates/creates erp_supplier_order if it does not exist
if (Tools::isSubmit('id_erpip_supply_order') && (int) Tools::getValue('id_erpip_supply_order') > 0) {
$erp_supplier_order = new ErpSupplyOrder((int) Tools::getValue('id_erpip_supply_order'));
} else {
$erp_supplier_order = new ErpSupplyOrder();
}
// creates erp_supplier_order
$erp_supplier_order->escompte = Tools::getValue('escompte', null);
$erp_supplier_order->global_discount_amount = Tools::getValue('global_discount_type', null);
$erp_supplier_order->global_discount_type = Tools::getValue('global_discount_type', null);
$erp_supplier_order->shipping_amount = Tools::getValue('shipping_amount', null);
//.........这里部分代码省略.........