Beispiel #1
0
 public function getContent()
 {
     $output = null;
     if (Tools::isSubmit('submit' . $this->name)) {
         $list_value = strval(Tools::getValue('PROFIT_MARGIN'));
         if (!$list_value || empty($list_value) || !Validate::isFloat($list_value)) {
             $output .= $this->displayError($this->l('Invalid Configuration value'));
         } else {
             $email_value = strval(Tools::getValue('ORDER_CNF_MANAGER_EMAIL'));
             if (Tools::getValue('ADMIN_CONFIRM_ORDER') == '1' && (empty($email_value) || !Validate::isEmail($email_value))) {
                 $output .= $this->displayError($this->l('Please enter valid Email ID'));
             } else {
                 $email_value = strval(Tools::getValue('PRODUCT_REQUEST_EMAIL'));
                 if (empty($email_value) || !Validate::isEmail($email_value)) {
                     $output .= $this->displayError($this->l('Please enter valid Email ID'));
                 } else {
                     Configuration::updateValue('PROFIT_MARGIN', $list_value);
                     Configuration::updateValue('PRODUCT_DYNAMIC_PRICE', Tools::getValue('PRODUCT_DYNAMIC_PRICE'));
                     Configuration::updateValue('ORDER_CNF_MANAGER_EMAIL', Tools::getValue('ORDER_CNF_MANAGER_EMAIL'));
                     Configuration::updateValue('ADMIN_CONFIRM_ORDER', Tools::getValue('ADMIN_CONFIRM_ORDER'));
                     Configuration::updateValue('PRODUCT_REQUEST_EMAIL', Tools::getValue('PRODUCT_REQUEST_EMAIL'));
                     Configuration::updateValue('PRODUCT_REQUEST_SAMPLE', Tools::getValue('PRODUCT_REQUEST_SAMPLE'));
                     Configuration::updateValue('PRODUCT_DOWNLOAD_BUTTON', Tools::getValue('PRODUCT_DOWNLOAD_BUTTON'));
                     $output .= $this->displayConfirmation($this->l('Settings updated'));
                 }
             }
         }
     }
     $this->context->controller->addJS($this->_path . 'websitesettings.js');
     //return $this->display(__FILE__,'productupdate.tpl');
     return $output . $this->displayForm();
 }
 public static function isItemsOrder($value)
 {
     $str_error = Tools::displayError('For the items');
     foreach ($value as $key => $item) {
         $str_error .= ' ' . $key . ' ';
         $str_error .= isset($item['name']) ? $item['name'] . ' ' : '';
         $str_error .= ' :';
         if (isset($item['total_ht']) && !Validate::isFloat($item['total_ht'])) {
             throw new TwengaFieldsException($str_error . Tools::displayError('The total HT must be a float value.'));
         }
         if (isset($item['quantity']) && !Validate::isInt($item['quantity'])) {
             throw new TwengaFieldsException($str_error . Tools::displayError('The quantity must be a integer value.'));
         }
         if (isset($item['sku']) && !is_string($item['sku']) && strlen($item['sku']) > 40) {
             throw new TwengaFieldsException($str_error . Tools::displayError('The sku must be a string with length less than 40 chars.'));
         }
         if (isset($item['name']) && !is_string($item['name'])) {
             throw new TwengaFieldsException($str_error . Tools::displayError('The name must be a string with length less than 100 chars.'));
         }
         if (isset($item['category_name']) && !is_string($item['category_name'])) {
             throw new TwengaFieldsException($str_error . Tools::displayError('The category name must be a string with length less than 100 chars.'));
         }
     }
     return true;
 }
 /**
  * Calculate shipping costs without tax
  * @return float Shipping costs
  */
 protected function getShippingCost($products, Currency $currency, $country, $useTax = true)
 {
     $c = $country;
     $id_carrier = (int) Configuration::get('POWATAG_SHIPPING');
     if (!$country instanceof Country) {
         if (Validate::isInt($country)) {
             $country = new Country((int) $country, (int) $this->context->language->id);
         } else {
             $country = $this->getCountryByCode($country);
         }
     }
     if (!PowaTagValidate::countryEnable($country)) {
         $this->addError(sprintf($this->module->l('Country does not exists or is not enabled for this shop : %s'), $country->iso_code), PowaTagErrorType::$MERCHANT_WRONG_COUNTRY);
         return false;
     }
     $shippingCost = $this->getShippingCostByCarrier($products, $currency, $id_carrier, $country, $useTax);
     if (!$shippingCost) {
         $shippingCost = 0.0;
     }
     if (Validate::isFloat($shippingCost)) {
         return $shippingCost;
     } else {
         return false;
     }
 }
 private function validateCSVCODPrice($csv_data)
 {
     $wrong_price = '';
     $wrong_price_method = '';
     $wrong_price_country = '';
     $csv_data_count = count($csv_data);
     for ($i = 0; $i < $csv_data_count; $i++) {
         if (!empty($csv_data[$i][DpdPolandCSV::COLUMN_COD_PRICE])) {
             if (!Validate::isFloat($csv_data[$i][DpdPolandCSV::COLUMN_COD_PRICE]) || $csv_data[$i][DpdPolandCSV::COLUMN_COD_PRICE] < 0) {
                 $wrong_price .= $i + self::DEFAULT_FIRST_LINE_INDEX . ', ';
             } else {
                 if ($csv_data[$i][DpdPolandCSV::COLUMN_CARRIER] != _DPDPOLAND_STANDARD_COD_ID_) {
                     $wrong_price_method .= $i + self::DEFAULT_FIRST_LINE_INDEX . ', ';
                 }
                 if ($csv_data[$i][DpdPolandCSV::COLUMN_COUNTRY] !== self::POLAND_ISO_CODE) {
                     $wrong_price_country .= $i + self::DEFAULT_FIRST_LINE_INDEX . ', ';
                 }
             }
         }
     }
     if (!empty($wrong_price)) {
         $wrong_price = Tools::substr($wrong_price, 0, -2);
     }
     //remove last two symbols (comma & space)
     if (!empty($wrong_price_method)) {
         $wrong_price_method = Tools::substr($wrong_price_method, 0, -2);
     }
     //remove last two symbols (comma & space)
     if (!empty($wrong_price_country)) {
         $wrong_price_country = Tools::substr($wrong_price_country, 0, -2);
     }
     //remove last two symbols (comma & space)
     return empty($wrong_price) && empty($wrong_price_method) && empty($wrong_price_country) ? true : array($wrong_price, $wrong_price_method, $wrong_price_country);
 }
