public function hookProductFooter($params) { $id_product = (int) $params['product']->id; /* First we try to display the number of people who are currently watching this product page */ if (Configuration::get('PS_PTOOLTIP_PEOPLE')) { $date = strftime('%Y-%m-%d %H:%M:%S', time() - (int) (Configuration::get('PS_PTOOLTIP_LIFETIME') * 60)); $nbPeople = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(DISTINCT(id_connections)) nb FROM ' . _DB_PREFIX_ . 'page p LEFT JOIN ' . _DB_PREFIX_ . 'connections_page cp ON (p.id_page = cp.id_page) WHERE p.id_page_type = 1 AND p.id_object = ' . (int) $id_product . ' AND cp.time_start > \'' . pSQL($date) . '\''); if (isset($nbPeople['nb']) and $nbPeople['nb'] > 0) { $this->smarty->assign('nb_people', (int) $nbPeople['nb']); } } /* Then, we try to display last sale */ if (Configuration::get('PS_PTOOLTIP_DATE_ORDER')) { $days = (int) Configuration::get('PS_PTOOLTIP_DAYS'); $date = strftime('%Y-%m-%d', strtotime('-' . (int) $days . ' day')); $order = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT o.date_add FROM ' . _DB_PREFIX_ . 'order_detail od LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON (od.id_order = o.id_order) WHERE od.product_id = ' . (int) $id_product . ' AND o.date_add >= \'' . pSQL($date) . '\' ORDER BY o.date_add DESC'); if (isset($order['date_add']) && Validate::isDateFormat($order['date_add']) && $order['date_add'] != '0000-00-00 00:00:00') { $this->smarty->assign('date_last_order', $order['date_add']); } else { /* No sale? display last cart add instead */ if (Configuration::get('PS_PTOOLTIP_DATE_CART')) { $cart = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT cp.date_add FROM ' . _DB_PREFIX_ . 'cart_product cp WHERE cp.id_product = ' . (int) $id_product); if (isset($cart['date_add']) && Validate::isDateFormat($cart['date_add']) && $cart['date_add'] != '0000-00-00 00:00:00') { $this->smarty->assign('date_last_cart', $cart['date_add']); } } } } if (isset($nbPeople['nb']) and $nbPeople['nb'] > 0 or isset($order['date_add']) or isset($cart['date_add'])) { return $this->display(__FILE__, 'producttooltip.tpl'); } }
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; } }
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_combination = 0) { if (!Validate::isUnsignedId($id_shop) || !Validate::isUnsignedId($id_currency) || !Validate::isUnsignedId($id_country) || !Validate::isUnsignedId($id_group) || !Validate::isUnsignedId($id_customer)) { $this->errors[] = Tools::displayError('Wrong IDs'); } elseif (!isset($price) && !isset($reduction) || isset($price) && !Validate::isNegativePrice($price) || isset($reduction) && !Validate::isPrice($reduction)) { $this->errors[] = Tools::displayError('Invalid price/discount amount'); } elseif (!Validate::isUnsignedInt($from_quantity)) { $this->errors[] = Tools::displayError('Invalid quantity'); } elseif ($reduction && !Validate::isReductionType($reduction_type)) { $this->errors[] = Tools::displayError('Please select a discount type (amount or percentage).'); } elseif ($from && $to && (!Validate::isDateFormat($from) || !Validate::isDateFormat($to))) { $this->errors[] = Tools::displayError('The from/to date is invalid.'); } elseif (SpecificPrice::exists((int) $this->object->id, $id_combination, $id_shop, $id_group, $id_country, $id_currency, $id_customer, $from_quantity, $from, $to, false)) { $this->errors[] = Tools::displayError('A specific price already exists for these parameters.'); } else { return true; } return false; }
protected function _validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $price, $from_quantity, $reduction, $reduction_type, $from, $to) { if (!Validate::isUnsignedId($id_shop) or !Validate::isUnsignedId($id_currency) or !Validate::isUnsignedId($id_country) or !Validate::isUnsignedId($id_group)) { $this->_errors[] = Tools::displayError('Wrong ID\'s'); } elseif (empty($price) and empty($reduction) or !empty($price) and !Validate::isPrice($price) or !empty($reduction) and !Validate::isPrice($reduction)) { $this->_errors[] = Tools::displayError('Invalid price/reduction amount'); } elseif (!Validate::isUnsignedInt($from_quantity)) { $this->_errors[] = Tools::displayError('Invalid quantity'); } elseif ($reduction and !Validate::isReductionType($reduction_type)) { $this->_errors[] = Tools::displayError('Please select a reduction type (amount or percentage)'); } elseif ($from and $to and (!Validate::isDateFormat($from) or !Validate::isDateFormat($to))) { $this->_errors[] = Tools::displayError('Wrong from/to date'); } else { return true; } return false; }
private function _postProcess() { //Проверяем отправлена ли форма if(Tools::isSubmit('exportOrder_taxes')) { //Получаем значение поля формы с датами $from_day = sprintf("%02d", Tools::getValue('from_day')); $from_month = sprintf("%02d", Tools::getValue('from_month')); $from_year = Tools::getValue('from_year'); $till_day = sprintf("%02d",Tools::getValue('till_day')); $till_month = sprintf("%02d",Tools::getValue('till_month')); $till_year = Tools::getValue('till_year'); $from_date = $from_year.'-'.$from_month.'-'.$from_day; $till_date = $till_year.'-'.$till_month.'-'.$till_day; //Проверяем валидность даты if(Validate::isDateFormat($from_date) && Validate::isDateFormat($till_date)) { //$this->_html .= $this->displayConfirmation($this->l('Дата верная.')); //Сохраняем настройку //Configuration::updateValue('FROM_DATE', $from_date); $this->exportOrder_taxes ($from_date, $till_date); } else //Выводим сообщение об ошибке $this->_html .= $this->displayError($this->l('Неверная дата.')); } }
/** * @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); }
public function setAvailableDate($available_date = '0000-00-00') { if (Validate::isDateFormat($available_date) && $this->available_date != $available_date) { $this->available_date = $available_date; return $this->update(); } return false; }
private function processCombinations() { ${"GLOBALS"}["eihxllnsogy"] = "product"; if (!Combination::isFeatureActive() || !Tools::getIsset("attribute")) { return; } if (Validate::isLoadedObject(${${"GLOBALS"}["eihxllnsogy"]} = $this->object)) { if ($this->isProductFieldUpdated("attribute_price") && (!Tools::getIsset("attribute_price") || Tools::getIsset("attribute_price") == null)) { $this->errors[] = Tools::displayError("Attribute price required."); } if (!Tools::getIsset("attribute_combination_list") || Tools::isEmpty(Tools::getValue("attribute_combination_list"))) { $this->errors[] = Tools::displayError("You must add at least one attribute."); } if (!count($this->errors)) { if (!isset($_POST["attribute_wholesale_price"])) { $_POST["attribute_wholesale_price"] = 0; } if (!isset($_POST["attribute_price_impact"])) { $_POST["attribute_price_impact"] = 0; } if (!isset($_POST["attribute_weight_impact"])) { $_POST["attribute_weight_impact"] = 0; } if (!isset($_POST["attribute_ecotax"])) { $_POST["attribute_ecotax"] = 0; } if (Tools::getValue("attribute_default")) { $product->deleteDefaultAttributes(); } if (${${"GLOBALS"}["tbhwjssdhx"]} = (int) Tools::getValue("id_product_attribute")) { ${"GLOBALS"}["cpvnlwngne"] = "id_product_attribute"; if ($product->productAttributeExists(Tools::getValue("attribute_combination_list"), (int) ${${"GLOBALS"}["cpvnlwngne"]})) { $this->errors[] = Tools::displayError("This attribute already exists."); } else { if ($this->isProductFieldUpdated("available_date_attribute") && !Validate::isDateFormat(Tools::getValue("available_date_attribute"))) { $this->errors[] = Tools::displayError("Invalid date format."); } else { $product->updateAttribute((int) ${${"GLOBALS"}["tbhwjssdhx"]}, $this->isProductFieldUpdated("attribute_wholesale_price") ? Tools::getValue("attribute_wholesale_price") : null, $this->isProductFieldUpdated("attribute_price_impact") ? Tools::getValue("attribute_price") * Tools::getValue("attribute_price_impact") : null, $this->isProductFieldUpdated("attribute_weight_impact") ? Tools::getValue("attribute_weight") * Tools::getValue("attribute_weight_impact") : null, $this->isProductFieldUpdated("attribute_unit_impact") ? Tools::getValue("attribute_unity") * Tools::getValue("attribute_unit_impact") : null, $this->isProductFieldUpdated("attribute_ecotax") ? Tools::getValue("attribute_ecotax") : null, Tools::getValue("id_image_attr"), Tools::getValue("attribute_reference"), Tools::getValue("attribute_ean13"), $this->isProductFieldUpdated("attribute_default") ? Tools::getValue("attribute_default") : null, Tools::getValue("attribute_location"), Tools::getValue("attribute_upc"), $this->isProductFieldUpdated("attribute_minimal_quantity") ? Tools::getValue("attribute_minimal_quantity") : null, $this->isProductFieldUpdated("available_date_attribute") ? Tools::getValue("available_date_attribute") : null, false); } } } else { ${"GLOBALS"}["bxevjsn"] = "id_product_attribute"; if ($product->productAttributeExists(Tools::getValue("attribute_combination_list"))) { $this->errors[] = Tools::displayError("This combination already exists."); } else { ${${"GLOBALS"}["bxevjsn"]} = $product->addCombinationEntity(Tools::getValue("attribute_wholesale_price"), Tools::getValue("attribute_price") * Tools::getValue("attribute_price_impact"), Tools::getValue("attribute_weight") * Tools::getValue("attribute_weight_impact"), Tools::getValue("attribute_unity") * Tools::getValue("attribute_unit_impact"), Tools::getValue("attribute_ecotax"), 0, Tools::getValue("id_image_attr"), Tools::getValue("attribute_reference"), null, Tools::getValue("attribute_ean13"), Tools::getValue("attribute_default"), Tools::getValue("attribute_location"), Tools::getValue("attribute_upc"), Tools::getValue("attribute_minimal_quantity")); } } if (!count($this->errors)) { ${"GLOBALS"}["gdohtzw"] = "id_product_attribute"; $qqxwhsfpb = "id_images"; ${${"GLOBALS"}["yedtbmwbugs"]} = new Combination((int) ${${"GLOBALS"}["gdohtzw"]}); $combination->setAttributes(Tools::getValue("attribute_combination_list")); ${$qqxwhsfpb} = Tools::getValue("id_image_attr"); if (!empty(${${"GLOBALS"}["cynhhztd"]})) { $combination->setImages(${${"GLOBALS"}["cynhhztd"]}); } $product->checkDefaultAttributes(); if (Tools::getValue("attribute_default")) { Product::updateDefaultAttribute((int) $product->id); $yihcjzfqycuf = "available_date"; $jcuzacll = "id_product_attribute"; ${"GLOBALS"}["yhkmhfis"] = "id_product_attribute"; ${"GLOBALS"}["uxbmswdpvwp"] = "available_date"; if (isset(${${"GLOBALS"}["yhkmhfis"]})) { $product->cache_default_attribute = (int) ${$jcuzacll}; } if (${$yihcjzfqycuf} = Tools::getValue("available_date_attribute")) { $product->setAvailableDate(${${"GLOBALS"}["uxbmswdpvwp"]}); } } } if (!count($this->errors)) { if (!$product->cache_default_attribute) { Product::updateDefaultAttribute($product->id); } } } } }
protected function _validateCustomPrice($id_shop, $id_product, $id_currency, $id_country, $id_group, $id_customer, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $id_combination = 0) { if (!Validate::isUnsignedId($id_shop) || !Validate::isUnsignedId($id_currency)) { //$this->errors[] = Tools::displayError('Wrong IDs'); //error_log(__LINE__); return false; } elseif (!isset($price) && !isset($reduction) || isset($price) && !Validate::isNegativePrice($price) || isset($reduction) && !Validate::isPrice($reduction)) { //$this->errors[] = Tools::displayError('Invalid price/discount amount'); //error_log(__LINE__); return false; } elseif ($reduction && !Validate::isReductionType($reduction_type)) { //$this->errors[] = Tools::displayError('Please select a discount type (amount or percentage).'); //error_log(__LINE__); return false; } elseif ($from && $to && (!Validate::isDateFormat($from) || !Validate::isDateFormat($to))) { //$this->errors[] = Tools::displayError('The from/to date is invalid.'); //error_log(__LINE__); return false; } elseif (empty($this->id) && CustomPrice::exists($id_product, $id_combination, $id_shop, $id_group, $id_country, $id_currency, $id_customer, $from_quantity, $from, $to, false)) { //$this->errors[] = Tools::displayError('A custom price already exists for these parameters.'); //error_log(__LINE__); return false; } else { //error_log(__LINE__); return false; } return false; }
public function validate() { $date = Tools::getValue('pickupDate'); if (!Validate::isDateFormat($date)) { self::$errors[] = $this->l('Wrong date format'); return false; } if (strtotime($date) < strtotime(date('Y-m-d'))) { self::$errors[] = $this->l('Date can not be earlier than') . ' ' . date('Y-m-d'); return false; } if ($this->isWeekend($date)) { self::$errors[] = $this->l('Weekends can not be chosen'); return false; } if (!$this->dox && !$this->parcels && !$this->pallet) { self::$errors[] = $this->l('At least one service must be selected'); return false; } foreach ($this->rules as $element => $rules) { if (!isset($rules['dependency']) || isset($rules['dependency']) && $this->{$rules['dependency']}) { if ($rules['required'] && !$this->{$element}) { self::$errors[] = sprintf($this->l('The "%s" field is required.'), $rules['fieldname']); return false; } elseif ($this->{$element} && method_exists('Validate', $rules['validate']) && !call_user_func(array('Validate', $rules['validate']), $this->{$element})) { self::$errors[] = sprintf($this->l('The "%s" field is invalid.'), $rules['fieldname']); return false; } } } return true; }
public function attribute() { $app = JFactory::getApplication(); // Don't process if the combination fields have not been submitted if (!JeproshopCombinationModelCombination::isFeaturePublished() || !$app->input->get('attribute_combination_list')) { return; } if (Validate::isLoadedObject($product = $this->object)) { if ($this->isProductFieldUpdated('attribute_price') && (!Tools::getIsset('attribute_price') || Tools::getIsset('attribute_price') == null)) { $this->has_errors = Tools::displayError('The price attribute is required.'); } if (!Tools::getIsset('attribute_combination_list') || Tools::isEmpty(Tools::getValue('attribute_combination_list'))) { $this->has_errors = Tools::displayError('You must add at least one attribute.'); } $array_checks = array('reference' => 'isReference', 'supplier_reference' => 'isReference', 'location' => 'isReference', 'ean13' => 'isEan13', 'upc' => 'isUpc', 'wholesale_price' => 'isPrice', 'price' => 'isPrice', 'ecotax' => 'isPrice', 'quantity' => 'isInt', 'weight' => 'isUnsignedFloat', 'unit_price_impact' => 'isPrice', 'default_on' => 'isBool', 'minimal_quantity' => 'isUnsignedInt', 'available_date' => 'isDateFormat'); foreach ($array_checks as $property => $check) { if (Tools::getValue('attribute_' . $property) !== false && !call_user_func(array('Validate', $check), Tools::getValue('attribute_' . $property))) { $this->errors[] = sprintf(Tools::displayError('Field %s is not valid'), $property); } } if (!count($this->errors)) { if (!isset($_POST['attribute_wholesale_price'])) { $_POST['attribute_wholesale_price'] = 0; } if (!isset($_POST['attribute_price_impact'])) { $_POST['attribute_price_impact'] = 0; } if (!isset($_POST['attribute_weight_impact'])) { $_POST['attribute_weight_impact'] = 0; } if (!isset($_POST['attribute_ecotax'])) { $_POST['attribute_ecotax'] = 0; } if (Tools::getValue('attribute_default')) { $product->deleteDefaultAttributes(); } // Change existing one if (($id_product_attribute = (int) Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true))) { if ($this->tabAccess['edit'] === '1') { if ($this->isProductFieldUpdated('available_date_attribute') && (Tools::getValue('available_date_attribute') != '' && !Validate::isDateFormat(Tools::getValue('available_date_attribute')))) { $this->errors[] = Tools::displayError('Invalid date format.'); } else { $product->updateAttribute((int) $id_product_attribute, $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null, $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null, $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null, $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null, $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_ean13'), $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null, Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null, $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, false); StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute); StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute); } } else { $this->errors[] = Tools::displayError('You do not have permission to add this.'); } } else { if ($this->tabAccess['add'] === '1') { if ($product->productAttributeExists(Tools::getValue('attribute_combination_list'))) { $this->errors[] = Tools::displayError('This combination already exists.'); } else { $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), 0, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), null, Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity'), array(), Tools::getValue('available_date_attribute')); StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute); StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute); } } else { $this->errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('edit here.'); } } if (!count($this->errors)) { $combination = new Combination((int) $id_product_attribute); $combination->setAttributes(Tools::getValue('attribute_combination_list')); // images could be deleted before $id_images = Tools::getValue('id_image_attr'); if (!empty($id_images)) { $combination->setImages($id_images); } $product->checkDefaultAttributes(); if (Tools::getValue('attribute_default')) { Product::updateDefaultAttribute((int) $product->id); if (isset($id_product_attribute)) { $product->cache_default_attribute = (int) $id_product_attribute; } if ($available_date = Tools::getValue('available_date_attribute')) { $product->setAvailableDate($available_date); } } } } } }
private function validateSpecificPrice($shop_id, $currency_id, $country_id, $group_id, $customer_id, $price, $from_quantity, $reduction, $reduction_type, $from, $to, $product_attribute_id = 0) { $app = JFactory::getApplication(); $product_id = $app->input->get('product_id'); if (!JeproshopTools::isUnsignedInt($shop_id) || !JeproshopTools::isUnsignedInt($currency_id) || !JeproshopTools::isUnsignedInt($country_id) || !JeproshopTools::isUnsignedInt($group_id) || !JeproshopTools::isUnsignedInt($customer_id)) { $this->context->controller->has_errors = true; JError::raiseError(500, JText::_('Wrong IDs')); } elseif (!isset($price) && !isset($reduction) || isset($price) && !JeproshopTools::isNegativePrice($price) || isset($reduction) && !JeproshopTools::isPrice($reduction)) { $this->context->controller->has_errors = true; JError::raiseError(500, JText::_('Invalid price/discount amount')); } elseif (!JeproshopTools::isUnsignedInt($from_quantity)) { $this->context->controller->has_errors = true; JError::raiseError(500, JText::_('Invalid quantity')); } elseif ($reduction && !JeproshopTools::isReductionType($reduction_type)) { $this->context->controller->has_errors = true; JError::raiseError(500, JText::_('Please select a discount type (amount or percentage).')); } elseif ($from && $to && (!JeproshopTools::isDateFormat($from) || !Validate::isDateFormat($to))) { $this->context->controller->has_errors = true; JError::raiseError(500, JText::_('The from/to date is invalid.')); } elseif (JeproshopSpecificPriceMpdelSpecificPrice::exists((int) $product_id, $product_attribute_id, $shop_id, $group_id, $country_id, $currency_id, $customer_id, $from_quantity, $from, $to, false)) { $this->context->controller->has_errors = true; JError::raiseError(500, JText::_('A specific price already exists for these parameters.')); } else { return true; } return false; }