From 830643dcc63d99df76d12bc9058a0956355d88e7 Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Wed, 26 Mar 2025 00:08:41 +0100 Subject: [PATCH] update --- .vscode/ftp-kr.sync.cache.json | 4 +- config/defines.inc.php | 2 +- ...mport_Product_conflict-20171219-163900.php | 1944 ----------------- override/classes/Combination.php | 36 + 4 files changed, 39 insertions(+), 1947 deletions(-) delete mode 100644 modules/pshowimporter/classes/PShow_Import_Product_conflict-20171219-163900.php create mode 100644 override/classes/Combination.php diff --git a/.vscode/ftp-kr.sync.cache.json b/.vscode/ftp-kr.sync.cache.json index 12fab2d5..0a2c5c4e 100644 --- a/.vscode/ftp-kr.sync.cache.json +++ b/.vscode/ftp-kr.sync.cache.json @@ -64,7 +64,7 @@ }, "custom-script.php": { "type": "-", - "size": 1917, + "size": 1916, "lmtime": 0, "modified": true }, @@ -98,7 +98,7 @@ }, "google-merchant_id-1.xml": { "type": "-", - "size": 17951117, + "size": 17900206, "lmtime": 0, "modified": true }, diff --git a/config/defines.inc.php b/config/defines.inc.php index 8f90b1d7..ed1edd5b 100644 --- a/config/defines.inc.php +++ b/config/defines.inc.php @@ -25,7 +25,7 @@ */ /* Debug only */ -( $_SERVER['REMOTE_ADDR'] == '91.189.216.43' ) ? define('_PS_MODE_DEV_', false ) : define('_PS_MODE_DEV_', false); +( $_SERVER['REMOTE_ADDR'] == '178.42.108.40' ) ? define('_PS_MODE_DEV_', false ) : define('_PS_MODE_DEV_', false); /* Compatibility warning */ define('_PS_DISPLAY_COMPATIBILITY_WARNING_', false); if (_PS_MODE_DEV_ === true) { diff --git a/modules/pshowimporter/classes/PShow_Import_Product_conflict-20171219-163900.php b/modules/pshowimporter/classes/PShow_Import_Product_conflict-20171219-163900.php deleted file mode 100644 index 7858e43d..00000000 --- a/modules/pshowimporter/classes/PShow_Import_Product_conflict-20171219-163900.php +++ /dev/null @@ -1,1944 +0,0 @@ - - * @copyright 2015 PrestaShow.pl - * @license http://PrestaShow.pl/license - */ -class PShow_Import_Product extends PShow_Import_Object_Abstract -{ - - public $matched_categories = array(); - public $product_img_count = 0; - - /** - * Unlink product from all categories - * - * @param int|null $id_shop - */ - public function unlinkProductFromAllCategories($id_shop = null) - { - if (!PShow_Config::isChecked('category_unlink_old')) { - return; - } - - PShow_Log::addImportLog("unlink product from all categories"); - - $q = "DELETE FROM `" . _DB_PREFIX_ . "category_product` " - . "WHERE `id_product` = " . (int) PShow_Import::$objects['Product']->id; - - if ($id_shop !== null && is_numeric($id_shop)) { - $q .= " AND `id_category` IN (" - . "SELECT `id_category` " - . "FROM `" . _DB_PREFIX_ . "category_shop` " - . "WHERE `id_shop` = " . (int) $id_shop - . ")"; - } - - Db::getInstance()->query($q); - } - - /** - * Add product to categories - * - * @param array $addToCategories - */ - public function addProductToCategories(array $addToCategories) - { - $q = ""; - foreach ($addToCategories as $cat_id) { - PShow_Log::addImportLog("add product to category #" . (int) $cat_id); - $q .= "INSERT IGNORE `" . _DB_PREFIX_ . "category_product` " - . "(`id_category`, `id_product`, `position`) VALUES " - . "(" . (int) $cat_id . ", " . (int) PShow_Import::$objects['Product']->id . ", 1); "; - } - - if (empty($q)) { - return; - } - - try { - Db::getInstance(_PS_USE_SQL_SLAVE_)->query($q); - } catch (PrestaShopDatabaseException $e) { - PShow_Log::addImportLog("Unable to add product to categories because: " . $e->getMessage()); - } - } - - /** - * getNewObject() - * - * get new or existing object - */ - public function getNewObject($id = null) - { - $price = 0; - - if (array_key_exists('price', $this->data)) { - $price = $this->data['price'][0]; - } elseif (array_key_exists('price_brutto', $this->data)) { - $price = $this->data['price_brutto'][0]; - } - - if (PShow_Config::isChecked('productskipp_price_eg_checkbox', true) && PShow_Config::get('productskipp_price_eg', 'intval', true) < $price) { - return 5; - } - - if (PShow_Config::isChecked('productskipp_price_el_checkbox', true) && PShow_Config::get('productskipp_price_el', 'intval', true) >= $price) { - return 4; - } - - $quantity = (array_key_exists('quantity', $this->data) ? (int) $this->data['quantity'][0] : 0); - - if (PShow_Config::isChecked('productskipp_quantity_eg_checkbox', true) && PShow_Config::get('productskipp_quantity_eg', 'intval', true) < $quantity) { - return 8; - } - - if (PShow_Config::isChecked('productskipp_quantity_el_checkbox', true) && PShow_Config::get('productskipp_quantity_el', 'intval', true) >= $quantity) { - return 9; - } - - if ($this->matched_categories && count($this->matched_categories) > 0) { - - if (array_key_exists('category', $this->data)) { - $cat = $this->data['category']; - $type = 'name'; - } elseif (array_key_exists('category_path', $this->data)) { - $cat = $this->data['category_path']; - $type = 'path'; - } - - if (isset($cat)) { - $cat_md5 = md5($cat[0]); - - if (array_key_exists($cat_md5, $this->matched_categories) && $this->matched_categories[$cat_md5] == 'disableNotExistingInFile') { - $categoriesToDisable = file_get_contents(_IMPORT_STATUS_PATH_ . '/categoriesToDisable.ini'); - - if (empty($categoriesToDisable) || stripos($categoriesToDisable, $type . $cat_md5) === false) { - file_put_contents( - _IMPORT_STATUS_PATH_ - . '/categoriesToDisable.ini', "\n" . $type . $cat_md5 . "=" . $cat[0], FILE_APPEND - ); - } - } - - if (array_key_exists($cat_md5, $this->matched_categories) && $this->matched_categories[$cat_md5] == 'skip') { - return 2; - } - } - } - - if (array_key_exists('weight', $this->data) && PShow_Config::get('skipGtWeight', 'intval', true) > 0 && ((int) $this->data['weight'][0]) > PShow_Config::get('skipGtWeight', 'intval', true)) { - return 0; - } - - if (isset($this->skipped_manufacturers) && $this->skipped_manufacturers && count($this->skipped_manufacturers) > 0 && - array_key_exists('manufacturer', $this->data) && array_key_exists(md5($this->data['manufacturer'][0]), $this->skipped_manufacturers) && - (int) ($this->skipped_manufacturers[md5($this->data['manufacturer'][0])])) { - return 1; - } - - if (isset($this->skipped_manufacturers) && $this->skipped_manufacturers && count($this->skipped_manufacturers) > 0 && - (!array_key_exists('manufacturer', $this->data) || empty($this->data['manufacturer'][0])) && - array_key_exists(md5("Without value in the file"), $this->skipped_manufacturers)) { - return 1; - } - - if (array_key_exists('id_product', $this->data)) { - $object = parent::getNewObject((int) $this->data['id_product'][0]); - } else { - $object = parent::getNewObject(); - } - - $obj = is_array($object) ? reset($object) : $object; - if ($obj && $obj->id && $this->object_status == PShow_Import_Object_Abstract::STATUS_EXISTS && - method_exists('Product', 'checkImportStatus') && - !Product::checkImportStatus($obj->id, PShow_Import::getInstance()->id_shop)) { - PShow_Log::addImportLog("This product #" . $obj->id . " in the shop #" . PShow_Import::getInstance()->id_shop . " has blocked modification during import."); - return 0; - } - - if (array_key_exists('price', $this->data) && PShow_Config::isChecked('productskipp_netprice_l_than_shop') && $this->calculateExchangeRate($this->data['price'][0], false) < $object->getPrice(false)) { - return 10; - } - - if (array_key_exists('price_brutto', $this->data) && PShow_Config::isChecked('productskipp_grossprice_l_than_shop') && $this->calculateExchangeRate($this->data['price_brutto'][0], false) < $object->getPrice()) { - return 11; - } - - if (array_key_exists('price', $this->data) && PShow_Config::isChecked('productskipp_netprice_h_than_shop') && $this->calculateExchangeRate($this->data['price'][0], false) > $object->getPrice(false)) { - return 10; - } - - if (array_key_exists('price_brutto', $this->data) && PShow_Config::isChecked('productskipp_grossprice_h_than_shop') && $this->calculateExchangeRate($this->data['price_brutto'][0], false) > $object->getPrice()) { - return 11; - } - - // Skip product when net price with overhead in the file is higher than in the shop - if (array_key_exists('price', $this->data) && array_key_exists('margin_prices', $this->data) && - PShow_Config::isChecked('productskipp_netmarginprice_h_than_shop') && - $this->calculateExchangeRate(((float) $this->data['price'][0]) + (((float) $this->data['price'][0]) * ((float) $this->data['margin_prices'][0])), false) > $object->getPrice()) { - return 11; - } - - // Skip product when net price with overhead in the file is lower than in the shop - if (array_key_exists('price', $this->data) && array_key_exists('margin_prices', $this->data) && - PShow_Config::isChecked('productskipp_netmarginprice_l_than_shop') && - $this->calculateExchangeRate(((float) $this->data['price'][0]) + (((float) $this->data['price'][0]) * ((float) $this->data['margin_prices'][0])), false) < $object->getPrice()) { - return 10; - } - - if (PShow_Config::isChecked('updateAndRemoveImages', true)) { - PShow_Log::addImportLog("Removing product images...", true); - - $imported = Tools::file_get_contents(_IMPORT_STATUS_PATH_ . "imported_references"); - PShow_Import::$imported_ref = (!empty($imported)) ? explode(';', $imported) : array(); - - $objects = (is_array($object)) ? $object : array($object); - - // remove product images ! - foreach ($objects as $obj) { - if (!is_object($obj)) { - continue; - } - - $obj->deleteImages(); - } - } - - return $object; - } - - /** - * Remove product combinations images - * - * @param int $id_product - * @param array $except_ - */ - public static function removeProductCombinationImages($id_product, $except_ = array()) - { - - $except = array_filter($except_, 'ctype_digit'); - - $q = "SELECT `id_image` " - . "FROM `" . _DB_PREFIX_ . "product_attribute_image` " - . "WHERE `id_product_attribute` IN (" - . "SELECT `id_product_attribute` " - . "FROM `" . _DB_PREFIX_ . "product_attribute` " - . "WHERE `id_product` = " . (int) $id_product . ") " - . (count($except) ? "AND `id_image` NOT IN (" . implode(',', $except) . ")" : null); - $ids_ = Db::getInstance()->executeS($q); - - $ids = array(); - - foreach ($ids_ as $id) { - array_push($ids, $id['id_image']); - - // remove files - $tmp = new Image((int) $id['id_image']); - $tmp->deleteImage(true); - unset($tmp); - } - - if (!count($ids)) { - PShow_Log::addImportLog("Product don't have any images assigned to combinations"); - return; - } - - PShow_Log::addImportLog( - "Removing images with id: " . implode(',', $ids) - ); - - $q = "DELETE FROM `" . _DB_PREFIX_ . "image` " - . "WHERE `id_product` = " . (int) $id_product . " " - . "AND `id_image` IN (" . implode(',', $ids) . "); "; - - $q .= "DELETE FROM `" . _DB_PREFIX_ . "image_shop` " - . "WHERE `id_product` = " . (int) $id_product . " " - . "AND `id_image` IN (" . implode(',', $ids) . "); "; - - $q .= "DELETE FROM `" . _DB_PREFIX_ . "image_lang` " - . "WHERE `id_image` IN (" . implode(',', $ids) . "); "; - - PShow_Log::addImportLog("Database cleaning... "); - - $q .= "DELETE FROM `" . _DB_PREFIX_ . "product_attribute_image` " - . "WHERE (`id_image` IN (" . implode(',', $ids) . ")) OR (`id_product_attribute` = 0); "; - - $q .= "DELETE FROM `" . _DB_PREFIX_ . "product_attribute_image` " - . "WHERE `id_image` NOT IN (SELECT `id_image` FROM `" . _DB_PREFIX_ . "image`); "; - - Db::getInstance()->query($q); - } - - /** - * Set and prepare data to import - * - * @param array $data - * @param array $merge_fields - */ - public function setData(array $data, array $merge_fields = array()) - { - parent::setData($data, $merge_fields); - - if (isset(PShow_Import::getInstance()->config[2])) { - $this->matched_categories = PShow_Import::getInstance()->config[2]; - } - - if (isset(PShow_Import::getInstance()->config[3])) { - $this->skipped_manufacturers = PShow_Import::getInstance()->config[3]; - } - } - - /** - * Add product to parent categories - * - * @param Category $category - */ - public function addToParentCategories(Category $category) - { - if (!PShow_Config::isChecked('addToParentCategories')) { - return; - } - - PShow_Log::addImportLog("add product to parent categories"); - - $thisObject = &PShow_Import::$objects['Product']; - $productCategories = $thisObject->getCategories(); - $addToCategories = array(); - - foreach ($category->getParentsCategories() as $cat) { - if (!in_array($cat['id_category'], $addToCategories) && !in_array($cat['id_category'], $productCategories)) { - $addToCategories[] = $cat['id_category']; - } - } - - if (!in_array(1, $addToCategories) && !in_array(2, $productCategories)) { - $addToCategories[] = 2; - } - - if (PShow_Config::isChecked('doNotAddToHomeCategory')) { - $addToCategories = array_diff($addToCategories, array(2)); - } - - $this->addProductToCategories($addToCategories); - } - - /** - * Check if product exists - * - * @return \Product|boolean|array - */ - public function exists() - { - // check by reference - if (PShow_Config::get('unique_data') == 'reference' && - array_key_exists('reference', $this->data)) { - $key = pSQL($this->data['reference'][0]); - if (!empty($key)) { - - PShow_Log::addImportLog("Search by reference: " . $key); - - /** - * At first check if product exists in defined shop - */ - $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' - SELECT p.`id_product` - FROM `' . _DB_PREFIX_ . 'product` p - JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON ( - p.`id_product` = ps.`id_product` AND ps.`id_shop` = ' . (int) PShow_Import::getInstance()->id_shop . ' - ) - WHERE p.reference = "' . $key . '"'); - - $products = array(); - - foreach ($rows as $row) { - $products[] = new Product((int) $row['id_product'], false, null, PShow_Import::getInstance()->id_shop); - } - - if (count($products) > 0) { - return $products; - } - - /** - * If products not exists in defined shop, search in other shops - */ - $rows = Db::getInstance()->executeS(' - SELECT p.`id_product`, ps.`id_shop` - FROM `' . _DB_PREFIX_ . 'product` p - JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON ( - p.`id_product` = ps.`id_product` - ) - WHERE p.reference = "' . $key . '"'); - - if (count($rows)) { - - $products = array(); - - foreach ($rows as $row) { - $this->pushObjectToOtherShops( - 'product', (int) $row['id_product'], (int) $row['id_shop'], array(PShow_Import::getInstance()->id_shop) - ); - - PShow_Log::addImportLog( - "product with reference '" . $key . "' " - . "found in shop #" . (int) $row['id_shop'] . " " - . "and copied into shop #" . PShow_Import::getInstance()->id_shop - ); - - $products[] = new Product((int) $row['id_product'], false, null, PShow_Import::getInstance()->id_shop); - } - - if (count($products) > 0) { - return $products; - } - } - } - } - - // check by id - if (PShow_Config::get('unique_data') == 'id' && - array_key_exists('id_product', $this->data)) { - $key = (int) $this->data['id_product'][0]; - if ($key) { - PShow_Log::addImportLog("Search by id: " . (int) $key); - - $row = Db::getInstance()->getRow(' - SELECT p.`id_product` - FROM `' . _DB_PREFIX_ . 'product` p - JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON ( - p.`id_product` = ps.`id_product` AND ps.`id_shop` = ' . (int) PShow_Import::getInstance()->id_shop . ' - ) - WHERE p.`id_product` = ' . (int) $key); - - - if (is_array($row) && array_key_exists('id_product', $row)) { - return new Product((int) $row['id_product'], false, null, PShow_Import::getInstance()->id_shop); - } - - /** - * If products not exists in defined shop, search in other shops - */ - $rows = Db::getInstance()->executeS(' - SELECT p.`id_product`, ps.`id_shop` - FROM `' . _DB_PREFIX_ . 'product` p - JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON ( - p.`id_product` = ps.`id_product` - ) - WHERE p.`id_product` = ' . (int) $key); - - if (is_array($row) && array_key_exists('id_product', $row)) { - - $this->pushObjectToOtherShops( - 'product', (int) $row['id_product'], (int) $row['id_shop'], array(PShow_Import::getInstance()->id_shop) - ); - - PShow_Log::addImportLog( - "product with id '" . pSQL($this->data['id_product'][0]) . "' " - . "found in shop #" . (int) $row['id_shop'] . " " - . "and copied into shop #" . PShow_Import::getInstance()->id_shop - ); - - return new Product((int) $row['id_product'], false, null, PShow_Import::getInstance()->id_shop); - } - } - } - - // check by ean13 - if (PShow_Config::get('unique_data') == 'ean13' && - array_key_exists('ean13', $this->data)) { - $key = pSQL($this->data['ean13'][0]); - if (!empty($key)) { - PShow_Log::addImportLog("Search by ean13: " . $key); - - $row = Db::getInstance()->getRow(' - SELECT p.`id_product` - FROM `' . _DB_PREFIX_ . 'product` p - JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON ( - p.`id_product` = ps.`id_product` AND ps.`id_shop` = ' . (int) PShow_Import::getInstance()->id_shop . ' - ) - WHERE p.ean13 = \'' . $key . '\''); - - if (is_array($row) && array_key_exists('id_product', $row)) { - return new Product((int) $row['id_product'], false, null, PShow_Import::getInstance()->id_shop); - } - - /** - * If products not exists in defined shop, search in other shops - */ - $row = Db::getInstance()->getRow(' - SELECT p.`id_product`, ps.`id_shop` - FROM `' . _DB_PREFIX_ . 'product` p - JOIN `' . _DB_PREFIX_ . 'product_shop` ps ON ( - p.`id_product` = ps.`id_product` - ) - WHERE p.ean13 = \'' . (int) $this->data['ean13'][0] . '\''); - - if (is_array($row) && array_key_exists('id_product', $row)) { - - $this->pushObjectToOtherShops( - 'product', (int) $row['id_product'], (int) $row['id_shop'], array(PShow_Import::getInstance()->id_shop) - ); - - PShow_Log::addImportLog( - "product with ean13 '" . pSQL($this->data['id_product'][0]) . "' " - . "found in shop #" . (int) $row['id_shop'] . " " - . "and copied into shop #" . PShow_Import::getInstance()->id_shop - ); - - return new Product((int) $row['id_product'], false, null, PShow_Import::getInstance()->id_shop); - } - } - } - - return false; - } - - /** - * Get VAT percentage - * - * @return float - */ - public function getVatFromConfig() - { - $value = 0; - - if (PShow_Config::get('vat')) { - $value = PShow_Config::get('vat'); - } - - if (array_key_exists('vat_percentage', $this->data)) { - $value = $this->data['vat_percentage'][0]; - } - - if (array_key_exists('id_tax_rules_group', $this->data)) { - $id_tax_rules_group = (int) $this->data['id_tax_rules_group'][0]; - $q = "SELECT t.`rate` " - . "FROM `" . _DB_PREFIX_ . "tax_rules_group` trg " - . "JOIN `" . _DB_PREFIX_ . "tax_rules_group_shop` trgs " - . " ON (trgs.`id_tax_rules_group` = trg.`id_tax_rules_group`) " - . "JOIN `" . _DB_PREFIX_ . "tax_rule` tr " - . " ON (tr.`id_tax_rules_group` = trg.`id_tax_rules_group`) " - . "JOIN `" . _DB_PREFIX_ . "tax` t " - . " ON (t.`id_tax` = tr.`id_tax`) " - . "WHERE trg.`id_tax_rules_group` = " . $id_tax_rules_group . " " - . "AND trgs.`id_shop` = " . PShow_Import::getInstance()->id_shop . "; "; - $value = Db::getInstance()->getValue($q); - } - - $value = str_replace(',', '.', $value); - $value = preg_replace('/[^0-9.]*/', '', $value); - - PShow_Log::addImportLog("use tax value: " . $value); - - return (float) $value; - } - - public function import() - { - $this->product_img_count = Db::getInstance()->getValue('SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'image` ' - . 'WHERE `id_product` = ' . (int) PShow_Import::$objects['Product']->id); - - parent::import(); - -// $this->addToParentCategories( -// new Category( -// (int) PShow_Import::$objects['Product']->id_category_default, null, PShow_Import::getInstance()->id_shop -// ) -// ); - // add to home category if not checked option `doNotAddToHomeCategory` - if (!PShow_Config::isChecked('doNotAddToHomeCategory', true)) { -// $this->addProductToCategories(array(2)); -// if (!PShow_Import::$objects['Product']->id_category_default) { -// PShow_Import::$objects['Product']->id_category_default = 2; -// } - } else { - PShow_Import::$objects['Product']->deleteCategory(2); - } - } - - /** - * Calculate price with exchange rate - * - * @param float $price - */ - public function calculateExchangeRate(&$price, $overridePrice = true) - { - $temp = $price; - - $config = PShow_Config::getFileConfig(PShow_Import::getInstance()->filename); - if (array_key_exists('additional', $config) && array_key_exists('exchange_rates', $config['additional']) && - array_key_exists('active', $config['additional']['exchange_rates']) && $config['additional']['exchange_rates']['active'] && - array_key_exists('id_currency', $config['additional']['exchange_rates']) && - array_key_exists('currency_' . $config['additional']['exchange_rates']['id_currency'], $config['additional']['exchange_rates'])) { - - $id_currency = 0; - - if (array_key_exists('price_currency_iso', $this->data)) { - $id_currency = (int) Currency::getIdByIsoCode($this->data['price_currency_iso'], (int) PShow_Import::getInstance()->id_shop); - } elseif (array_key_exists('price_currency_iso_num', $this->data)) { - $id_currency = (int) Currency::getIdByIsoCodeNum((int) $this->data['price_currency_iso_num'], (int) PShow_Import::getInstance()->id_shop); - } - - if ($id_currency <= 0) { - $id_currency = $config['additional']['exchange_rates']['id_currency']; - } - - $rate = $config['additional']['exchange_rates']['currency_' . $id_currency]; - - $temp = round($price * (float) $rate, 9, PHP_ROUND_HALF_DOWN); - - PShow_Log::addImportLog("net price (" . (float) $price . ") calculated with exchange rate (" . (float) $rate . ") = " . (float) $temp); - - if ($overridePrice === true) { - $price = $temp; - } - } - - return $temp; - } - - protected function _import($key, &$value) - { - $feature_type = 'pre-defined'; - if (strpos($key, 'feature:') !== false) { - $feature_id = (int) str_replace('feature:', '', $key); - $key = 'feature'; - } elseif (strpos($key, 'feature_custom:') !== false) { - $feature_id = (int) str_replace('feature_custom:', '', $key); - $key = 'feature'; - $feature_type = 'customized'; - } - - if ($key == 'combination_reference') { - $key = 'combination'; - } elseif (stripos($key, 'combination_') === 0) { - return; - } - - $classname = $this->getObjectName(); - $thisObject = &PShow_Import::$objects[$classname]; - - parent::_import($key, $value); - - switch ($key) { - - case 'combination': - - if (isset($this->data['combination_reference'])) { - $references = $this->data['combination_reference']; - } else { - PShow_Log::addImportLog("combination import failed, you do not specified combination reference"); - return; - } - - $update_existing = PShow_Config::get('update_existing', 'boolval'); - - foreach ($references as $i => $reference) { - - // filter combination values - $data = array(); - foreach ($this->data as $k => $v) { - if (strpos($k, 'combination_') === 0) { - $data[str_replace('combination_', null, $k)] = $v; - } - } - $data['pro_id'] = array($thisObject->id); - - // get only one value to import into multi combinations - $fieldsToGetOneValue = array('attr_group', 'attr_value', 'attr_type', 'attr_texture', 'attr_color', 'weight', 'reference', - 'available_date', 'wholesale_price', 'price', 'unit_price_impact', 'reference', 'supplier_reference', 'ean13', 'upc', - 'minimal_quantity', 'set_as_default', 'img_url'); - - foreach ($fieldsToGetOneValue as $field) { - if (isset($data[$field][$i])) { - $data[$field] = array($data[$field][$i]); - } else { - $data[$field] = array(reset($data[$field])); - } - } - - if (!array_key_exists('quantity', $data) || (is_array($data['quantity']) && !isset($data['quantity'][$i]))) { - $data['quantity'] = array(0); - } - - if (is_array($data['quantity']) && isset($data['quantity'][$i])) { - $data['quantity'] = array($data['quantity'][$i]); - } - - // create new importer of combination - $combination_importer = new PShow_Import_Combination(); - $combination_importer->importLangs = $this->importLangs; - $combination_importer->setData($data); - - $combination_importer->addDirectConf('pro_id', $thisObject->id); - $combination_importer->addDirectConf('what_import', 'all'); - - // update existing combinations - if ($update_existing) { - if (isset($data['reference'])) { - $combination_importer->addDirectConf('what_import', 'exists_or_not'); - $combination_importer->addDirectConf('unique_data', 'reference'); - PShow_Log::addImportLog("update existing combination with reference: " . $data['reference']); - } elseif (isset($data['ean13'])) { - $combination_importer->addDirectConf('what_import', 'exists_or_not'); - $combination_importer->addDirectConf('unique_data', 'ean13'); - PShow_Log::addImportLog("update existing combination with ean13: " . $data['ean13']); - } - } - - // get objects of combination - $objects_ = $combination_importer->getNewObject(); - - if (is_numeric($objects_) || is_bool($objects_)) { - continue; - } - - // import combinations - if (is_array($objects_)) { - foreach ($objects_ as $object) { - PShow_Import::$objects['Combination'] = $object; - - $combination_importer->import(); - - PShow_Import::$objects['Combination']->save(); - } - } else { - PShow_Import::$objects['Combination'] = $objects_; - - $combination_importer->import(); - - PShow_Import::$objects['Combination']->save(); - } - } - - break; - - case 'weight': - - $this->checkAndMergeValues($value, true); - - $weight = (float) str_replace(',', '.', $value); - - $thisObject->weight = $weight; - - break; - - case 'specific_price_promo': - - $this->checkAndMergeValues($value, true); - - if (Tools::getValue('debug')) { - return; - } - - $price = (float) $value; - - $id_specific_price = (int) Db::getInstance()->getValue( - 'SELECT `id_specific_price` FROM `' . _DB_PREFIX_ . 'specific_price` - WHERE `id_product` = ' . (int) $thisObject->id . ' - AND `id_group` = 0 AND `id_currency` = 0 - AND `id_country` = 0 AND `id_cart` = 0 AND `id_customer` = 0 '); - - if ($id_specific_price > 0) { - $sp = new SpecificPrice($id_specific_price, null, PShow_Import::getInstance()->id_shop); - $sp->price = $price; - try { - $sp->save(); - } catch (PrestaShopException $e) { - PShow_Log::addExceptionLog($e); - } - } else { - try { - $sp = new SpecificPrice(null, null, PShow_Import::getInstance()->id_shop); - $sp->id_product = $thisObject->id; - $sp->id_cart = 0; - $sp->id_shop = PShow_Import::getInstance()->id_shop; - $sp->id_currency = 0; - $sp->id_country = 0; - $sp->id_group = 0; - $sp->id_customer = 0; - $sp->price = $price; - $sp->from_quantity = 1; - $sp->reduction = 0; - $sp->reduction_tax = 1; - $sp->reduction_type = 'amount'; - $sp->from = '0000-00-00 00:00:00'; - $sp->to = '0000-00-00 00:00:00'; - $sp->add(); - } catch (PrestaShopException $e) { - PShow_Log::addExceptionLog($e); - } - } - - break; - - case 'specific_price': - - $this->checkAndMergeValues($value, true); - - if (Tools::getValue('debug')) { - return; - } - - $id_currency = PShow_Config::get('id_currency', 'intval'); - $id_country = PShow_Config::get('id_country', 'intval'); - $id_group = PShow_Config::get('id_group', 'intval'); - $id_customer = PShow_Config::get('id_customer', 'intval'); - $price = PShow_Config::get('leave_bprice', 'boolval') ? '-1' : floatval($value); - $from_quantity = PShow_Config::get('from_quantity', 'intval'); - $reduction = (float) (PShow_Config::get('reduction', 'floatval')); - $reduction_tax = PShow_Config::get('reduction_tax', 'intval'); - $reduction_type = !$reduction ? 'amount' : PShow_Config::get('reduction_type'); - $reduction_type = $reduction_type == '-' ? 'amount' : $reduction_type; - $from = PShow_Config::get('sp_from'); - if (!$from) { - $from = '0000-00-00 00:00:00'; - } - $to = PShow_Config::get('sp_to'); - if (!$to) { - $to = '0000-00-00 00:00:00'; - } - - try { - $specificPrice = new SpecificPrice(); - $specificPrice->id_product = (int) $thisObject->id; - $specificPrice->id_product_attribute = (int) 0; - $specificPrice->id_shop = (int) PShow_Import::getInstance()->id_shop; - $specificPrice->id_currency = (int) ($id_currency); - $specificPrice->id_country = (int) ($id_country); - $specificPrice->id_group = (int) ($id_group); - $specificPrice->id_customer = (int) $id_customer; - $specificPrice->price = (float) ($price); - $specificPrice->from_quantity = (int) ($from_quantity); - $specificPrice->reduction = (float) ($reduction_type == 'percentage' ? $reduction / 100 : $reduction); - $specificPrice->reduction_tax = $reduction_tax; - $specificPrice->reduction_type = $reduction_type; - $specificPrice->from = $from; - $specificPrice->to = $to; - if (!$specificPrice->add()) { - PShow_Log::addImportLog(Tools::displayError('An error occurred while updating the specific price.')); - } - } catch (PrestaShopException $e) { - PShow_Log::addExceptionLog($e); - } - - break; - - case 'out_of_stock': - - $this->checkAndMergeValues($value, true); - - $value = (int) $value; - - if (empty($value)) { - return; - } - - StockAvailable::setProductOutOfStock($thisObject->id, $value); - - break; - - case 'asm_warehouse_name': - break; - - case 'quantity': - - $this->checkAndMergeValues($value, true); - - if (PShow_Config::isChecked('product_qty_int')) { - $value = (int) intval($value); - } else { - $value = (int) str_replace(array('.', ',', ' '), '', $value); - } - - if (Tools::getValue('debug')) { - return; - } - - if (PShow_Addon::getInstance('ASM') && PShow_Addon::getInstance('ASM')->isEnabled() && PShow_Config::get('asm_enabled', 'boolval')) { - PShow_Addon::getInstance('ASM')->importProductQuantity($value); - } else { - - if (PShow_Config::get('type', 'intval') == 2) { - $current_qty = StockAvailable::getQuantityAvailableByProduct($thisObject->id, 0, PShow_Import::getInstance()->id_shop); - PShow_Log::addImportLog("current product quantity: " . $current_qty); - $value = $value + $current_qty; - PShow_Log::addImportLog("new product quantity: " . $value); - } - - $thisObject->quantity = $value; - - StockAvailable::setQuantity($thisObject->id, 0, $value, PShow_Import::getInstance()->id_shop); - - if (PShow_Config::get('producton_stock_checkbox', 'intval') && $value >= PShow_Config::get('producton_stock', 'intval')) { - $thisObject->active = true; - } elseif (PShow_Config::get('productoff_stock_checkbox', 'intval') && $value <= PShow_Config::get('productoff_stock', 'intval')) { - $thisObject->active = false; - } - } - - //StockAvailable::updateQuantity($product_item_temp['id_product'], 0, 0, null); - StockAvailable::synchronize($thisObject->id, null); - Product::updateDefaultAttribute($thisObject->id); - - break; - - case 'feature_id': - - $this->checkAndMergeValues($value, true); - - $key = (int) $value; - - if (!$key) { - PShow_Log::addImportLog("unable to import feature because ID is invalid: " . $key); - continue; - } - - $value = PShow_Config::get('feature_value'); - - if (!is_string($value)) { - return; - } - - // get feature value type from options - $feature_value_type = PShow_Config::get('feature_value_type', null, false, $i); - $this->_import('feature' . (($feature_value_type && $feature_value_type == 'customized') ? '_custom' : null) . ':' . $key, $value); - - break; - - case 'feature_value': - - $this->checkAndMergeValues($value); - - $values = $value; - - $feature_names = array_key_exists('feature_name', $this->data) ? $this->data['feature_name'] : array(); - $feature_ids = array_key_exists('feature_id', $this->data) ? $this->data['feature_id'] : array(); - $i = -1; - - foreach ($values as $value) { - - ++$i; - - $key = (int) PShow_Config::get('feature_id', 'intval', null, false, $i); - - $feature_name = PShow_Config::get('feature_name', null, false, $i); - if (!$key && $feature_name && !empty($feature_name)) { - PShow_Log::addImportLog("import: feature_name=" . $feature_name); - $key = (int) Feature::addFeatureImport($feature_name); - } - - if (!$key && isset($feature_ids[$i]) && !empty($feature_ids[$i])) { - $key = (int) $feature_ids[$i]; - } - - if (!$key && isset($feature_names[$i]) && !empty($feature_names[$i])) { - PShow_Log::addImportLog("import: feature_name=" . $feature_names[$i]); - $key = (int) Feature::addFeatureImport($feature_names[$i]); - } - - if (!$key) { - PShow_Log::addImportLog("unable to import feature because not exists and unable to create new"); - continue; - } - - // get feature value type from options - $feature_value_type = PShow_Config::get('feature_value_type', null, false, $i); - $this->_import('feature' . (($feature_value_type && $feature_value_type == 'customized') ? '_custom' : null) . ':' . $key, $value); - } - break; - - case 'feature_name': - - break; - - case 'link_rewrite': - - $this->checkAndMergeValues($value, true); - - $this->prepareLangField($thisObject->link_rewrite, Tools::link_rewrite($value)); - - if (empty($thisObject->link_rewrite) || !is_array($thisObject->link_rewrite) || !count($thisObject->link_rewrite)) { - $this->prepareLangField($thisObject->link_rewrite, Tools::link_rewrite('product-' . $thisObject->id)); - } - - break; - - case 'name': - - $this->checkAndMergeValues($value, true); - - $value = strip_tags($value); - - $this->prepareLangField($thisObject->name, $value); - - if (!isset($this->data['link_rewrite'][0])) { - $str = Tools::link_rewrite($value); - - if (empty($str)) { - $str = Tools::link_rewrite('product-' . $thisObject->id); - } - - $this->prepareLangField($thisObject->link_rewrite, $str); - } - - if (!isset($this->data['meta_title'][0])) { - $this->prepareLangField($thisObject->meta_title, $value); - } - - if (!isset($this->data['meta_description'][0])) { - $this->prepareLangField($thisObject->meta_description, $value); - } - - $q = ""; - foreach ($thisObject->name as $id_lang => $value) { - $q .= "UPDATE `" . _DB_PREFIX_ . "product_lang` " - . "SET `name` = '" . $value . "' " - . "WHERE `id_product` = " . $thisObject->id . " " - . "AND `id_lang` = " . $id_lang . " " - . "AND `name` = 'not-defined-but-required'; "; - } - foreach ($thisObject->link_rewrite as $id_lang => $value) { - $q .= "UPDATE `" . _DB_PREFIX_ . "product_lang` " - . "SET `link_rewrite` = '" . $value . "' " - . "WHERE `id_product` = " . $thisObject->id . " " - . "AND `id_lang` = " . $id_lang . " " - . "AND `link_rewrite` = 'not-defined-but-required'; "; - } - Db::getInstance()->execute($q); - - break; - - case 'feature': - - if (Tools::getValue('debug')) { - return; - } - - $this->checkAndMergeValues($value, true); - - if (empty($value)) { - return; - } - - $value = strip_tags($value); - - foreach ($this->importLangs as $lang) { - try { - $fv_id = FeatureValue::addFeatureValueImport( - $feature_id, $value, $thisObject->id, $lang['id_lang'], (isset($feature_type) && $feature_type == 'customized') - ); - - $hasFeature = false; - $features = $thisObject->getFeatures(); - - foreach ($features as $feature) { - if ($feature['id_feature'] == $feature_id) { - $hasFeature = true; - break; - } - } - - if (!$hasFeature) - $thisObject->addFeaturesToDB($feature_id, $fv_id); - } catch (PrestaShopException $msg) { - $msg = strip_tags($msg->getMessage()); - - if (stripos($msg, 'duplicate') === false) { - PShow_Log::add(pathinfo(PShow_Import::getInstance()->filepath, PATHINFO_FILENAME) . ".log", "Error in importing feature: " . $msg->getMessage()); - } - } - } - - break; - - case 'tags': - - $this->checkAndMergeValues($value); - - if (Tools::getValue('debug')) { - return; - } - - for ($i = 0; $i < count($value); ++$i) { - if (empty($value[$i])) { - continue; - } - - try { - foreach ($this->importLangs as $lang) { - Tag::addTags($lang['id_lang'], $thisObject->id, $value[$i], PShow_Config::get('tags_separator', null, false, $i)); - } - } catch (PrestaShopDatabaseException $e) { - PShow_Log::addImportLog("Error in tags import: " . $value[$i] . " with separator: " . PShow_Config::get('tags_separator', null, false, $i)); - } - } - - break; - - case 'manufacturer': - - if (Tools::getValue('debug')) { - return; - } - - if (PShow_Config::isChecked('manufacturer_dont_import')) { - PShow_Log::addImportLog("Manufacturer not importer because configured to not import"); - return; - } - - $this->checkAndMergeValues($value, true); - - $value = strip_tags($value); - - $id = Manufacturer::getIdByName($value); - - if (!$id) { - $manufacturer = new Manufacturer(); - $manufacturer->name = $value; - $manufacturer->active = true; - try { - $manufacturer->save(); - } catch (PrestaShopException $e) { - PShow_Log::addExceptionLog($e); - } - - $id = $manufacturer->id; - } - - $thisObject->id_manufacturer = (int) $id; - - break; - - case 'supplier': - - if (Tools::getValue('debug')) { - return; - } - - $this->checkAndMergeValues($value, true); - - $value = strip_tags($value); - - $id = Supplier::getIdByName(pSQL($value)); - - /** - * Assign supplier to the product - * - * @param \Product $product - * @param int $id_supplier - */ - $setProductSupplier = function($product, $id_supplier) { - try { - $ps = new ProductSupplier(null, null, PShow_Import::getInstance()->id_shop); - $ps->id_product = (int) $product->id; - $ps->id_supplier = (int) $id_supplier; - $ps->id_product_attribute = (int) 0; - $ps->save(); - $product->id_supplier = (int) $id_supplier; - } catch (PrestaShopDatabaseException $e) { - PShow_Log::addImportLog("PrestaShopDatabaseException: " . $e->getMessage()); - } - }; - - if (is_numeric($id) && $id) { - // supplier exists - $setProductSupplier($thisObject, $id); - return; - } - - try { - // supplier not exists - $supplier = new Supplier(); - $supplier->name = pSQL($value); - $supplier->active = true; - $supplier->save(); - - $setProductSupplier($thisObject, $supplier->id); - } catch (PrestaShopException $e) { - PShow_Log::addExceptionLog($e); - } - - break; - - case 'category_ids': - - if (Tools::getValue('debug')) { - return; - } - - $this->unlinkProductFromAllCategories(PShow_Import::getInstance()->id_shop); - - $this->checkAndMergeValues($value); - - foreach ($value as $v) { - //$v = preg_replace('/([^0-9\,]+)/g', null, $v); - - PShow_Log::addImportLog("add product to categories: " . $v); - - $values = array_map('intval', explode(',', $v)); - - $this->addProductToCategories($values); - $thisObject->id_category_default = end($values); - } - - break; - - case 'category': - - $this->_import('category_path', $value); - - break; - - case 'category_id': - - if (Tools::getValue('debug')) { - return; - } - - $values = $value; - - $this->checkAndMergeValues($value); - - $this->unlinkProductFromAllCategories(PShow_Import::getInstance()->id_shop); - - foreach ($values as $value) { - - $category = new Category((int) $value, null, PShow_Import::getInstance()->id_shop); - - if ($category instanceof Category) { - $c_id = $category->id; - $this->addProductToCategories(array($c_id)); - $thisObject->id_category_default = $c_id; - - if (PShow_Config::isChecked('addToParentCategories')) { - $c_id = $category->id_parent; - while ($c_id != 2 && $c_id != 1 && is_numeric($c_id)) { - $this->addProductToCategories(array($c_id)); - - $category = new Category((int) $c_id, null, PShow_Import::getInstance()->id_shop); - $c_id = $category->id_parent; - } - } - } - } - - break; - - case 'unit_price': - - $this->checkAndMergeValues($value, true); - - $value = str_replace(',', '.', $value); - $value = (float) preg_replace('/[^0-9.]*/', '', $value); - - $thisObject->unit_price = round($value, 9, PHP_ROUND_HALF_DOWN); - - $this->calculateExchangeRate($thisObject->unit_price); - - break; - - case 'wholesale_price': - - $this->checkAndMergeValues($value, true); - - $value = str_replace(',', '.', $value); - $value = (float) preg_replace('/[^0-9.]*/', '', $value); - - $thisObject->wholesale_price = round($value, 9, PHP_ROUND_HALF_DOWN); - - $this->calculateExchangeRate($thisObject->wholesale_price); - - break; - - case 'price_currency_iso': - - break; - - case 'price_currency_iso_num': - - break; - - case 'price': - - $this->checkAndMergeValues($value, true); - - $value = str_replace(',', '.', $value); - $value = (float) preg_replace('/[^0-9.]*/', '', $value); - - $margin = (float) PShow_Config::get('margin_prices'); - - if ($margin == 0) { - $margin = 1; - } - - $thisObject->price = round($value * $margin, 9, PHP_ROUND_HALF_DOWN); - - $this->calculateExchangeRate($thisObject->price); - - break; - - case 'accessories_id': - - if (Tools::getValue('debug')) { - return; - } - - $this->checkAndMergeValues($value, true); - - $value = str_replace(' ', '', $value); - $accessories = array(); - $values = explode(PShow_Config::get('accessories_separator'), $value); // array of references - - foreach ($values as $v) { - $accessories[]['id'] = (int) $v; - } - - $thisObject->setWsAccessories($accessories); - - break; - - case 'accessories_ref': - - if (Tools::getValue('debug')) - return; - - $this->checkAndMergeValues($value, true); - - $value = str_replace(' ', '', $value); - $accessories = array(); - $values = explode(PShow_Config::get('accessories_separator'), $value); // array of references - - foreach ($values as $v) { - $ref = pSQL($v); - - if (empty($ref)) { - continue; - } - - $q = "SELECT `id_product` FROM `" . _DB_PREFIX_ . "product` WHERE `reference` = '" . $ref . "'"; - - $products = Db::getInstance()->executeS($q); - - foreach ($products as $p) { - $accessories[]['id'] = (int) $p['id_product']; - } - } - - $thisObject->setWsAccessories($accessories); - - break; - - case 'vat_percentage': - - if (Tools::getValue('debug')) - return; - - $this->checkAndMergeValues($value, true); - - $value = str_replace(',', '.', $value); - $value = (float) preg_replace('/[^0-9.]*/', '', $value); - - $thisObject->id_tax_rules_group = $this->getOrCreateTaxRulesGroup($value); - - break; - - case 'price_brutto': - - $this->checkAndMergeValues($value, true); - - $value = str_replace(',', '.', $value); - $value = (float) preg_replace('/[^0-9.]*/', '', $value); - - $vat = $this->getVatFromConfig(); - - $margin = (float) PShow_Config::get('margin_prices'); - - if ($margin == 0) { - $margin = 1; - } - - $value = (float) ($value * $margin); - - $vat = ((float) $vat) + 100; - $netto = (float) ( 1 / ($vat / 100) ); - - $thisObject->price = round($netto * $value, 9, PHP_ROUND_HALF_DOWN); - - $this->calculateExchangeRate($thisObject->price); - - break; - - case 'category_path': - - if (Tools::getValue('debug')) { - return; - } - - $values = $value; - - $this->checkAndMergeValues($values); - - $this->unlinkProductFromAllCategories(PShow_Import::getInstance()->id_shop); - - foreach ($values as $value) { - - // category matching - - $valFromMatching = $value; - if (substr($valFromMatching, (strlen($valFromMatching) - 1), 1) == '/') { - $valFromMatching = substr($valFromMatching, 0, (strlen($valFromMatching) - 1)); - } - $md5 = md5($valFromMatching); - if ($this->matched_categories && array_key_exists($md5, $this->matched_categories) && - $this->matched_categories[$md5] != 'leave' && is_numeric($this->matched_categories[$md5])) { - $cat = new Category((int) $this->matched_categories[$md5], null, PShow_Import::getInstance()->id_shop); - - if ($cat instanceof Category) { - PShow_Log::addImportLog("found matched category with ID: " . (int) $this->matched_categories[$md5], true); - - $this->addProductToCategories(array($cat->id)); - - if (PShow_Config::isChecked('addToParentCategories')) { - $this->addToParentCategories($cat); - } - $thisObject->id_category_default = $cat->id; - } else { - PShow_Log::addImportLog("warning! category from matching not found", true); - } - - continue; - } - - // category creating - - $value = str_replace(' / ', '|slash|', $value); - $separator = str_replace('backslash', '\\', PShow_Config::get('category_separator')); - $path = explode($separator, $value); - - if (!$path) { - $path = array($value); - } - - if (PShow_Config::isChecked('reverseCategoryPath')) { - $path = array_reverse($path); - } - - $parent_id = (int) PShow_Config::get('parent_id'); - $level_depth = 2; - - if ($parent_id < 1 || !Validate::isLoadedObject(($tmp = new Category($parent_id)))) { - $parent_id = 2; - } - - foreach ($path as $value) { - $value = str_replace('|slash|', ' / ', $value); - $value = strip_tags($value); - - if (empty($value)) - continue; - - $valFromMatching = $value; - if (substr($valFromMatching, (strlen($valFromMatching) - 1), 1) == '/') { - $valFromMatching = substr($valFromMatching, 0, (strlen($valFromMatching) - 1)); - } - $md5 = md5($valFromMatching); - if ($this->matched_categories && array_key_exists($md5, $this->matched_categories) && $this->matched_categories[$md5] != 'leave' && is_numeric($this->matched_categories[$md5])) { - - $cat = new Category((int) $this->matched_categories[$md5], null, PShow_Import::getInstance()->id_shop); - - if ($cat instanceof Category) { - $this->addProductToCategories(array($cat->id)); - - if (PShow_Config::isChecked('addToParentCategories')) { - $this->addToParentCategories($cat); - } - $thisObject->id_category_default = $cat->id; - } else { - PShow_Log::addImportLog("Warning! Category from matching not found", true); - } - - continue; - } - - foreach ($this->importLangs as $lang) { - $category = Category::searchByNameAndParentCategoryId($lang['id_lang'], $value, $parent_id); - - if ($category && $category->id_shop == PShow_Import::getInstance()->id_shop) { - break; - } - } - - if (!$category) { - $category = new Category(null, null, PShow_Import::getInstance()->id_shop); - - $this->prepareLangField($category->name, $value); - $this->prepareLangField($category->link_rewrite, Tools::link_rewrite($value)); - $this->prepareLangField($category->meta_keywords, implode(',', explode(' ', $value))); - - $category->active = true; - $category->is_root_category = 0; - $category->position = 0; - $category->id_parent = $parent_id; - $category->level_depth = $level_depth; - - try { - $category->save(); - } catch (PrestaShopException $msg) { - PShow_Log::add(pathinfo(PShow_Import::getInstance()->filepath, PATHINFO_FILENAME) . ".log", "Error in importing category: " . $msg->getMessage()); - } - $c_id = $category->id; - $parent_id = $c_id; - $level_depth += 1; - } else { - $cat = $category; - - if (!array_key_exists('id_category', $cat)) { - $cat = reset($category); - } - - $c_id = $cat['id_category']; - $parent_id = $c_id; - } - - if (PShow_Config::isChecked('addToParentCategoriesInPath')) { - $this->addProductToCategories(array($parent_id)); - } - - $thisObject->id_category_default = $parent_id; - } - - $this->addProductToCategories(array($parent_id)); - } - - break; - - case 'single_image0': - - if (Tools::getValue('debug')) { - return; - } - - $this->checkAndMergeValues($value, true); - - if (PShow_Config::isChecked('imgNotForExisting', null, false, $i) && $this->object_status == self::STATUS_EXISTS) { - PShow_Log::addImportLog("Image not imported because selected option `imgNotForExisting`: " . $value[$i]); - continue; - } - - if (empty($value)) { - return; - } - - if (PShow_Config::isChecked('imgNotForAlreadyHas') && $this->object_status == self::STATUS_EXISTS && $this->product_img_count) { - PShow_Log::addImportLog("Image not imported because selected option `imgNotForAlreadyHas`: " . $value); - return; - } - - $img_path = $value; - - // check: image exists - $headers = PShow_File::isImage($img_path); - if (!$headers) { - PShow_Log::addImportLog("Error in importing image from url: " . $img_path); - return; - } - $img_path = $headers['url']; - - $img = new Image(); - $img->id_product = $thisObject->id; - - $product_images = Db::getInstance()->ExecuteS( - 'SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` - WHERE `id_product` = ' . (int) $thisObject->id); - - $img->cover = 1; - $img->legend = $thisObject->name; - - try { - Db::getInstance()->query( - 'UPDATE `' . _DB_PREFIX_ . 'image` - SET `cover` = 0 - WHERE `id_product` = ' . (int) $thisObject->id); - - $img->save(); - } catch (PrestaShopException $e) { - PShow_Log::addExceptionLog($e); - } - - $img->createImgFolder(); - - $images_path = $img->getPathForCreation(); - - $updateGenThumbnails = PShow_Config::isChecked('updateGenThumbnails'); - - PShow_File::import_image( - $img_path, $images_path, PShow_Config::get('image_quality', 'intval', true), $updateGenThumbnails, pathinfo(PShow_Import::getInstance()->filepath, PATHINFO_FILENAME) . ".log" - ); - - break; - - case 'image': - - if (Tools::getValue('debug')) - return; - - $this->checkAndMergeValues($value); - - for ($i = 0; $i < count($value); ++$i) { - - if (empty($value[$i])) { - continue; - } - - if (PShow_Config::isChecked('imgNotForExisting', null, false, $i) && $this->object_status == self::STATUS_EXISTS) { - PShow_Log::addImportLog("Image not imported because selected option `imgNotForExisting`: " . $value[$i]); - continue; - } - - if (PShow_Config::isChecked('imgNotForAlreadyHas', null, false, $i) && $this->object_status == self::STATUS_EXISTS && $this->product_img_count) { - PShow_Log::addImportLog("Image not imported because selected option `imgNotForAlreadyHas`: " . $value[$i]); - continue; - } - - $img_pathes = array($value[$i]); - - foreach ($img_pathes as $img_path) { - - // check: image exists - $headers = PShow_File::isImage($img_path); - if (!$headers) { - PShow_Log::addImportLog("Error in importing image from url: " . $img_path); - continue; - } - $img_path = $headers['url']; - - $img = new Image(); - $img->id_product = $thisObject->id; - $img->legend = $thisObject->name; - - $product_images = Db::getInstance()->ExecuteS( - 'SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` - WHERE `id_product` = ' . (int) $thisObject->id); - - if (!$product_images || count($product_images) == 0) { - $img->cover = 1; - } - - try { - $img->save(); - } catch (PrestaShopException $e) { - PShow_Log::addExceptionLog($e); - continue; - } - - $img->createImgFolder(); - - $images_path = $img->getPathForCreation(); - - $updateGenThumbnails = PShow_Config::isChecked('updateGenThumbnails'); - - PShow_File::import_image( - $img_path, $images_path, PShow_Config::get('image_quality'), $updateGenThumbnails, pathinfo(PShow_Import::getInstance()->filepath, PATHINFO_FILENAME) . ".log" - ); - } - } - - break; - - case 'carrier': - - $this->checkAndMergeValues($value); - - if (is_array($value)) { - $value = implode(',', $value); - } - - if (empty($value)) { - return; - } - - $value = preg_replace("([a-zA-Z\ ]+)", null, $value); - $carrier_list = preg_replace("([,,]+)", ",", $value); - - $ids = explode(',', $carrier_list); - $references = array(); - foreach ($ids as $id) { - $id_reference = Db::getInstance()->getValue('' - . 'SELECT `id_reference` ' - . 'FROM `' . _DB_PREFIX_ . 'carrier` ' - . 'WHERE `id_carrier` = ' . (int) $id); - - if (!$id_reference) { - continue; - } - - $references[] = (int) $id_reference; - } - - $thisObject->setCarriers($references); - - break; - - case 'images': - - if (Tools::getValue('debug')) - return; - - $this->checkAndMergeValues($value); - - PShow_Log::addImportLog("importing separated images: " . implode(' & ', $value)); - - for ($i = 0; $i < count($value); ++$i) { - - if (empty($value[$i])) { - continue; - } - - if (PShow_Config::isChecked('imgNotForExisting', null, false, $i) && $this->object_status == self::STATUS_EXISTS) { - PShow_Log::addImportLog("Image not imported because selected option `imgNotForExisting`: " . $value[$i]); - continue; - } - - if (PShow_Config::isChecked('imgNotForAlreadyHas', null, false, $i) && $this->object_status == self::STATUS_EXISTS && $this->product_img_count) { - PShow_Log::addImportLog("Image not imported because selected option `imgNotForAlreadyHas`: " . $value[$i]); - continue; - } - - $separator = PShow_Config::get('images_separator', null, false, $i); - - if (!$separator || empty($separator)) { - PShow_Log::addImportLog("separator not found for value: " . $value[$i]); - continue; - } - - $img_pathes = explode($separator, $value[$i]); - - if (!is_array($img_pathes)) { - PShow_Log::addImportLog("unable to separate img pathes (" . $value[$i] . ") using separator (" . $separator . ")"); - continue; - } - - foreach ($img_pathes as $img_path) { - // check: image exists - $headers = PShow_File::isImage($img_path); - if (!$headers) { - PShow_Log::add(pathinfo(PShow_Import::getInstance()->filepath, PATHINFO_FILENAME) . ".log", "Error in importing image from url: " . $img_path); - return; - } - $img_path = $headers['url']; - - $img = new Image(); - $img->id_product = $thisObject->id; - $img->legend = $thisObject->name; - - $product_images = Db::getInstance()->ExecuteS( - 'SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image` - WHERE `id_product` = ' . (int) $thisObject->id); - - if (!$product_images || count($product_images) == 0) { - $img->cover = 1; - } - - try { - $img->save(); - } catch (PrestaShopException $e) { - PShow_Log::addExceptionLog($e); - } - - $img->createImgFolder(); - - $images_path = $img->getPathForCreation(); - - $updateGenThumbnails = PShow_Config::isChecked('updateGenThumbnails'); - - PShow_File::import_image( - $img_path, $images_path, PShow_Config::get('image_quality'), $updateGenThumbnails, pathinfo(PShow_Import::getInstance()->filepath, PATHINFO_FILENAME) . ".log" - ); - } - } - - break; - - case 'description_short_without_html': - - $this->checkAndMergeValues($value, true); - - $value = strip_tags($value); - - $value = str_replace(array('\n', '\r'), null, $value); -// $value = str_replace(array('\n', '
'), '
', $value); -// $value = str_replace('', $value); - $value = str_replace('\"', '"', $value); - - $this->prepareLangField($thisObject->description_short, $value); - - break; - - case 'description_short': - - $this->checkAndMergeValues($value, true); - - $value = htmlspecialchars_decode($value); - - if (PShow_Config::get('insert_newline_tags', 'boolval')) { - $value = nl2br($value); - } - - $value = str_replace(array('\n', '\r'), null, $value); - $value = str_replace('', $value); - $value = str_replace('\"', '"', $value); - - $this->prepareLangField($thisObject->description_short, $value); - - break; - - case 'description_without_html': - - $this->checkAndMergeValues($value, true); - - $value = strip_tags($value); - - $value = str_replace(array('\n', '\r'), null, $value); -// $value = str_replace(array('\n', '
'), '
', $value); -// $value = str_replace('', $value); - $value = str_replace('\"', '"', $value); - - $this->prepareLangField($thisObject->description, $value); - - break; - - case 'description': - - $this->checkAndMergeValues($value, true); - - $value = htmlspecialchars_decode($value); - - if (PShow_Config::get('insert_newline_tags', 'boolval')) { - $value = nl2br($value); - } - - $value = str_replace(array('\n', '\r'), null, $value); - $value = str_replace('', $value); - $value = str_replace('\"', '"', $value); - - $this->prepareLangField($thisObject->description, $value); - - break; - - default: - $this->checkAndMergeValues($value, true); - - if (array_key_exists($key, $classname::$definition['fields']) && array_key_exists('lang', $classname::$definition['fields'][$key])) { - $this->prepareLangField($thisObject->{$key}, $value); - } else { - $thisObject->$key = $value; - } - - break; - } - } - - /** - * getOrCreateTaxRulesGroup() - * - * This function try find rules group with $value tax rate - * or create own rules group and return id. - * - * @param float $value_ - * @return int - */ - public function getOrCreateTaxRulesGroup($value_) - { - $value = preg_replace('/[^0-9\.\,]/', '', $value_); - - $q = "SELECT trg.`id_tax_rules_group` " - . "FROM `" . _DB_PREFIX_ . "tax_rules_group` trg " - . "LEFT JOIN `" . _DB_PREFIX_ . "tax_rule` tr " - . " ON (tr.`id_tax_rules_group` = trg.`id_tax_rules_group`) " - . "LEFT JOIN `" . _DB_PREFIX_ . "tax` t " - . " ON (t.`id_tax` = tr.`id_tax`) " - . "WHERE t.`rate` = " . $value . " "; - - $idTaxRulesGroup = Db::getInstance()->getValue($q); - - if (!$idTaxRulesGroup) { - try { - $tax = new Tax(null, null, PShow_Import::getInstance()->id_shop); - - $this->prepareLangField($tax->name, $value . "%"); - - $tax->rate = $value; - $tax->active = true; - $tax->deleted = false; - $tax->add(); - - $taxRulesGroup = new TaxRulesGroup(null, null, PShow_Import::getInstance()->id_shop); - $taxRulesGroup->name = $value . "%"; - $taxRulesGroup->active = true; - $taxRulesGroup->deleted = false; - $taxRulesGroup->add(); - - $taxRule = new TaxRule(null, null, PShow_Import::getInstance()->id_shop); - $taxRule->id_tax_rules_group = $taxRulesGroup->id; - $taxRule->id_country = 0; - $taxRule->id_tax = $tax->id; - $taxRule->add(); - - $idTaxRulesGroup = $taxRulesGroup->id; - } catch (PrestaShopException $msg) { - - } - } - - return $idTaxRulesGroup; - } - - /** - * Activate product only in selected shops and deactivate product in other - * - * @param int $id_product_ - * @param array $id_shops_ - * @return boolean - */ - public static function activateProductOnlyInSelectedShops($id_product_, array $id_shops_) - { - $id_product = intval($id_product_); - - if (!$id_product) { - return false; - } - - $id_shops = array_map('intval', $id_shops_); - - $q = "UPDATE `" . _DB_PREFIX_ . "product_shop` " - . "SET `active` = 0 " - . "WHERE `id_product` = " . (int) $id_product . "; "; - - foreach ($id_shops as $id_shop) { - $q .= "UPDATE `" . _DB_PREFIX_ . "product_shop` " - . "SET `active` = 1 " - . "WHERE `id_product` = " . (int) $id_product . " " - . "AND `id_shop` = " . (int) $id_shop . "; "; - PShow_Log::addImportLog("activate product in shop #" . $id_shop); - } - - $result &= Db::getInstance()->execute($q); - - return $result; - } -} diff --git a/override/classes/Combination.php b/override/classes/Combination.php new file mode 100644 index 00000000..dcd14fbc --- /dev/null +++ b/override/classes/Combination.php @@ -0,0 +1,36 @@ + 'product_attribute', + 'primary' => 'id_product_attribute', + 'fields' => array( + 'id_product' => array('type' => self::TYPE_INT, 'shop' => 'both', 'validate' => 'isUnsignedId', 'required' => true), + 'location' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64), + 'ean13' => array('type' => self::TYPE_STRING, 'validate' => 'isEan13', 'size' => 13), + 'upc' => array('type' => self::TYPE_STRING, 'validate' => 'isUpc', 'size' => 12), + 'quantity' => array('type' => self::TYPE_INT, 'validate' => 'isInt', 'size' => 10), + 'reference' => array('type' => self::TYPE_STRING, 'size' => 32), + 'supplier_reference' => array('type' => self::TYPE_STRING, 'size' => 32), + 'description' => array('type' => self::TYPE_HTML, 'size' => 1000000), + + 'wholesale_price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 27), + 'price' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isNegativePrice', 'size' => 20), + 'ecotax' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20), + 'weight' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isFloat'), + 'unit_price_impact' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isNegativePrice', 'size' => 20), + 'minimal_quantity' => array('type' => self::TYPE_INT, 'shop' => true, 'validate' => 'isUnsignedId', 'required' => true), + 'default_on' => array('type' => self::TYPE_BOOL, 'allow_null' => true, 'shop' => true, 'validate' => 'isBool'), + 'available_date' => array('type' => self::TYPE_DATE, 'shop' => true, 'validate' => 'isDateFormat'), + ), + ); + /** + * Constructor + * + * @param int $id_combination + */ +} \ No newline at end of file