Beispiel #5
0
 /**
  * Data validation for module configuration
  **/
 public function _postValidation()
 {
     $errors = array();
     $method = Tools::getValue('method');
     if ($method == 'signin') {
         if (empty($_POST['login'])) {
             $errors[] = $this->l('login is required.');
         }
         if (empty($_POST['password'])) {
             $errors[] = $this->l('password is required.');
         }
         if (empty($_POST['country'])) {
             $errors[] = $this->l('country is required.');
         }
     } elseif ($method == 'register') {
         if (empty($_POST['login'])) {
             $errors[] = $this->l('login is required.');
         }
         if (empty($_POST['login']) or !Validate::isEmail($_POST['login'])) {
             $errors[] = $this->l('login must be a valid e-mail address.');
         }
         if (empty($_POST['password'])) {
             $errors[] = $this->l('password is required.');
         }
         if (empty($_POST['store_name'])) {
             $errors[] = $this->l('Shop name is required.');
         }
         if (empty($_POST['country'])) {
             $errors[] = $this->l('country is required.');
         }
     } elseif ($method == 'products') {
         $products = array();
         $djlUtil = new DejalaUtils();
         $responseArray = $djlUtil->getStoreProducts($this->dejalaConfig, $products);
         if ('200' != $responseArray['status']) {
             $products = array();
         }
         foreach ($_POST as $key => $value) {
             if (0 === strpos($key, 'margin_')) {
                 $this->mylog("key=" . substr($key, 7));
                 $productID = (int) substr($key, 7);
                 if (is_null($_POST[$key]) || 0 == strlen($_POST[$key])) {
                     $_POST[$key] = 0;
                 }
                 $_POST[$key] = str_replace(',', '.', $_POST[$key]);
                 $_POST[$key] = str_replace(' ', '', $_POST[$key]);
                 if (!Validate::isFloat($_POST[$key])) {
                     $errors[] = $value . ' ' . $this->l('is not a valid margin.');
                 }
                 $margin = (double) $_POST[$key];
                 foreach ($products as $l_product) {
                     if ((int) $l_product['id'] == (int) $productID) {
                         $product = (int) $l_product;
                         break;
                     }
                 }
                 if ($product) {
                     $vat_factor = 1 + $product['vat'] / 100;
                     $public_price = round($product['price'] * $vat_factor, 2);
                     $public_price = round($public_price + $margin, 2);
                     if ($public_price < 0) {
                         $errors[] = $value . ' ' . $this->l('is not a valid margin.');
                     }
                 }
             }
         }
     }
     return $errors;
 }
Beispiel #6
0
 public function hookAdminOrder($params)
 {
     if (Tools::isSubmit('submitPayPalCapture')) {
         if ($capture_amount = Tools::getValue('totalCaptureMoney')) {
             if ($capture_amount = PaypalCapture::parsePrice($capture_amount)) {
                 if (Validate::isFloat($capture_amount)) {
                     $capture_amount = Tools::ps_round($capture_amount, '6');
                     $ord = new Order((int) $params['id_order']);
                     $cpt = new PaypalCapture();
                     if ($capture_amount > Tools::ps_round(0, '6') && Tools::ps_round($cpt->getRestToPaid($ord), '6') >= $capture_amount) {
                         $complete = false;
                         if ($capture_amount > Tools::ps_round((double) $ord->total_paid, '6')) {
                             $capture_amount = Tools::ps_round((double) $ord->total_paid, '6');
                             $complete = true;
                         }
                         if ($capture_amount == Tools::ps_round($cpt->getRestToPaid($ord), '6')) {
                             $complete = true;
                         }
                         $this->_doCapture($params['id_order'], $capture_amount, $complete);
                     }
                 }
             }
         }
     } elseif (Tools::isSubmit('submitPayPalRefund')) {
         $this->_doTotalRefund($params['id_order']);
     }
     $admin_templates = array();
     if ($this->isPayPalAPIAvailable()) {
         if ($this->_needValidation((int) $params['id_order'])) {
             $admin_templates[] = 'validation';
         }
         if ($this->_needCapture((int) $params['id_order'])) {
             $admin_templates[] = 'capture';
         }
         if ($this->_canRefund((int) $params['id_order'])) {
             $admin_templates[] = 'refund';
         }
     }
     if (count($admin_templates) > 0) {
         $order = new Order((int) $params['id_order']);
         $currency = new Currency($order->id_currency);
         $cpt = new PaypalCapture();
         $cpt->id_order = (int) $order->id;
         if (version_compare(_PS_VERSION_, '1.5', '>=')) {
             $order_state = $order->current_state;
         } else {
             $order_state = OrderHistory::getLastOrderState($order->id);
         }
         $this->context->smarty->assign(array('authorization' => (int) Configuration::get('PAYPAL_OS_AUTHORIZATION'), 'base_url' => _PS_BASE_URL_ . __PS_BASE_URI__, 'module_name' => $this->name, 'order_state' => $order_state, 'params' => $params, 'id_currency' => $currency->getSign(), 'rest_to_capture' => Tools::ps_round($cpt->getRestToPaid($order), '6'), 'list_captures' => $cpt->getListCaptured(), 'ps_version' => _PS_VERSION_));
         foreach ($admin_templates as $admin_template) {
             $this->_html .= $this->fetchTemplate('/views/templates/admin/admin_order/' . $admin_template . '.tpl');
             $this->_postProcess();
             $this->_html .= '</fieldset>';
         }
     }
     return $this->_html;
 }
Beispiel #7
0
 /**
  * @return string
  */
 public function getContent()
 {
     $ok = null;
     if (Tools::isSubmit('submitShipping')) {
         $handle = new CSVReader(Tools::getValue("filename"), $_FILES['PINCODE_UPLOAD']['tmp_name']);
         if ($handle->iscsvUpload()) {
             $shipping = Tools::getValue('SHIPPING_METHOD');
             if (isset($shipping) && Validate::isCarrierName((string) $shipping)) {
                 Configuration::updateValue('SHIPPING_METHOD', (string) $shipping);
                 $this->updateCODPincode($handle->getRows(), $shipping);
                 $ok = true;
             } else {
                 $this->_html .= $this->displayError($this->l('Error occurred during Shipping Pincode update'));
             }
         } else {
             $this->_html .= $this->displayError(CSVconst::UPLOAD_ERROR);
         }
     } else {
         if (Tools::isSubmit('submitCOD')) {
             $cod_min = Tools::getValue('COD_MINIMUM_AMOUNT');
             $cod_fee = Tools::getValue('COD_FEE');
             if (isset($cod_min) && isset($cod_fee) && Validate::isFloat((double) $cod_min) && Validate::isFloat((double) $cod_fee)) {
                 Configuration::updateValue('COD_MINIMUM_AMOUNT', (string) $cod_min);
                 Configuration::updateValue('COD_FEE', (string) $cod_fee);
                 $ok = true;
             } else {
                 $this->_html .= $this->displayError($this->l('Error occurred during COD update'));
             }
         }
     }
     if ($ok) {
         $this->_html .= $this->displayConfirmation($this->l('Settings updated succesfully'));
     }
     $this->_html .= $this->renderForm();
     return $this->_html;
 }
 private function postValidation()
 {
     if (Tools::getValue('id_user') == null) {
         $this->post_errors[] = $this->l('ID SO not specified');
     }
     if (Tools::getValue('key') == null) {
         $this->post_errors[] = $this->l('Key SO not specified');
     }
     if (Tools::getValue('dypreparationtime') == null) {
         $this->post_errors[] = $this->l('Preparation time not specified');
     } elseif (!Validate::isInt(Tools::getValue('dypreparationtime'))) {
         $this->post_errors[] = $this->l('Invalid preparation time');
     }
     if (Tools::getValue('overcost') == null) {
         $this->post_errors[] = $this->l('Additional cost not specified');
     } elseif (!Validate::isFloat(Tools::getValue('overcost'))) {
         $this->post_errors[] = $this->l('Invalid additional cost');
     }
 }
 /**
  * Validate fields before exportation
  *
  * @return array errors
  */
 public function validateFields()
 {
     $errors = array();
     foreach ($this->fields as $key => $params) {
         if ($params['mandatory'] == 1 && $params['value']) {
             $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' is mandatory but was not found.');
         }
         switch ($params['type']) {
             case 'string':
                 if ($params['value'] && strlen($params['value']) > $params['length']) {
                     $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' is too long.');
                 }
                 break;
             case 'price':
                 if ($params['value'] && strlen($params['value']) > $params['length']) {
                     $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' is too long.');
                 }
                 if ($params['value'] && !Validate::isPrice($params['value'])) {
                     $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' has a wrong format.');
                 }
                 break;
             case 'float':
                 if ($params['value'] && !Validate::isFloat($params['value'])) {
                     $errors[] = $kiala_instance->l('Field ') . $key . $kiala_instance->l(' has a wrong format.');
                 }
                 break;
             default:
         }
     }
     return $errors;
 }
Beispiel #10
0
 public function getContent()
 {
     $output = null;
     if (Tools::isSubmit('submit' . $this->name)) {
         $mappa_name = strval(Tools::getValue('MAPPA_NAME'));
         $latitude_center_map = floatval(Tools::getValue('MAPPA_LATITUDE_CENTER_MAP'));
         $longitude_center_map = floatval(Tools::getValue('MAPPA_LONGITUDE_CENTER_MAP'));
         $zoom_map = intval(Tools::getValue('MAPPA_ZOOM_MAP'));
         $basemap_name = strval(Tools::getValue('MAPPA_BASEMAP_NAME'));
         if ($mappa_name != strval(Configuration::get('MAPPA_NAME'))) {
             if (!$mappa_name || empty($mappa_name) || !Validate::isGenericName($mappa_name)) {
                 $output .= $this->displayError($this->l('Invalid Configuration value'));
             } else {
                 Configuration::updateValue('MAPPA_NAME', $mappa_name);
                 $output .= $this->displayConfirmation($this->l('Settings updated'));
             }
         }
         if ($latitude_center_map != floatval(Configuration::get('MAPPA_LATITUDE_CENTER_MAP'))) {
             if (!$latitude_center_map || empty($latitude_center_map) || !Validate::isFloat($latitude_center_map) || $latitude_center_map > 90 || $latitude_center_map < -90) {
                 $output .= $this->displayError($this->l('Invalid Latitude value'));
             } else {
                 Configuration::updateValue('MAPPA_LATITUDE_CENTER_MAP', $latitude_center_map);
                 $output .= $this->displayConfirmation($this->l('Map center latitude updated'));
             }
         }
         if ($longitude_center_map != floatval(Configuration::get('MAPPA_LONGITUDE_CENTER_MAP'))) {
             if (!$longitude_center_map || empty($longitude_center_map) || !Validate::isFloat($longitude_center_map) || $longitude_center_map > 180 || $longitude_center_map < -180) {
                 $output .= $this->displayError($this->l('Invalid Longitude value'));
             } else {
                 Configuration::updateValue('MAPPA_LONGITUDE_CENTER_MAP', $longitude_center_map);
                 $output .= $this->displayConfirmation($this->l('Map center longitude updated'));
             }
         }
         if ($zoom_map != intval(Configuration::get('MAPPA_ZOOM_MAP'))) {
             if (!$zoom_map || empty($zoom_map) || !Validate::isInt($zoom_map) || $zoom_map < 0 || $zoom_map > 22) {
                 $output .= $this->displayError($this->l('Invalid Zoom value'));
             } else {
                 Configuration::updateValue('MAPPA_ZOOM_MAP', $zoom_map);
                 $output .= $this->displayConfirmation($this->l('Map zoom level updated'));
             }
         }
         if ($basemap_name != strval(Configuration::get('MAPPA_BASEMAP_NAME'))) {
             Configuration::updateValue('MAPPA_BASEMAP_NAME', $basemap_name);
             $output .= $this->displayConfirmation($this->l('Basemap updated'));
         }
     }
     return $output . $this->displayForm();
 }
 /**
  * \brief	Link a product to an attribute
  * \param	integer Product id
  * \param	array 	Attributes id to link
  * \param	integer Attributes group id
  * \param	string 	Value of the scale in config parameters
  * \param	string 	Fixed dimensions separated by a comma
  * \param	boolean Indicates if there are fixed values to update
  * \param	boolean Indicates if it's a product update
  * \param	integer Default value to display
  * \param	array 	Default values
  * \retval 	boolean Result of the operation
  */
 private function _link_product($product_id, $attributes_id, $group_id, $scale, $fixed_dimensions, &$fixed_update, $update, $default, &$default_values)
 {
     global $cookie;
     $return = true;
     //	Get the scale default value
     $scale_value = $this->_get_scale($scale);
     //	Get the default attribute
     $attribute = Db::getInstance()->getRow('SELECT attribute.* FROM ' . _DB_PREFIX_ . 'attribute as attribute LEFT JOIN ' . _DB_PREFIX_ . 'attribute_lang as lang ON ' . 'lang.id_attribute = attribute.id_attribute WHERE attribute.id_attribute_group = ' . $group_id . ' AND lang.name = "' . $scale_value . '" AND lang.id_lang = ' . (int) $cookie->id_lang);
     //	Create dimensions only if not an update
     if (!$update) {
         //	We add each attribute
         foreach ($attributes_id as $attribute_id) {
             if (!Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute) VALUES (' . $attribute['id_attribute'] . ', ' . $attribute_id['id_product_attribute'] . ')')) {
                 $return = false;
                 break;
             }
         }
     }
     //    Set attribute impact for delayed combinations module
     $impact = (int) Db::getInstance()->getValue('SELECT id_attribute_impact FROM ' . _DB_PREFIX_ . 'attribute_impact WHERE id_product = ' . $product_id . ' AND id_attribute = ' . $attribute['id_attribute']);
     if (!$impact) {
         Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'attribute_impact (id_product, id_attribute, weight, price) VALUES (' . $product_id . ', ' . $attribute['id_attribute'] . ', 0, 0)');
     }
     //	Insert in shops if needed
     $shops_id = array();
     if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) {
         if ((int) Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 1 && (Tools::getIsset('shop_linked') && Tools::getValue('shop_linked'))) {
             $shops_id = array((int) Tools::getValue('shop_linked'));
         } else {
             $shops_id = Db::getInstance()->ExecuteS('SELECT id_shop FROM ' . _DB_PREFIX_ . 'shop WHERE active = 1');
         }
     }
     //	Save fixed dimension if needed
     if ($return && $fixed_dimensions) {
         //	If update, delete fixed dimensions in DB before to add them
         if ($update) {
             Db::getInstance()->Execute('DELETE FROM ' . _DB_PREFIX_ . 'aimultidimensions_fixed_dimensions WHERE fd_product = ' . $product_id . ' AND fd_attribute_group = ' . $attribute['id_attribute_group']);
         }
         $fixed_dimensions = str_replace(', ', ',', $fixed_dimensions);
         $fixed = explode(',', $fixed_dimensions);
         foreach ($fixed as $value) {
             if (Validate::isFloat($value)) {
                 Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'aimultidimensions_fixed_dimensions (fd_product, fd_attribute_group, fd_value) VALUES (' . $product_id . ', ' . $attribute['id_attribute_group'] . ', ' . $value . ')');
             }
             //	Attribut creation if needed
             $attribute_id = (int) Db::getInstance()->getValue('SELECT a.id_attribute FROM ' . _DB_PREFIX_ . 'attribute AS a LEFT JOIN ' . _DB_PREFIX_ . 'attribute_lang AS al ON al.id_attribute = a.id_attribute WHERE ' . 'a.id_attribute_group = ' . $attribute['id_attribute_group'] . ' AND al.name = ' . $value . ' GROUP BY a.id_attribute ORDER BY a.id_attribute DESC');
             if (!$attribute_id) {
                 //	Attribut creation if needed
                 if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) {
                     $position = (int) Attribute::getHigherPosition($group_id);
                     $position++;
                     $request = 'INSERT INTO ' . _DB_PREFIX_ . 'attribute (id_attribute_group, position) VALUES (' . $group_id . ', ' . $position . ')';
                 } else {
                     $request = 'INSERT INTO ' . _DB_PREFIX_ . 'attribute (id_attribute_group) VALUES (' . $group_id . ')';
                 }
                 if (Db::getInstance()->Execute($request)) {
                     $attribute_id = Db::getInstance()->Insert_ID();
                     //	Attribute lang creation if needed
                     for ($cpt = 1; $cpt < 6; $cpt++) {
                         Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'attribute_lang (`id_attribute`, `id_lang`, `name`) VALUES (' . $attribute_id . ', ' . $cpt . ', ' . $value . ')');
                     }
                     //	Add for Prestashop 1.5 version and above
                     if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) {
                         foreach ($shops_id as $shop_id) {
                             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'attribute_shop (id_attribute, id_shop) VALUES (' . $attribute_id . ', ' . (int) $shop_id['id_shop'] . ')');
                         }
                     }
                 }
             }
         }
     }
     //	Save default dimensions
     $default_dimension = Db::getInstance()->getRow('SELECT al.name, al.id_attribute FROM ' . _DB_PREFIX_ . 'attribute_lang AS al LEFT JOIN ' . _DB_PREFIX_ . 'attribute AS a ON a.id_attribute = al.id_attribute WHERE ' . 'a.id_attribute_group = ' . $group_id . ' AND al.id_lang = ' . (int) $cookie->id_lang . ' ORDER BY a.id_attribute ASC');
     if ($default != (int) $default_dimension['name']) {
         //	Attribut creation if needed
         $attribute_id = (int) Db::getInstance()->getValue('SELECT a.id_attribute FROM ' . _DB_PREFIX_ . 'attribute AS a LEFT JOIN ' . _DB_PREFIX_ . 'attribute_lang AS al ON al.id_attribute = a.id_attribute WHERE ' . 'a.id_attribute_group = ' . $group_id . ' AND al.name = ' . $default . ' GROUP BY a.id_attribute ORDER BY a.id_attribute DESC');
         if (!$attribute_id) {
             if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) {
                 $position = (int) Attribute::getHigherPosition($group_id);
                 $position++;
                 $request = 'INSERT INTO ' . _DB_PREFIX_ . 'attribute (id_attribute_group, position) VALUES (' . $group_id . ', ' . $position . ')';
             } else {
                 $request = 'INSERT INTO ' . _DB_PREFIX_ . 'attribute (id_attribute_group) VALUES (' . $group_id . ')';
             }
             if (Db::getInstance()->Execute($request)) {
                 $attribute_id = Db::getInstance()->Insert_ID();
                 //	Attribute lang creation if needed
                 for ($cpt = 1; $cpt < 6; $cpt++) {
                     Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'attribute_lang (`id_attribute`, `id_lang`, `name`) VALUES (' . $attribute_id . ', ' . $cpt . ', ' . $default . ')');
                 }
                 //	Add for Prestashop 1.5 version and above
                 if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) {
                     foreach ($shops_id as $shop_id) {
                         Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'attribute_shop (id_attribute, id_shop) VALUES (' . $attribute_id . ', ' . (int) $shop_id['id_shop'] . ')');
                     }
                 }
             }
         }
         $default_values[$group_id] = array($attribute_id, $default);
         $default_values[0] = 1;
     } else {
         $default_values[$group_id] = array((int) $default_dimension['id_attribute'], (int) $default_dimension['name']);
     }
     //	If fixed dimensions have only one value, make it default one
     if (isset($fixed) && count($fixed) == 1) {
         $fixed_update = true;
     }
     return $return;
 }
Beispiel #12
0
    private function postprocess()
    {
        $sufixe = (int) Configuration::get('JC-EANUPC-gs1') ? (int) Configuration::get('JC-EANUPC-gs1') : '200';
        if (Tools::isSubmit('submitParam')) {
            if (!Configuration::updateValue('JC-EANUPC-EAN', (int) Tools::getValue('bean')) || !Configuration::updateValue('JC-EANUPC-UPC', (int) Tools::getValue('bupc')) || !Configuration::updateValue('JC-EANUPC-gs1', (int) Tools::getValue('gs1'))) {
                $this->posterrors[] = $this->l('Cannot update settings');
            }
            // validate fields
            if (!Validate::isInt(Tools::getValue('font_size'))) {
                $this->posterrors[] = $this->l('font_size required and shoud be numeric.');
            }
            if (!Validate::isInt(Tools::getValue('margin_top'))) {
                $this->posterrors[] = $this->l('Margin top required and shoud be numeric.');
            }
            if (!Validate::isInt(Tools::getValue('margin_bottom'))) {
                $this->posterrors[] = $this->l('Margin bottom required and shoud be numeric.');
            }
            if (!Validate::isInt(Tools::getValue('margin_left'))) {
                $this->posterrors[] = $this->l('Margin left required and shoud be numeric.');
            }
            if (!Validate::isInt(Tools::getValue('margin_right'))) {
                $this->posterrors[] = $this->l('Margin right required and shoud be numeric.');
            }
            if (!Validate::isFloat(Tools::getValue('barheight'))) {
                $this->posterrors[] = $this->l('Barcode Height required and shoud be numeric.');
            }
            if (!Validate::isFloat(Tools::getValue('blocheight'))) {
                $this->posterrors[] = $this->l('block Height required and shoud be numeric.');
            }
            if (!Validate::isInt(Tools::getValue('blockborder'))) {
                $this->posterrors[] = $this->l('block blockborder required and shoud be numeric.');
            }
            if (!Validate::isFloat(Tools::getValue('barwidth'))) {
                $this->posterrors[] = $this->l('Width required and shoud be numeric.');
            }
            if (!Validate::isFloat(Tools::getValue('blocwidth'))) {
                $this->posterrors[] = $this->l('block Width required and shoud be numeric.');
            }
            if (!Validate::isColor(Tools::getValue('color'))) {
                $this->posterrors[] = $this->l('Color required and shoud be numeric.');
            }
            // if (!Validate::isInt('stretch'))
            // $this->posterrors[] = $this->l('Stretch no valid.');
            // if (!Tools::getValue('unitmeasure'))
            // $this->posterrors[] = $this->l('Unit of measure.');
            // if (!Validate::isInt('setborder'))
            // $this->posterrors[] = $this->l('Set border no valid.');
            if (!count($this->posterrors)) {
                Configuration::updateValue('JC-EANUPC-font_size', (int) Tools::getValue('font_size'));
                Configuration::updateValue('JC-EANUPC-margin_top', (int) Tools::getValue('margin_top'));
                Configuration::updateValue('JC-EANUPC-margin_bottom', (int) Tools::getValue('margin_bottom'));
                Configuration::updateValue('JC-EANUPC-margin_left', (int) Tools::getValue('margin_left'));
                Configuration::updateValue('JC-EANUPC-margin_right', (int) Tools::getValue('margin_right'));
                Configuration::updateValue('JC-EANUPC-barheight', (double) Tools::getValue('barheight'));
                Configuration::updateValue('JC-EANUPC-blocheight', (double) Tools::getValue('blocheight'));
                Configuration::updateValue('JC-EANUPC-blockborder', (int) Tools::getValue('blockborder'));
                Configuration::updateValue('JC-EANUPC-barwidth', (double) Tools::getValue('barwidth'));
                Configuration::updateValue('JC-EANUPC-blocwidth', (double) Tools::getValue('blocwidth'));
                Configuration::updateValue('JC-EANUPC-color', Tools::getValue('color'));
                Configuration::updateValue('JC-EANUPC-stretch', (int) Tools::getValue('stretch'));
                Configuration::updateValue('JC-EANUPC-unitmeasure', Tools::getValue('unitmeasure'));
                Configuration::updateValue('JC-EANUPC-setborder', Tools::getValue('setborder'));
                Configuration::updateValue('JC-EANUPC-productname', (int) Tools::getValue('productname'));
                Configuration::updateValue('JC-EANUPC-productref', (int) Tools::getValue('productref'));
                Configuration::updateValue('JC-EANUPC-truncateproductname', (int) Tools::getValue('truncateproductname'));
                Configuration::updateValue('JC-EANUPC-productprice', (int) Tools::getValue('productprice'));
                Configuration::updateValue('JC-EANUPC-usereduction', (int) Tools::getValue('usereduction'));
                $this->html .= '<div class="bootstrapalert-success conf confirm">' . $this->l('Settings updated') . '</div>';
            } else {
                foreach ($this->posterrors as $err) {
                    $this->html .= '<div class="alert-error error">' . $err . '</div>';
                }
            }
        } elseif (Tools::isSubmit('submitUpdate')) {
            $sqlWhere = '';
            $categorie_generate_id = Tools::getValue('categorie_generate_id');
            if ($categorie_generate_id != 0) {
                $sqlWhere = "AND id_category_default = '" . $categorie_generate_id . "'";
            }
            $this->refreshproperties();
            $this->html .= '<div class="bootstrapalert-success conf confirm">' . $this->l('Missing codes generated') . '</div>';
            if (Tools::getValue('typeTogenerate') == 'EAN13' || Tools::getValue('typeTogenerate') == 0) {
                $products_to_update_code = Db::getInstance()->ExecuteS('SELECT `id_product` FROM ' . _DB_PREFIX_ . 'product
				WHERE (ean13 IS NULL OR ean13 = "" OR ean13 = "0")' . $sqlWhere);
                foreach ($products_to_update_code as $product) {
                    $ean13 = '';
                    $ean13 = $this->generateEAN($product['id_product'], $sufixe);
                    Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product SET ean13 = "' . $ean13 . '" WHERE id_product = ' . (int) $product['id_product']);
                }
                $products_attr_to_update_code = Db::getInstance()->ExecuteS('SELECT `id_product`,`id_product_attribute`
				FROM ' . _DB_PREFIX_ . 'product_attribute WHERE ean13 IS NULL OR ean13 = "" OR ean13 = "0"');
                foreach ($products_attr_to_update_code as $product_attr) {
                    $ean13 = '';
                    $ean13 = $this->generateEAN($product_attr['id_product'] . $product_attr['id_product_attribute'], $sufixe);
                    Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product_attribute SET ean13 = "' . $ean13 . '" WHERE
					id_product_attribute =' . $product_attr['id_product_attribute']);
                }
            }
            if (Tools::getValue('typeTogenerate') == 'UPC' || Tools::getValue('typeTogenerate') == 0) {
                $products_to_update_code = Db::getInstance()->ExecuteS('SELECT `id_product` FROM ' . _DB_PREFIX_ . 'product WHERE
				(upc IS NULL OR upc = "" OR upc = "0") ' . $sqlWhere);
                foreach ($products_to_update_code as $product) {
                    $upc = '';
                    $upc = $this->generateEAN($product['id_product'], $sufixe, 'upc');
                    Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product SET upc = "' . $upc . '" WHERE id_product =' . (int) $product['id_product']);
                }
                $products_attr_to_update_code = Db::getInstance()->ExecuteS('SELECT `id_product`,`id_product_attribute` FROM ' . _DB_PREFIX_ . 'product_attribute
				WHERE upc IS NULL OR upc = "" OR upc = "0"');
                foreach ($products_attr_to_update_code as $product_attr) {
                    $upc = '';
                    $upc = $this->generateEAN($product_attr['id_product'] . $product_attr['id_product_attribute'], $sufixe, 'upc');
                    Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'product_attribute SET upc = "' . $upc . '" WHERE
					id_product_attribute =' . $product_attr['id_product_attribute']);
                }
            }
        } elseif (Tools::isSubmit('submitPrint')) {
            $margin = array();
            $printformat = Tools::getValue('printformat');
            $nbproduct = (int) Tools::getValue('nbproduct');
            $printformatw = (int) Tools::getValue('customprintformatwidth');
            $printformath = (int) Tools::getValue('customprintformatheight');
            if ($printformatw && $printformath) {
                $printformat = array($printformath, $printformatw);
            }
            $type = Tools::getValue('type');
            $categorie_id = Tools::getValue('categorie_id');
            $manufacturer_id = Tools::getValue('manufacturer_id');
            $products = array();
            $products = Tools::getValue('product_id');
            $declinaisons = Tools::getValue('declinaisons_id');
            $orientation = Tools::getValue('orientation');
            $unitmeasure = Configuration::get('JC-EANUPC-unitmeasure');
            $font_size = Configuration::get('JC-EANUPC-font_size');
            $color = Configuration::get('JC-EANUPC-color');
            $margin['top'] = Configuration::get('JC-EANUPC-margin_top');
            $margin['left'] = Configuration::get('JC-EANUPC-margin_left');
            $margin['right'] = Configuration::get('JC-EANUPC-margin_right');
            $margin['bottom'] = Configuration::get('JC-EANUPC-margin_bottom');
            $barheight = Configuration::get('JC-EANUPC-barheight');
            $barwidth = Configuration::get('JC-EANUPC-barwidth');
            $blocheight = Configuration::get('JC-EANUPC-blocheight');
            $blocwidth = Configuration::get('JC-EANUPC-blocwidth');
            $blockborder = Configuration::get('JC-EANUPC-blockborder');
            $stretch = Configuration::get('JC-EANUPC-stretch');
            $setborder = Configuration::get('JC-EANUPC-setborder');
            $showname = Configuration::get('JC-EANUPC-productname');
            $showprice = Configuration::get('JC-EANUPC-productprice');
            $showref = Configuration::get('JC-EANUPC-productref');
            // render pdf
            if (!count($this->posterrors)) {
                $this->printPDF($type, $categorie_id, $products, $declinaisons, $unitmeasure, $orientation, $font_size, $color, $margin, $barheight, $barwidth, $blocheight, $blocwidth, $blockborder, $printformat, $stretch, $setborder, $showname, $showref, $showprice, $nbproduct, $manufacturer_id);
            } else {
                foreach ($this->posterrors as $err) {
                    $this->html .= '<div class="bootstrapalert-error">' . $err . '</div>';
                }
            }
        }
        $this->refreshproperties();
    }
 /**
  * get SQL retrieve Filter
  * 
  * @param string $sqlId
  * @param string $filterValue
  * @param string $tableAlias = 'main.'
  * @return string
  */
 protected function getSQLRetrieveFilter($sqlId, $filterValue, $tableAlias = 'main.')
 {
     $ret = '';
     // "LIKE" case (=%[foo]%, =%[foo], =[foo]%)
     preg_match('/^(.*)\\[(.*)\\](.*)$/', $filterValue, $matches);
     if (count($matches) > 1) {
         if ($matches[1] == '%' || $matches[3] == '%') {
             $ret .= ' AND ' . $tableAlias . '`' . pSQL($sqlId) . '` LIKE "' . $matches[1] . pSQL($matches[2]) . $matches[3] . "\"\n";
         } elseif ($matches[1] == '' && $matches[3] == '') {
             // "OR" case
             if (strpos($matches[2], '|') > 0) {
                 $values = explode('|', $matches[2]);
                 $ret .= ' AND (';
                 $temp = '';
                 foreach ($values as $value) {
                     $temp .= $tableAlias . '`' . pSQL($sqlId) . '` = "' . pSQL($value) . '" OR ';
                 }
                 // AND (field = value3 OR field = value7 OR field = value9)
                 $ret .= rtrim($temp, 'OR ') . ')' . "\n";
             } elseif (preg_match('/^([\\d\\.:-\\s]+),([\\d\\.:-\\s]+)$/', $matches[2], $matches3)) {
                 unset($matches3[0]);
                 if (count($matches3) > 0) {
                     sort($matches3);
                     $ret .= ' AND ' . $tableAlias . '`' . pSQL($sqlId) . '` BETWEEN "' . $matches3[0] . '" AND "' . $matches3[1] . "\"\n";
                     // AND field BETWEEN value3 AND value4
                 }
             } else {
                 $ret .= ' AND ' . $tableAlias . '`' . pSQL($sqlId) . '`="' . $matches[2] . '"' . "\n";
             }
             // AND field = value1
         } elseif ($matches[1] == '>') {
             $ret .= ' AND ' . $tableAlias . '`' . pSQL($sqlId) . '` > "' . pSQL($matches[2]) . "\"\n";
         } elseif ($matches[1] == '<') {
             $ret .= ' AND ' . $tableAlias . '`' . pSQL($sqlId) . '` < "' . pSQL($matches[2]) . "\"\n";
         } elseif ($matches[1] == '!') {
             $ret .= ' AND ' . $tableAlias . '`' . pSQL($sqlId) . '` != "' . pSQL($matches[2]) . "\"\n";
         }
         // AND field IS NOT value3
     } else {
         $ret .= ' AND ' . $tableAlias . '`' . pSQL($sqlId) . '` ' . (Validate::isFloat(pSQL($filterValue)) ? 'LIKE' : '=') . ' "' . pSQL($filterValue) . "\"\n";
     }
     return $ret;
 }
Beispiel #14
0
 private function postValidation()
 {
     if (Tools::getValue('id_user') == null) {
         $this->post_errors[] = $this->l('ID SO not specified');
     }
     if (Tools::getValue('key') == null) {
         $this->post_errors[] = $this->l('Key SO not specified');
     }
     if (Tools::getValue('dypreparationtime') == null) {
         $this->post_errors[] = $this->l('Preparation time not specified');
     } elseif (!Validate::isInt(Tools::getValue('dypreparationtime'))) {
         $this->post_errors[] = $this->l('Invalid preparation time');
     }
     if (Tools::getValue('overcost') == null) {
         $this->post_errors[] = $this->l('Additional cost not specified');
     } elseif (!Validate::isFloat(Tools::getValue('overcost'))) {
         $this->post_errors[] = $this->l('Invalid additional cost');
     }
     if ((int) Tools::getValue('id_socolissimo_allocation') == (int) Tools::getValue('id_socolissimocc_allocation')) {
         $this->post_errors[] = $this->l('Socolissimo carrier cannot be the same as socolissimo CC');
     }
 }
 private function validateSettings()
 {
     if (!Tools::getValue(DpdGroupConfiguration::COUNTRY)) {
         self::$errors[] = $this->l('DPD Country can not be empty');
     }
     if (!Tools::getValue(DpdGroupConfiguration::SENDER_ID)) {
         self::$errors[] = $this->l('Sender Address Id can not be empty');
     }
     if (!Tools::getValue(DpdGroupConfiguration::PAYER_ID)) {
         self::$errors[] = $this->l('Payer Id can not be empty');
     }
     if (!Tools::getValue(DpdGroupConfiguration::USERNAME)) {
         self::$errors[] = $this->l('Web Service Username can not be empty');
     }
     if (!Tools::getValue(DpdGroupConfiguration::PASSWORD)) {
         self::$errors[] = $this->l('Web Service Password can not be empty');
     }
     if (Tools::getValue(DpdGroupConfiguration::COUNTRY) == DpdGroupConfiguration::OTHER_COUNTRY && !Tools::getValue(DpdGroupConfiguration::PRODUCTION_URL) && !Tools::getValue(DpdGroupConfiguration::TEST_URL)) {
         self::$errors[] = $this->l('At least one WS URL must be entered');
     }
     if (Tools::getValue(DpdGroupConfiguration::PRODUCTION_URL) !== '' && !Validate::isUrl(Tools::getValue(DpdGroupConfiguration::PRODUCTION_URL))) {
         self::$errors[] = $this->l('Production WS URL is not valid');
     }
     if (Tools::getValue(DpdGroupConfiguration::TEST_URL) !== '' && !Validate::isUrl(Tools::getValue(DpdGroupConfiguration::TEST_URL))) {
         self::$errors[] = $this->l('Test WS URL is not valid');
     }
     if (Tools::getValue(DpdGroupConfiguration::PASSWORD) !== '' && !Validate::isPasswd(Tools::getValue(DpdGroupConfiguration::PASSWORD))) {
         self::$errors[] = $this->l('Web Service Password is not valid');
     }
     if (Tools::getValue(DpdGroupConfiguration::TIMEOUT) !== '' && !Validate::isUnsignedInt(Tools::getValue(DpdGroupConfiguration::TIMEOUT))) {
         self::$errors[] = $this->l('Web Service Connection Timeout is not valid');
     }
     if (!Tools::getValue(DpdGroupConfiguration::WEIGHT_CONVERSATION_RATE)) {
         self::$errors[] = $this->l('Weight conversation rate can not be empty');
     } elseif (!Validate::isFloat(Tools::getValue(DpdGroupConfiguration::WEIGHT_CONVERSATION_RATE)) || Validate::isFloat(Tools::getValue(DpdGroupConfiguration::WEIGHT_CONVERSATION_RATE)) && Tools::getValue(DpdGroupConfiguration::WEIGHT_CONVERSATION_RATE) < 0) {
         self::$errors[] = $this->l('Weight conversation rate is not valid');
     }
     $this->validateCODMethods();
 }
 private function _postValidation()
 {
     if (Tools::getValue('id_user') == NULL) {
         $this->_postErrors[] = $this->l('ID SO not specified');
     }
     if (Tools::getValue('key') == NULL) {
         $this->_postErrors[] = $this->l('Key SO not specified');
     }
     if (Tools::getValue('dypreparationtime') == NULL) {
         $this->_postErrors[] = $this->l('Preparation time not specified');
     } elseif (!Validate::isInt(Tools::getValue('dypreparationtime'))) {
         $this->_postErrors[] = $this->l('Invalid preparation time');
     }
     if (Tools::getValue('overcost') == NULL) {
         $this->_postErrors[] = $this->l('Overcost not specified');
     } elseif (!Validate::isFloat(Tools::getValue('overcost'))) {
         $this->_postErrors[] = $this->l('Invalid overcost');
     }
 }
Beispiel #17
0
 /**
  * Check for an percentage validity (between 0 and 100)
  *
  * @param float $value Float to validate
  * @return boolean Validity is ok or not
  */
 public static function isPercentage($value)
 {
     return Validate::isFloat($value) && $value >= 0 && $value <= 100;
 }
 public function handleConfirm($update = false)
 {
     global $currentIndex, $cookie, $smarty;
     $products_to_import = array();
     $defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
     $file_path = Tools::getValue('current_file');
     $overwrite_imgs = Tools::getValue("overwrite_imgs");
     //$file_path = '/Users/rohit/webroot/indusdiva/admin12/product-uploads/upload_sheet_1.csv';
     $f = fopen($file_path, 'r');
     $file_error = false;
     if ($f) {
         //discard header
         $line = fgetcsv($f);
         while ($line = fgetcsv($f)) {
             //ignore empty lines
             if (empty($line)) {
                 continue;
             }
             //trim data
             foreach ($line as $key => $value) {
                 $line[$key] = trim($value);
             }
             $id_product = $line[0];
             $images = $line[1];
             $product_name = $line[2];
             $fabric = $line[3];
             $color = $line[4];
             $mrp = $line[5];
             $supplier_code = $line[6];
             $reference = $line[7];
             $location = $line[8];
             $length = $line[9];
             $width = $line[10];
             $blouse_length = $line[11];
             $garment_type = $line[12];
             $work_type = $line[13];
             $weight = $line[14];
             $description = $line[15];
             $other_info = $line[16];
             $wash_care = $line[17];
             $shipping_estimate = $line[18];
             $supplier_price = $line[19];
             $manufacturer = $line[20];
             $categories = explode(",", $line[21]);
             $tax_rule = $line[22];
             $quantity = $line[23];
             $active = $line[24];
             $discount = $line[25];
             $tags = $line[26];
             $kameez_style = $line[27];
             $salwar_style = $line[28];
             $sleeves = $line[29];
             $customizable = $line[30];
             $generic_color = $line[31];
             $skirt_length = $line[32];
             $dupatta_length = $line[33];
             $stone = $line[34];
             $plating = $line[35];
             $material = $line[36];
             $dimensions = $line[37];
             $look = $line[38];
             $as_shown = isset($line[39]) && !empty($line[39]) ? intval($line[39]) : 0;
             $id_sizechart = isset($line[40]) && !empty($line[40]) ? intval($line[40]) : 0;
             $is_exclusive = isset($line[41]) && !empty($line[41]) ? intval($line[41]) : 0;
             $handbag_occasion = isset($line[42]) && !empty($line[42]) ? $line[42] : null;
             $handbag_style = isset($line[43]) && !empty($line[43]) ? $line[43] : null;
             $handbag_material = isset($line[44]) && !empty($line[44]) ? $line[44] : null;
             $images = explode(",", $images);
             $error = false;
             //validate fields
             if (!Validate::isFloat($mrp)) {
                 $error = 'MRP should be a number: ' . trim($reference);
             } elseif (!Validate::isFloat($supplier_price)) {
                 $error = 'Supplier Price should be a number: ' . trim($reference);
             }
             $importCategories = array();
             if (is_array($categories)) {
                 $categories = array_unique($categories);
                 foreach ($categories as $category) {
                     $category = intval(trim($category));
                     if (empty($category)) {
                         continue;
                     }
                     if (!is_numeric($category) || !Category::categoryExists($category)) {
                         $error = 'Category does not exist: ' . $category;
                     }
                     $importCategories[] = $category;
                 }
             } else {
                 $error = 'Atleast one category required: ' . trim($reference);
             }
             if (!Validate::isFloat($weight)) {
                 $error = 'Weight has to be a number: ' . trim($reference);
             }
             if (!empty($manufacturer) && (!is_numeric($manufacturer) || !Manufacturer::manufacturerExists((int) $manufacturer))) {
                 $error = 'Manufacturer does not exist';
             }
             if ($quantity && !is_numeric($quantity) || $discount && !is_numeric($discount)) {
                 $error = 'Quantity and discount should be numbers: ' . trim($reference);
             }
             if (!Validate::isLoadedObject(new TaxRulesGroup($tax_rule))) {
                 $error = 'Tax rate invalid: ' . trim($reference);
             }
             if (!$update) {
                 $sql = "SELECT `reference`\n\t\t\t\t\t\t\tFROM " . _DB_PREFIX_ . "product p\n\t\t\t\t\t\t\tWHERE p.`reference` = '" . $reference . "'";
                 $row = Db::getInstance()->getRow($sql);
                 if (isset($row['reference'])) {
                     $error = "Duplicate indusdiva code : " . trim($reference);
                 }
             }
             //check for souring price
             if ($supplier_price > $mrp / 1.2) {
                 $error = "MRP too low : " . trim($reference);
             }
             //check for images
             if (!$update || $overwrite_imgs == "on") {
                 foreach ($images as $image_name) {
                     $image_name = trim($image_name);
                     $image_path = IMAGE_UPLOAD_PATH . $image_name;
                     if (!empty($image_name) && !file_exists($image_path)) {
                         $error = "Image not found for: " . trim($reference) . ", Image Name: " . $image_name;
                         break;
                     }
                 }
             }
             $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;
                 $product->generic_color = $generic_color;
                 $product->garment_type = $garment_type;
                 $product->work_type = $work_type;
                 $product->blouse_length = $blouse_length ? $blouse_length : ' ';
                 $product->wash_care = $wash_care ? $wash_care : ' ';
                 $product->other_info = $other_info ? $other_info : ' ';
                 $product->shipping_estimate = $shipping_estimate ? $shipping_estimate : ' ';
                 $product->is_customizable = $customizable == 1 ? 1 : 0;
                 $product->kameez_style = $kameez_style;
                 $product->salwar_style = $salwar_style;
                 $product->sleeves = $sleeves;
                 $product->skirt_length = $skirt_length;
                 $product->dupatta_length = $dupatta_length;
                 $product->stone = $stone;
                 $product->plating = $plating;
                 $product->material = $material;
                 $product->dimensions = $dimensions;
                 $product->look = $look;
                 $product->as_shown = $as_shown;
                 $product->id_sizechart = $id_sizechart;
                 $product->is_exclusive = $is_exclusive;
                 $product->handbag_occasion = $handbag_occasion;
                 $product->handbag_style = $handbag_style;
                 $product->handbag_material = $handbag_material;
                 $product->indexed = 0;
                 $products_to_import[] = $product;
             } else {
                 $smarty->assign('error', $error);
                 return;
                 $file_error = true;
             }
         }
         if (!$file_error) {
             $added_product_ids = array();
             foreach ($products_to_import as $product) {
                 $fieldError = $product->validateFields(UNFRIENDLY_ERROR, true);
                 $langFieldError = $product->validateFieldsLang(UNFRIENDLY_ERROR, true);
                 if ($fieldError === true and $langFieldError === true) {
                     // check quantity
                     if ($product->quantity == NULL) {
                         $product->quantity = 0;
                     }
                     // If no id_product or update failed
                     if ($update && $product->id) {
                         $res = $product->update();
                     } else {
                         $res = $product->add();
                     }
                     $added_product_ids[] = $product->id;
                 }
                 if (isset($product->discount) && $product->discount > 0) {
                     SpecificPrice::deleteByProductId((int) $product->id);
                     $specificPrice = new SpecificPrice();
                     $specificPrice->id_product = (int) $product->id;
                     $specificPrice->id_shop = (int) Shop::getCurrentShop();
                     $specificPrice->id_currency = 0;
                     $specificPrice->id_country = 0;
                     $specificPrice->id_group = 0;
                     $specificPrice->from_quantity = 1;
                     $specificPrice->reduction = $product->discount / 100;
                     $specificPrice->reduction_type = 'percentage';
                     $specificPrice->from = '2012-01-01 00:00:00';
                     $specificPrice->to = '2016-01-01 00:00:00';
                     $specificPrice->price = $product->price;
                     $specificPrice->add();
                 }
                 if (isset($product->tags) and !empty($product->tags)) {
                     // Delete tags for this id product, for no duplicating error
                     Tag::deleteTagsForProduct($product->id);
                     $tag = new Tag();
                     $tag->addTags($defaultLanguageId, $product->id, $tags);
                 }
                 if (isset($product->images) and is_array($product->images) and sizeof($product->images) and !$update || $overwrite_imgs == "on") {
                     $product->deleteImages();
                     $first_image = true;
                     foreach ($product->images as $image_name) {
                         $image_name = trim($image_name);
                         $image_path = IMAGE_UPLOAD_PATH . $image_name;
                         if (!empty($image_name)) {
                             $image = new Image();
                             $image->id_product = (int) $product->id;
                             $image->position = Image::getHighestPosition($product->id) + 1;
                             $image->cover = $first_image;
                             $image->legend[$defaultLanguageId] = $product->name[$defaultLanguageId];
                             if (($fieldError = $image->validateFields(false, true)) === true and ($langFieldError = $image->validateFieldsLang(false, true)) === true and $image->add()) {
                                 if (!self::copyImg($product->id, $image->id, $image_path)) {
                                     $_warnings[] = Tools::displayError('Error copying image: ') . $image_path;
                                 } else {
                                     //delete the original image
                                     @unlink($image_path);
                                 }
                             } else {
                                 $_warnings[] = $image->legend[$defaultLanguageId] . (isset($image->id_product) ? ' (' . $image->id_product . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                                 $_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                             }
                         }
                         $first_image = false;
                     }
                 }
                 if (isset($product->id_category)) {
                     $product->updateCategories(array_map('intval', $product->id_category));
                 }
                 $this->addFeature($product->id, 'fabric', $product->fabric);
                 $this->addFeature($product->id, 'color', $product->color);
                 $this->addFeature($product->id, 'garment_type', $product->garment_type);
                 $this->addFeature($product->id, 'work_type', $product->work_type);
                 $this->addFeature($product->id, 'blouse_length', $product->blouse_length);
                 $this->addFeature($product->id, 'wash_care', $product->wash_care);
                 $this->addFeature($product->id, 'other_info', $product->other_info);
                 // to avoid type errors in the catalog sheet - construct the string here again
                 $shipping_sla = (int) preg_replace('/\\D/', '', $product->shipping_estimate);
                 $shipping_estimate_str = "";
                 if ($shipping_sla > 0) {
                     $shipping_estimate_str = $shipping_sla === 1 ? "Ready to be shipped in 1 day" : "Ready to be shipped in {$shipping_sla} days";
                 }
                 $this->addFeature($product->id, 'shipping_estimate', $shipping_estimate_str);
                 $this->addFeature($product->id, 'kameez_style', $product->kameez_style);
                 $this->addFeature($product->id, 'salwar_style', $product->salwar_style);
                 $this->addFeature($product->id, 'sleeves', $product->sleeves);
                 $this->addFeature($product->id, 'generic_color', $product->generic_color);
                 $this->addFeature($product->id, 'skirt_length', $product->skirt_length);
                 $this->addFeature($product->id, 'dupatta_length', $product->dupatta_length);
                 $this->addFeature($product->id, 'stone', $product->stone);
                 $this->addFeature($product->id, 'plating', $product->plating);
                 $this->addFeature($product->id, 'material', $product->material);
                 $this->addFeature($product->id, 'dimensions', $product->dimensions);
                 $this->addFeature($product->id, 'look', $product->look);
                 $this->addFeature($product->id, 'handbag_occasion', $product->handbag_occasion);
                 $this->addFeature($product->id, 'handbag_style', $product->handbag_style);
                 $this->addFeature($product->id, 'handbag_material', $product->handbag_material);
             }
             $smarty->assign("products_affected", $products_to_import);
             //reindex the products
             SolrSearch::updateProducts($added_product_ids);
             $smarty->assign("is_update", $update);
         } else {
             $smarty->assign('file_error', 1);
         }
     } else {
         $smarty->assign('error_reading', 1);
     }
 }
Beispiel #19
0
 /**
  * get SQL retrieve Filter
  *
  * @param string $sqlId
  * @param string $filterValue
  * @param string $tableAlias = 'main.'
  * @return string
  */
 protected function getSQLRetrieveFilter($sqlId, $filterValue, $tableAlias = 'main.')
 {
     $ret = '';
     preg_match('/^(.*)\\[(.*)\\](.*)$/', $filterValue, $matches);
     if (count($matches) > 1) {
         if ($matches[1] == '%' || $matches[3] == '%') {
             $ret .= ' AND ' . bqSQL($tableAlias) . '`' . bqSQL($sqlId) . '` LIKE "' . pSQL($matches[1] . $matches[2] . $matches[3]) . "\"\n";
         } elseif ($matches[1] == '' && $matches[3] == '') {
             if (strpos($matches[2], '|') > 0) {
                 $values = explode('|', $matches[2]);
                 $ret .= ' AND (';
                 $temp = '';
                 foreach ($values as $value) {
                     $temp .= bqSQL($tableAlias) . '`' . bqSQL($sqlId) . '` = "' . bqSQL($value) . '" OR ';
                 }
                 $ret .= rtrim($temp, 'OR ') . ')' . "\n";
             } elseif (preg_match('/^([\\d\\.:-\\s]+),([\\d\\.:-\\s]+)$/', $matches[2], $matches3)) {
                 unset($matches3[0]);
                 if (count($matches3) > 0) {
                     sort($matches3);
                     $ret .= ' AND ' . $tableAlias . '`' . bqSQL($sqlId) . '` BETWEEN "' . pSQL($matches3[0]) . '" AND "' . pSQL($matches3[1]) . "\"\n";
                 }
             } else {
                 $ret .= ' AND ' . $tableAlias . '`' . bqSQL($sqlId) . '`="' . pSQL($matches[2]) . '"' . "\n";
             }
         } elseif ($matches[1] == '>') {
             $ret .= ' AND ' . $tableAlias . '`' . bqSQL($sqlId) . '` > "' . pSQL($matches[2]) . "\"\n";
         } elseif ($matches[1] == '<') {
             $ret .= ' AND ' . $tableAlias . '`' . bqSQL($sqlId) . '` < "' . pSQL($matches[2]) . "\"\n";
         } elseif ($matches[1] == '!') {
             $ret .= ' AND ' . $tableAlias . '`' . bqSQL($sqlId) . '` != "' . pSQL($matches[2]) . "\"\n";
         }
     } else {
         $ret .= ' AND ' . $tableAlias . '`' . bqSQL($sqlId) . '` ' . (Validate::isFloat(pSQL($filterValue)) ? 'LIKE' : '=') . ' "' . pSQL($filterValue) . "\"\n";
     }
     return $ret;
 }
Beispiel #20
0
     }
 }
 if (Tools::isSubmit('submitAddBlock') && $nb < LOF_MODULE_ADVFOOTER_LIMIT_BLOCK) {
     $titles = array();
     foreach ($module->_languages as $language) {
         $titles[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']);
     }
     if (!Tools::getValue('title_' . $module->_defaultFormLanguage)) {
         $errors[] = $module->l('the field Title is required at least in ' . $defaultLanguage->name);
     }
     foreach ($titles as $key => $val) {
         if (!Validate::isGenericName($val)) {
             $errors[] = $module->l('the field Title is invalid');
         }
     }
     if (Tools::getValue('width') && !Validate::isFloat(Tools::getValue('width'))) {
         $errors[] = $module->l('the field Width is invalid');
     }
     if ($totalWidth + Tools::getValue('width') > 100) {
         $errors[] = $module->l('Width total is invalid(>100)');
     }
     if (!Tools::getValue('id_position')) {
         $errors[] = $module->l('the field Position is invalid');
     }
     if (!sizeof($errors)) {
         $objBlock = new LofBlock();
         $objBlock->title = $titles;
         $objBlock->width = Tools::getValue('width');
         $objBlock->show_title = Tools::getValue('show_title');
         $objBlock->id_position = Tools::getValue('id_position');
         $objBlock->is_link = Tools::isSubmit('link_title');