first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,380 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
abstract class BaseTabMEP
{
const CHANGE_FOR_PRODUCT = 0;
const CHANGE_FOR_COMBINATION = 1;
public $ids_shop = null;
public $sql_shop = null;
public $context;
protected $combinations;
protected $products;
protected $errors = array();
public function __construct()
{
$this->ids_shop = MassEditTools::getShopIds();
$this->sql_shop = MassEditTools::getSqlShop();
$this->context = Context::getContext();
}
protected function handleRequest()
{
$this->combinations = $this->getCombinationsFromRequest();
$this->products = $this->getProductsFromRequest();
}
public static $positions = array(
CategoryTabMEP::class => '1',
PriceTabMEP::class => '2',
VirtualTabMEP::class => '3',
ActiveTabMEP::class => '4',
ManufacturerTabMEP::class => '5',
AccessoriesTabMEP::class => '6',
SupplierTabMEP::class => '7',
DiscountTabMEP::class => '8',
FeaturesTabMEP::class => '9',
DeliveryTabMEP::class => '10',
ImageTabMEP::class => '11',
DescriptionTabMEP::class => '12',
RuleCombinationTabMEP::class => '13',
AttachmentTabMEP::class => '14',
AdvancedStockManagementTabMEP::class => '15',
QuantityTabMEP::class => '16',
MetaTabMEP::class => '17',
ReferenceTabMEP::class => '18',
CreateproductsTabMEP::class => '19',
CustomizationTabMEP::class => '20',
// CarrierTabMEP::class => '21',
);
public $result = array();
public function apply()
{
$this->result = array();
$t = TransModMEP::getInstance();
$this->handleRequest();
if ($this->checkOptionForCombination()) {
if (count($this->combinations) && $this->checkBeforeChange()) {
$this->result = $this->applyChangeForCombinations($this->combinations);
$this->applyChangeBoth($this->products, $this->getCombinationsIdsFromRequest());
foreach (array_keys($this->combinations) as $id) {
$this->addToReIndexSearch((int)$id);
}
$this->updateDateUpdProducts(array_keys($this->combinations));
} else {
LoggerMEP::getInstance()->error($t->l('No combinations', __FILE__));
}
} else {
if (count($this->products)) {
if ($this->checkBeforeChange()) {
$this->result = $this->applyChangeForProducts($this->products);
$this->applyChangeBoth($this->products, $this->getCombinationsIdsFromRequest());
foreach ($this->products as $id) {
$this->addToReIndexSearch((int)$id);
}
$this->updateDateUpdProducts($this->products);
}
} else {
LoggerMEP::getInstance()->error($t->l('No products', __FILE__));
}
}
if (LoggerMEP::getInstance()->hasError()) {
return array();
} else {
$this->reindexSearch();
return $this->result;
}
}
abstract public function applyChangeForProducts($products);
abstract public function applyChangeForCombinations($products);
abstract public function applyChangeBoth($products, $combinations);
abstract public function getTitle();
public function assignVariables()
{
$variable_features = Feature::getFeatures($this->context->language->id);
foreach ($variable_features as &$variable_feature) {
$variable_feature['values'] = FeatureValue::getFeatureValuesWithLang(
$this->context->language->id,
(int)$variable_feature['id_feature'],
true
);
}
$variables = array(
'languages' => ToolsModuleMEP::getLanguages(false),
'default_form_language' => $this->context->language->id,
'variables' => array(
'currency' => $this->context->currency,
'static' => array(
'{name}' => $this->l('name product'),
'{price}' => $this->l('price final'),
'{manufacturer}' => $this->l('manufacturer'),
'{category}' => $this->l('default category'),
'{reference}' => $this->l('product reference'),
),
'features' => $variable_features,
),
'tab_name' => ToolsModuleMEP::toCamelCase($this->getTabName(), true)
);
return $variables;
}
public function renderTabForm()
{
SmartyMEP::registerSmartyFunctions();
return ToolsModuleMEP::fetchTemplate(
'admin/mass_edit_product/helpers/form/tabs/' . $this->getTabName() . '.tpl',
$this->assignVariables()
);
}
public function checkAvailable()
{
return true;
}
public function checkBeforeChange()
{
return true;
}
public function checkOptionForCombination()
{
return false;
}
protected function getCombinationsFromRequest()
{
$combinations = Tools::getValue('combinations');
$tmp_combinations = array();
if (is_array($combinations) && count($combinations)) {
foreach ($combinations as $combination) {
$combination = explode('_', $combination);
if (!array_key_exists((int)$combination[0], $tmp_combinations)) {
$tmp_combinations[(int)$combination[0]] = array();
}
$tmp_combinations[(int)$combination[0]][] = (int)$combination[1];
}
}
$combinations = $tmp_combinations;
return $combinations;
}
public function getCombinationsIdsFromRequest()
{
$products = $this->getCombinationsFromRequest();
$combinations = array();
foreach ($products as $c) {
$combinations = array_merge($combinations, $c);
}
return $combinations;
}
protected function getProductsFromRequest()
{
$products = Tools::getValue('products');
$ids_product = array();
if (is_array($products) && count($products)) {
foreach ($products as $product) {
$ids_product[] = (int)$product['id'];
}
}
return $ids_product;
}
public static $disabled = null;
public static $enabled = null;
public function cacheDisabled()
{
if (is_null(self::$disabled)) {
$disabled = Tools::getValue('disabled');
self::$disabled = (is_array($disabled) && count($disabled) ? $disabled : array());
}
}
// fix enabled TODO
public function cacheEnabled()
{
if (is_null(self::$enabled)) {
$enabled = Tools::getValue('enabled_feature_fix');
self::$enabled = (is_array($enabled) && count($enabled) ? $enabled : array());
}
}
public function checkAccessField($field)
{
$this->cacheDisabled();
if (in_array($field, self::$disabled)) {
return false;
}
return true;
}
/**
* @return array
*/
public function getEnabledFeatures()
{
$this->cacheEnabled();
return self::$enabled;
}
public $trigger_update_date_upd = false;
public function updateDateUpdProducts($ids, $date_upd = null)
{
if (!Tools::getValue('change_date_upd')) {
return false;
}
if ($this->trigger_update_date_upd) {
return false;
}
if (is_null($date_upd)) {
$date_upd = date('Y-m-d H:i:s');
}
Db::getInstance()->update(
'product',
array('date_upd' => $date_upd),
' id_product IN(' . pSQL(implode(',', array_map('intval', $ids))) . ')'
);
Db::getInstance()->update(
'product_shop',
array(
'date_upd' => $date_upd,
),
' id_product IN(' . pSQL(implode(',', array_map('intval', $ids))) . ')'
. (Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop ' . pSQL($this->sql_shop) : '')
);
$this->trigger_update_date_upd = true;
}
public function updateDateUpdProduct($id, $date_upd = null)
{
if (!Tools::getValue('change_date_upd')) {
return false;
}
if (is_null($date_upd)) {
$date_upd = date('Y-m-d H:i:s');
}
MassEditTools::updateObjectField('Product', 'date_upd', $id, $date_upd);
}
public $reindex_products = array();
public function addToReIndexSearch($ids_product)
{
if ((int)Tools::getValue('reindex_products')) {
if (is_array($ids_product) && count($ids_product)) {
$this->reindex_products = array_merge($this->reindex_products, $ids_product);
} else {
$this->reindex_products[] = $ids_product;
}
$this->reindex_products = array_unique($this->reindex_products);
}
}
public function reindexSearch()
{
if ((int)Tools::getValue('reindex_products')) {
$this->reindexProducts($this->reindex_products);
}
if (is_array($this->reindex_products) && count($this->reindex_products)) {
SpecificPriceRule::applyAllRules($this->reindex_products);
}
}
/**
* @param $ids_product
* @throws PrestaShopException
*/
public function reindexProducts($ids_product)
{
if (is_array($ids_product) && count($ids_product)) {
foreach ($ids_product as $id_product) {
Search::indexation(false, (int)$id_product);
Hook::exec('actionIndexProduct', array('product' => $id_product));
}
}
}
public function getIntvalArrayRequest($name)
{
$var = Tools::getValue($name);
if (!is_array($var)) {
return false;
}
foreach ($var as &$item) {
$item = (int)$item;
}
return $var;
}
public function getAttributes()
{
return array();
}
public function getPosition()
{
$class_name = get_class($this);
return (isset(self::$positions[$class_name]) ? self::$positions[$class_name] : 90000);
}
public function getTabName()
{
$class_name = get_class($this);
$tab = str_replace('TabMEP', '', $class_name);
return Tools::toUnderscoreCase($tab);
}
public function l($string)
{
return TransModMEP::getInstance()->l($string, Tools::strtolower(get_class($this)));
}
}

View File

@@ -0,0 +1,896 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class MassEditTools
{
public static function getTotalFeatures()
{
return Db::getInstance()->getValue('SELECT COUNT(f.id_feature) FROM `' . _DB_PREFIX_ . 'feature` f');
}
const ACTION_QUANTITY_INCREASE = 1;
const ACTION_QUANTITY_REDUCE = 2;
const ACTION_QUANTITY_REWRITE = 3;
const LIMIT_FEATURES = 30;
/**
* @param $id_lang
* @param bool $with_shop
* @param $p
*
* @return mixed
*/
public static function getFeatures($id_lang, $with_shop = true, $p = 1, $with_values = false)
{
$features = Db::getInstance()->executeS('
SELECT DISTINCT f.id_feature, f.*, fl.*
FROM `' . _DB_PREFIX_ . 'feature` f
' . ($with_shop ? Shop::addSqlAssociation('feature', 'f') : '') . '
LEFT JOIN `' . _DB_PREFIX_ . 'feature_lang` fl ON (f.`id_feature` = fl.`id_feature`
AND fl.`id_lang` = ' . (int)$id_lang . ')
ORDER BY f.`position` ASC LIMIT ' . (($p - 1) * self::LIMIT_FEATURES) . ', ' . (int)self::LIMIT_FEATURES);
if (is_array($features) && count($features) && $with_values) {
foreach ($features as &$feature) {
$feature['values'] = FeatureValue::getFeatureValuesWithLang(
Context::getContext()->language->id,
$feature['id_feature']
);
}
}
return $features;
}
public static function setQuantity(
$id_product,
$id_product_attribute,
$quantity,
$action_quantity,
$id_shop = null,
$location = null
) {
if (!Validate::isUnsignedId($id_product)) {
return false;
}
$context = Context::getContext();
// if there is no $id_shop, gets the context one
if ($id_shop === null && Shop::getContext() != Shop::CONTEXT_GROUP) {
$id_shop = (int)$context->shop->id;
}
$depends_on_stock = StockAvailable::dependsOnStock($id_product);
//Try to set available quantity if product does not depend on physical stock
if (!$depends_on_stock) {
$id_stock_available =
(int)StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
if ($id_stock_available) {
$stock_available = new StockAvailable($id_stock_available);
if ($action_quantity === self::ACTION_QUANTITY_INCREASE) {
$quantity = $stock_available->quantity + (int)$quantity;
} elseif ($action_quantity === self::ACTION_QUANTITY_REDUCE) {
$quantity = $stock_available->quantity - (int)$quantity;
}
$stock_available->quantity = (int)$quantity;
$stock_available->location = $location;
$stock_available->update();
} else {
$out_of_stock = StockAvailable::outOfStock($id_product, $id_shop);
$stock_available = new StockAvailable();
$stock_available->out_of_stock = (int)$out_of_stock;
$stock_available->id_product = (int)$id_product;
$stock_available->id_product_attribute = (int)$id_product_attribute;
if ($action_quantity === self::ACTION_QUANTITY_INCREASE) {
$quantity = $stock_available->quantity + (int)$quantity;
} elseif ($action_quantity === self::ACTION_QUANTITY_REDUCE) {
$quantity = $stock_available->quantity - (int)$quantity;
}
$stock_available->quantity = (int)$quantity;
$stock_available->location = $location;
if ($id_shop === null) {
$shop_group = Shop::getContextShopGroup();
} else {
$shop_group = new ShopGroup((int)Shop::getGroupFromShop((int)$id_shop));
}
// if quantities are shared between shops of the group
if ($shop_group->share_stock) {
$stock_available->id_shop = 0;
$stock_available->id_shop_group = (int)$shop_group->id;
} else {
$stock_available->id_shop = (int)$id_shop;
$stock_available->id_shop_group = 0;
}
$stock_available->add();
}
Hook::exec(
'actionUpdateQuantity',
array(
'id_product' => $id_product,
'id_product_attribute' => $id_product_attribute,
'quantity' => $stock_available->quantity
)
);
}
Cache::clean('StockAvailable::getQuantityAvailableByProduct_' . (int)$id_product . '*');
return $quantity;
}
public static function updatePriceProduct($id_product, $price)
{
if (!Shop::isFeatureActive()) {
Db::getInstance()->update('product', array(
'price' => ($price < 0 ? 0 : (float)$price)
), ' id_product = ' . (int)$id_product);
}
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product_shop` ps
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON ps.`id_product` = p.`id_product`
SET ps.`price` = ' . ($price < 0 ? 0 : (float)$price) . '
WHERE ps.`id_product` = ' . (int)$id_product . '
' . (Shop::isFeatureActive() && self::getSqlShop() ? ' AND ps.`id_shop` ' . self::getSqlShop() : ''));
}
public static function updateWholePriceProduct($id_product, $price)
{
if (!Shop::isFeatureActive()) {
Db::getInstance()->update('product', array(
'wholesale_price' => ($price < 0 ? 0 : (float)$price)
), ' id_product = ' . (int)$id_product);
}
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product_shop` ps
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON ps.`id_product` = p.`id_product`
SET ps.`wholesale_price` = ' . ($price < 0 ? 0 : (float)$price) . '
WHERE ps.`id_product` = ' . (int)$id_product . '
' . (Shop::isFeatureActive() && self::getSqlShop() ? ' AND ps.`id_shop` ' . self::getSqlShop() : ''));
}
public static function updatePriceCombination($id_product_attribute, $price)
{
if (!Shop::isFeatureActive()) {
Db::getInstance()->update('product_attribute', array(
'price' => (float)$price
), ' id_product_attribute = ' . (int)$id_product_attribute);
}
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product_attribute_shop` pas
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON pas.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = pa.`id_product`
SET pas.`price` = ' . (float)$price . '
WHERE pas.`id_product_attribute` = ' . (int)$id_product_attribute
. (Shop::isFeatureActive() && self::getSqlShop() ? ' AND pas.`id_shop` ' . self::getSqlShop() : ''));
}
public static function updateWholePriceCombination($id_product_attribute, $price)
{
if (!Shop::isFeatureActive()) {
Db::getInstance()->update('product_attribute', array(
'wholesale_price' => ($price < 0 ? 0 : (float)$price)
), ' id_product_attribute = ' . (int)$id_product_attribute);
}
Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'product_attribute_shop` pas
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON pas.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.`id_product` = pa.`id_product`
SET pas.`wholesale_price` = ' . ($price < 0 ? 0 : (float)$price) . '
WHERE pas.`id_product_attribute` = ' . (int)$id_product_attribute
. (Shop::isFeatureActive() && self::getSqlShop() ? ' AND pas.`id_shop` ' . self::getSqlShop() : ''));
}
public static function getCombinationsByIds($ids_combinations, $id_shop)
{
if (!is_array($ids_combinations) || (is_array($ids_combinations) && !count($ids_combinations))) {
return array();
}
$combinations = Db::getInstance()->executeS('SELECT
pa.`id_product`,
pa.`id_product_attribute`,
pa.`wholesale_price`,
sa.`quantity`,
pss.`price` as `product_price`,
pas.`price`,
(pas.`price` + pss.`price`) as total_price
FROM ' . _DB_PREFIX_ . 'product_attribute pa
LEFT JOIN ' . _DB_PREFIX_ . 'product p ON p.`id_product` = pa.`id_product`
LEFT JOIN `' . _DB_PREFIX_ . 'product_shop` pss ON (pa.`id_product` = pss.`id_product`
AND pss.id_shop = ' . pSQL($id_shop) . ')
LEFT JOIN ' . _DB_PREFIX_ . 'tax_rules_group trg ON trg.`id_tax_rules_group` = pss.`id_tax_rules_group`
LEFT JOIN ' . _DB_PREFIX_ . 'tax t ON t.`id_tax` = pss.`id_tax_rules_group`
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas
ON pas.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'stock_available sa ON sa.`id_product_attribute` = pa.`id_product_attribute`
AND sa.`id_shop` = ' . pSQL($id_shop) . '
WHERE pa.`id_product_attribute`
IN (' . pSQL(implode(',', array_map('intval', $ids_combinations))) . ')
AND pas.`id_shop` = ' . pSQL($id_shop) . '
GROUP BY pa.`id_product_attribute`');
$country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'));
$address = new Address();
$address->id_country = $country->id;
foreach ($combinations as &$combination) {
if ((int)Configuration::get('PS_TAX')) {
$tax_manager = TaxManagerFactory::getManager(
$address,
Product::getIdTaxRulesGroupByIdProduct(
(int)$combination['id_product'],
Context::getContext()
)
);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$combination['product_price_final'] = $product_tax_calculator->addTaxes($combination['product_price']);
$combination['price_final'] = $product_tax_calculator->addTaxes($combination['price']);
$combination['total_price_final'] =
$product_tax_calculator->addTaxes($combination['price'] + $combination['product_price']);
$combination['rate'] = $tax_manager->getTaxCalculator()->getTotalRate();
} else {
$combination['product_price_final'] = $combination['product_price'];
$combination['price_final'] = $combination['price'];
$combination['total_price_final'] = $combination['price'] + $combination['product_price'];
$combination['rate'] = 0;
}
}
return $combinations;
}
const ACTION_PRICE_INCREASE_PERCENT = 1;
const ACTION_PRICE_INCREASE = 2;
const ACTION_PRICE_REDUCE_PERCENT = 3;
const ACTION_PRICE_REDUCE = 4;
const ACTION_PRICE_REWRITE = 5;
public static function actionPrice($price, $action_price, $price_value)
{
switch ($action_price) {
case self::ACTION_PRICE_INCREASE_PERCENT:
$price += ($price * ($price_value / 100));
break;
case self::ACTION_PRICE_INCREASE:
$price += $price_value;
break;
case self::ACTION_PRICE_REDUCE_PERCENT:
$price -= ($price * ($price_value / 100));
break;
case self::ACTION_PRICE_REDUCE:
$price -= $price_value;
break;
case self::ACTION_PRICE_REWRITE:
$price = $price_value;
break;
}
return $price;
}
public static function actionPriceRound($price, $action, $price_value_round)
{
$price_old = $price;
switch ($action) {
case 0:
$price = ceil($price / $price_value_round) * $price_value_round;
break;
case 1:
$price = floor($price / $price_value_round) * $price_value_round;
if ($price == 0) {
$price = $price_old;
}
break;
case 2:
$price = round($price / $price_value_round) * $price_value_round;
break;
}
return $price;
}
public static function updateObjectField($class_name, $field, $id, $value)
{
$definition = ObjectModel::getDefinition($class_name);
$definition_field = ObjectModel::getDefinition($class_name, $field);
$ids_shop = Shop::getContextListShopID();
$multi_shop_active = (int)Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE');
$lang = (array_key_exists('lang', $definition_field) && $definition_field['lang'] ? true : false);
$shop = (array_key_exists('shop', $definition_field) && $definition_field['shop'] ? true : false);
$multi_lang_shop = (array_key_exists('multilang_shop', $definition)
&& $definition['multilang_shop'] ? true : false);
if (!$multi_shop_active || ($lang && $multi_lang_shop) || Shop::getContext() == Shop::CONTEXT_ALL) {
$sql = 'UPDATE ' . _DB_PREFIX_ . $definition['table'] . ($lang ? '_lang' : '');
if ($lang && is_array($value)) {
$languages = Language::getLanguages(false);
$sql .= ' SET `' . pSQL($field) . '` = CASE ' . PHP_EOL;
foreach ($languages as $l) {
if (array_key_exists($l['id_lang'], $value)) {
$sql .= 'WHEN `id_lang` = ' . (int)$l['id_lang'] . ' THEN "' . ObjectModel::formatValue(
$value[$l['id_lang']],
$definition_field['type']
) . '" ' . PHP_EOL;
}
}
$sql .= 'END ';
} else {
$sql .= ' SET `' . pSQL($field) . '` = "' .
ObjectModel::formatValue($value, $definition_field['type']) . '"';
}
$sql .= ' WHERE `' . $definition['primary'] . '` = ' . (int)$id;
if ($multi_shop_active && $lang && $multi_lang_shop) {
$sql .= ' AND `id_shop` IN(' . (count($ids_shop) ?
implode(',', array_map('intval', $ids_shop)) : 'NULL') . ')';
}
Db::getInstance()->execute($sql);
}
if (!$lang && $shop) {
$sql_shop = 'UPDATE ' . _DB_PREFIX_ . $definition['table'] . '_shop';
$sql_shop .= ' SET `' . pSQL($field) . '` = "' .
ObjectModel::formatValue($value, $definition_field['type']) . '"';
$sql_shop .= ' WHERE `' . $definition['primary'] . '` = ' . (int)$id;
if ($multi_shop_active) {
$sql_shop .= ' AND `id_shop` IN(' . (count($ids_shop) ?
implode(',', array_map('intval', $ids_shop)) : 'NULL') . ')';
}
Db::getInstance()->execute($sql_shop);
}
}
public static function getFrontFeaturesStatic($id_lang, $id_product)
{
if (!Feature::isFeatureActive()) {
return array();
}
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT name, value, pf.id_feature, pf.id_feature_value
FROM ' . _DB_PREFIX_ . 'feature_product pf
LEFT JOIN ' . _DB_PREFIX_ . 'feature_lang fl ON (fl.id_feature = pf.id_feature
AND fl.id_lang = ' . (int)$id_lang . ')
LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang fvl ON (fvl.id_feature_value = pf.id_feature_value
AND fvl.id_lang = ' . (int)$id_lang . ')
LEFT JOIN ' . _DB_PREFIX_ . 'feature f ON (f.id_feature = pf.id_feature
AND fl.id_lang = ' . (int)$id_lang . ')
' . Shop::addSqlAssociation('feature', 'f') . '
WHERE pf.id_product = ' . (int)$id_product . '
');
}
public static function renderMetaTag($meta, $id_product, $id_lang)
{
if (!$id_lang) {
$id_lang = Context::getContext()->language->id;
}
$product = new Product($id_product, true, $id_lang);
$replace = array();
$category = new Category($product->id_category_default, $id_lang);
$replace['{category}'] = $category->name;
$manufacturer = Manufacturer::getNameById((int)$product->id_manufacturer);
$replace['{manufacturer}'] = $manufacturer;
if (version_compare(_PS_VERSION_, '1.7.7', '>=')) {
$replace['{price}'] = Tools::getContextLocale(Context::getContext())->formatPrice(
$product->getPrice(),
Context::getContext()->currency->iso_code
);
} else {
$replace['{price}'] = Tools::displayPrice($product->getPrice());
}
$replace['{name}'] = $product->name;
$replace['{title}'] = $product->meta_title;
$replace['{reference}'] = $product->reference;
preg_match_all('/\{feature\_[0-9]+\}/', $meta, $matches);
$feature_matches = (isset($matches[0]) && is_array($matches[0]) ? $matches[0] : array());
foreach ($feature_matches as $fm) {
$replace[$fm] = '';
}
preg_match_all('/\{feature_value\_[0-9]+\}/', $meta, $matches);
$feature_value_matches = (isset($matches[0]) && is_array($matches[0]) ? $matches[0] : array());
foreach ($feature_value_matches as $fm) {
$replace[$fm] = '';
}
$product_features = self::getFrontFeaturesStatic($id_lang, $product->id);
if (Module::isInstalled('seosaextendedfeatures') && Module::isEnabled('seosaextendedfeatures')) {
$sum = "";
$feature_value = "";
$separator = Configuration::get('SEF_SEPARATOR');
}
$x = 0;
foreach ($product_features as $product_feature) {
if ($x != (int)$product_feature['id_feature']) {
$feature_value = "";
}
$feature_match = '{feature_' . (int)$product_feature['id_feature'] . '}';
if (in_array($feature_match, $feature_matches)) {
if (Module::isInstalled('seosaextendedfeatures') && Module::isEnabled('seosaextendedfeatures')) {
$replace[$feature_match] = $product_feature['name'] . ': ';
} else {
if (version_compare(_PS_VERSION_, '1.7.6.2', '>=')) {
if ($replace[$feature_match] == "") {
$replace[$feature_match] = $product_feature['name'] . ': ';
}
$replace[$feature_match] = $replace[$feature_match] . ',' . $product_feature['value'];
} else {
$replace[$feature_match] = $product_feature['name'] . ': ' . $product_feature['value'];
}
}
}
$feature_value_match = '{feature_value_' . (int)$product_feature['id_feature'] . '}';
if (in_array($feature_value_match, $feature_value_matches)) {
if (Module::isInstalled('seosaextendedfeatures') && Module::isEnabled('seosaextendedfeatures')) {
if ($x == 0 || $x == (int)$product_feature['id_feature']) {
if (empty($sum)) {
$sum = $product_feature['value'];
} else {
$sum = $sum . $separator . $product_feature['value'];
}
} else {
$sum = $product_feature['value'];
}
} else {
if (version_compare(_PS_VERSION_, '1.7.6.2', '>=')) {
if ($replace[$feature_value_match] == "") {
$replace[$feature_value_match] = $product_feature['value'];
} else {
$replace[$feature_value_match] =
$replace[$feature_value_match] . ',' . $product_feature['value'];
}
} else {
$replace[$feature_value_match] = $product_feature['value'];
}
}
}
if (Module::isInstalled('seosaextendedfeatures') && Module::isEnabled('seosaextendedfeatures')) {
//$replace[$feature_value_match] = substr($sum, 1);
$replace[$feature_value_match] = $sum;
}
if (Module::isInstalled('seosaextendedfeatures') && Module::isEnabled('seosaextendedfeatures')) {
if (in_array($feature_match, $feature_matches)) {
$feature_value = $feature_value . $separator . $product_feature['value'];
$replace[$feature_value_match] = Tools::substr($feature_value, 1);
$replace[$feature_match] = $replace[$feature_match] ;
}
}
$x = (int)$product_feature['id_feature'];
}
$str = str_replace(array_keys($replace), array_values($replace), $meta);
if (version_compare(_PS_VERSION_, '1.7.6.2', '>=')) {
$str = preg_replace('/: ,/', ': ', $str);
}
return $str;
}
public static function buildSQLSearchWhereFromQuery($query, $detailed_search, $field)
{
if (!$query || !$field) {
return '1';
}
if ((int)$detailed_search) {
return $field . ' LIKE "%' . pSQL($query) . '%"';
} else {
$sql_where = array();
$words = explode(' ', $query);
foreach ($words as $word) {
$sql_where[] = $field . ' LIKE "%' . pSQL($word) . '%"';
}
return implode(' AND ', $sql_where);
}
}
public static function removeTmpImageProduct($id_product)
{
if (file_exists(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int)$id_product . '_1.jpg')) {
unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int)$id_product . '_1.jpg');
}
}
public static function deleteFeatures($id_product, $ids_feature = array())
{
// List products features
$features = Db::getInstance()->executeS('
SELECT p.*, f.*
FROM `' . _DB_PREFIX_ . 'feature_product` as p
LEFT JOIN `' . _DB_PREFIX_ . 'feature_value` as f ON (f.`id_feature_value` = p.`id_feature_value`)
WHERE `id_product` = ' . (int)$id_product . (count($ids_feature) ?
' AND p.`id_feature` IN(' . implode(',', array_map('intval', $ids_feature)) . ')' : ''));
foreach ($features as $tab) {
// Delete product custom features
if ($tab['custom']) {
Db::getInstance()->execute('
DELETE FROM `' . _DB_PREFIX_ . 'feature_value`
WHERE `id_feature_value` = ' . (int)$tab['id_feature_value']);
Db::getInstance()->execute('
DELETE FROM `' . _DB_PREFIX_ . 'feature_value_lang`
WHERE `id_feature_value` = ' . (int)$tab['id_feature_value']);
}
}
// Delete product features
$result = Db::getInstance()->execute('
DELETE FROM `' . _DB_PREFIX_ . 'feature_product`
WHERE `id_product` = ' . (int)$id_product . (count($ids_feature) ?
' AND `id_feature` IN(' . implode(',', array_map('intval', $ids_feature)) . ')' : ''));
SpecificPriceRule::applyAllRules(array((int)$id_product));
return ($result);
}
public static function clearTmpFolder()
{
$files = glob(self::getPath() . '*.jpg');
if (is_array($files) && count($files)) {
foreach ($files as $file) {
if (file_exists($file)) {
unlink($file);
}
}
}
}
public static function getPath()
{
return _PS_MODULE_DIR_ . 'masseditproduct/tmp/';
}
public static function checkImage($image, $key)
{
$image_item = $_FILES[$image]['tmp_name'][$key];
if (function_exists('exif_imagetype')) {
$check_image = in_array(exif_imagetype($image_item), array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG));
} elseif (function_exists('finfo_open')) {
$check_image = false;
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$file_info = finfo_file($finfo, $image_item);
foreach (array('image/jpeg', 'image/gif', 'image/png') as $type) {
if (strpos($file_info, $type)) {
$check_image = true;
break;
}
}
} else {
$check_image = true;
}
if (array_key_exists($image, $_FILES)
&& !empty($_FILES[$image]['tmp_name'][$key])
&& $check_image) {
return true;
} else {
return false;
}
}
public static function attachToProduct($id_product, $array, $remove_old = false)
{
if ($remove_old) {
$result1 = Attachment::deleteProductAttachments($id_product);
} else {
$attachments = Attachment::getAttachments(Context::getContext()->language->id, $id_product, true);
if (is_array($attachments)) {
foreach ($attachments as $attachment) {
$key = array_search($attachment['id_attachment'], $array);
if ($key !== false) {
unset($array[$key]);
}
}
}
$result1 = true;
}
if (is_array($array)) {
$ids = array();
foreach ($array as $id_attachment) {
if ((int)$id_attachment > 0) {
$ids[] = array('id_product' => (int)$id_product, 'id_attachment' => (int)$id_attachment);
}
}
if (!empty($ids)) {
$result2 = Db::getInstance()->insert('product_attachment', $ids);
}
}
Product::updateCacheAttachment((int)$id_product);
if (is_array($array)) {
return ($result1 && (!isset($result2) || $result2));
}
return $result1;
}
public static function getImages($image)
{
if (!array_key_exists($image, $_FILES) || empty($_FILES[$image]['tmp_name'])) {
return array();
}
return $_FILES[$image]['tmp_name'];
}
public static function getSqlShop()
{
$context = Context::getContext();
switch ($context->shop->getContext()) {
case Shop::CONTEXT_SHOP:
return ' = ' . (int)$context->shop->id;
case Shop::CONTEXT_GROUP:
$ids_shop = Shop::getContextListShopID();
return ' IN(' . (count($ids_shop) ? implode(',', $ids_shop) : 'NULL') . ')';
case Shop::CONTEXT_ALL:
return false;
}
return false;
}
public static function getShopIds()
{
return Shop::getContextListShopID();
}
private static $options_number_characters = array(4 => '', 7 => '', 10 => '', 13 => '', 16 => '', 19 => '');
/**
* @param string "0000-00-00 00:00:00"
* @param int 10 - 0000-00-00
*
* @return string "0000-00-00 00:00:00"
*/
public static function roundFromDate($date, $number_characters = 10)
{
if (key_exists($number_characters, self::$options_number_characters)) {
$date = mb_strimwidth($date, 0, $number_characters, '', 'UTF-8');
}
return pSQL($date);
}
/**
* @param string "0000-00-00 00:00:00"
* @param int 10 - 0000-00-00
*
* @return string "0000-00-00 23:59:59"
*/
public static function roundToDate($date, $number_characters = 10)
{
if (key_exists($number_characters, self::$options_number_characters)) {
$date = mb_strimwidth($date, 0, $number_characters, '', 'UTF-8');
$trimmarker =
mb_strimwidth('9999-12-31 23:59:59', $number_characters, 15, '', 'UTF-8');
$date = $date . $trimmarker;
}
return pSQL($date);
}
public static function checkProductOnChoiceAttributes($id_product, $id_product_attribute, $delete_attribute)
{
$attributes = Product::getAttributesParams((int)$id_product, (int)$id_product_attribute);
$ids_attributes = array();
foreach ($attributes as $attribute) {
if ($attribute['id_attribute'] != $delete_attribute) {
$ids_attributes[] = (int)$attribute['id_attribute'];
}
}
$product = new Product();
$product->id = $id_product;
return $product->productAttributeExists($ids_attributes, false, null, true, true);
}
public static function checkProductOnChoiceAttributesReverse($id_product, $id_product_attribute, $add_attribute)
{
$attribute_obj = new Attribute($add_attribute);
$attributes = Product::getAttributesParams((int)$id_product, (int)$id_product_attribute);
$ids_attributes = array();
foreach ($attributes as $attribute) {
if ($attribute_obj->id_attribute_group == (int)$attribute['id_attribute_group']) {
return true;
}
$ids_attributes[] = (int)$attribute['id_attribute'];
}
$ids_attributes[] = $add_attribute;
$product = new Product();
$product->id = $id_product;
return $product->productAttributeExists($ids_attributes, false, null, true);
}
public static function getMinimalQuantityForUpdate($id_product, $quantity, $table, $action_quantity)
{
if ($action_quantity == 3 && $quantity >= 1) {
return $quantity;
}
$field = ($table == 'product_shop') ? 'id_product' : 'id_product_attribute';
$quantity_old = Db::getInstance()->getValue(
'SELECT `minimal_quantity` FROM `' . _DB_PREFIX_ . $table . '`
WHERE ' . pSQL($field) . ' = ' . (int)$id_product
);
if ($action_quantity == 1) {
return $quantity_old + $quantity;
} elseif ($action_quantity == 2 && ($quantity_old - $quantity) >= 1) {
return $quantity_old - $quantity;
} else {
return 1;
}
}
public static function getIdShopSql()
{
return Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP
? (int)Context::getContext()->shop->id : 'p.id_shop_default';
}
public static function getAttributeGroups()
{
$id_lang = Context::getContext()->language->id;
return Db::getInstance()->executeS('SELECT agl.`name`, agl.`id_attribute_group`
FROM `' . _DB_PREFIX_ . 'attribute_group` ag
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl
ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = ' . (int)$id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a
ON a.`id_attribute_group` = ag.`id_attribute_group`
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al
ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . (int)$id_lang . ')
' . Shop::addSqlAssociation('attribute_group', 'ag') . '
' . Shop::addSqlAssociation('attribute', 'a') . '
WHERE a.`id_attribute` IS NOT NULL AND al.`name` IS NOT NULL AND agl.`id_attribute_group` IS NOT NULL
GROUP BY agl.`id_attribute_group`
ORDER BY agl.`name` ASC, a.`position` ASC
');
}
public static function getAttributesByProduct($id_product)
{
return Db::getInstance()->executeS(
'SELECT
pa.`id_product`,
pa.`id_product_attribute`,
sa.`quantity`,
pas.`price`,
pss.`price` as product_price,
(pas.`price` + pss.`price`) as total_price,
agl.`name` as group_name,
al.`name`
FROM ' . _DB_PREFIX_ . 'product_attribute pa
LEFT JOIN ' . _DB_PREFIX_ . 'product p ON p.`id_product` = pa.`id_product`
LEFT JOIN `' . _DB_PREFIX_ . 'product_shop` pss
ON (pa.`id_product` = pss.`id_product` AND pss.id_shop = ' . pSQL(MassEditTools::getIdShopSql()) . ')
LEFT JOIN ' . _DB_PREFIX_ . 'tax_rules_group trg
ON trg.`id_tax_rules_group` = pss.`id_tax_rules_group`
LEFT JOIN ' . _DB_PREFIX_ . 'tax t ON t.`id_tax` = pss.`id_tax_rules_group`
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas
ON pas.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'stock_available sa
ON sa.`id_product_attribute` = pa.`id_product_attribute`
AND sa.`id_shop` = ' . pSQL(MassEditTools::getIdShopSql()) . '
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac
ON pac.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'attribute a
ON a.`id_attribute` = pac.`id_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'attribute_lang al
ON al.`id_attribute` = a.`id_attribute`
AND al.`id_lang` = ' . (int)Context::getContext()->language->id . '
LEFT JOIN ' . _DB_PREFIX_ . 'attribute_group_lang agl
ON agl.`id_attribute_group` = a.`id_attribute_group`
AND agl.`id_lang` = ' . (int)Context::getContext()->language->id . '
WHERE pa.`id_product` = ' . (int)$id_product . ' AND pas.`id_shop` = ' . pSQL(MassEditTools::getIdShopSql())
);
}
public static function getAttributes($id_lang)
{
return Db::getInstance()->executeS(
'SELECT a.`id_attribute`, al.`name` FROM `' . _DB_PREFIX_ . 'attribute` a
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON a.`id_attribute` = al.`id_attribute`
WHERE a.`id_attribute_group` = ' . (int)Tools::getValue('group') . '
AND al.`id_lang` = ' . (int)$id_lang
);
}
public static function renderCombinationsProduct($ids_product)
{
if (!is_array($ids_product)) {
$products = array($ids_product);
} else {
$products = $ids_product;
}
$json = array();
foreach ($products as $id_product) {
$attributes = MassEditTools::getAttributesByProduct($id_product);
$country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'));
$address = new Address();
$address->id_country = $country->id;
$combinations = array();
$product = array();
foreach ($attributes as $attribute) {
$tax_manager = TaxManagerFactory::getManager(
$address,
Product::getIdTaxRulesGroupByIdProduct(
(int)$attribute['id_product'],
Context::getContext()
)
);
$product_tax_calculator = $tax_manager->getTaxCalculator();
if (!array_key_exists(
$attribute['id_product_attribute'],
$combinations
)) {
// Fixme: $product['product_price'] is undefined key!!!
if (!array_key_exists('product_price', $attribute)) {
$product['product_price'] = 0;
}
$combinations[$attribute['id_product_attribute']] = array(
'id_product' => $attribute['id_product'],
'price' => $attribute['price'],
'price_final' => ((int)Configuration::get('PS_TAX')
? $product_tax_calculator->addTaxes($attribute['price']) : $attribute['price']),
'total_price' => $attribute['total_price'],
'total_price_final' =>
((int)Configuration::get('PS_TAX') ?
$product_tax_calculator->addTaxes($attribute['price'] + $attribute['product_price']) :
$attribute['price'] + $attribute['product_price']),
'quantity' => $attribute['quantity'],
'attributes' => $attribute['group_name'] . ': ' . $attribute['name'],
);
} else {
$combinations[$attribute['id_product_attribute']]['attributes']
.= ', ' . $attribute['group_name'] . ': ' . $attribute['name'];
}
}
$currency = Currency::getCurrency(Configuration::get('PS_CURRENCY_DEFAULT'));
$currency = $currency['id_currency'];
$json[$id_product] = ToolsModuleMEP::fetchTemplate(
'admin/mass_edit_product/helpers/form/product_combinations.tpl',
array(
'combinations' => $combinations,
'currency' => $currency,
'id_product' => $id_product,
)
);
}
return (is_array($ids_product) ? $json : $json[$ids_product]);
}
}

View File

@@ -0,0 +1,677 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ProductFinderMEP
{
public $categories;
public $search_only_default_category;
public $search_only_explicit_category;
public $search_query;
public $type_search;
public $manufacturers;
public $suppliers;
public $carrier;
public $features;
public $attributes;
public $no_feature_value;
public $how_many_show;
public $active;
public $disable;
public $no_image;
public $yes_image;
public $no_discount;
public $yes_discount;
public $log_on;
public $page;
public $exclude_ids;
public $product_name_type_search;
public $qty_from;
public $qty_to;
public $date_from;
public $date_to;
public $custom_feature;
public $price_from;
public $price_to;
public $type_visible;
public $orderby;
public $orderway;
public $mode_or;
public $mode_or_at;
public $carrier_mode_or;
public $carrier_pre;
public $percent_discout;
public $value_discout;
const SEARCH_TYPE_NAME = 0;
const SEARCH_TYPE_ID = 1;
const SEARCH_TYPE_REFERENCE = 2;
const SEARCH_TYPE_EAN13 = 3;
const SEARCH_TYPE_UPC = 4;
const SEARCH_TYPE_DESCRIPTION = 5;
const SEARCH_TYPE_DESCRIPTION_SHORT = 6;
protected static $search_type_fields = array(
self::SEARCH_TYPE_NAME => 'pl.`name`',
self::SEARCH_TYPE_ID => 'p.`id_product`',
self::SEARCH_TYPE_REFERENCE => 'p.`reference`',
self::SEARCH_TYPE_EAN13 => 'p.`ean13`',
self::SEARCH_TYPE_UPC => 'p.`upc`',
self::SEARCH_TYPE_DESCRIPTION => 'pl.`description`',
self::SEARCH_TYPE_DESCRIPTION_SHORT => 'pl.`description_short`',
);
const PRODUCT_NAME_TYPE_SEARCH_OCCURRENCE = 'occurrence';
const PRODUCT_NAME_TYPE_SEARCH_EXACT_MATCH = 'exact_match';
protected $context;
protected function __construct()
{
$this->initRequestParams();
$this->context = Context::getContext();
}
protected static $instance = null;
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
protected function initRequestParams()
{
$categories = Tools::getValue('categories');
$this->categories = (is_array($categories) ? $categories : array());
$this->search_only_default_category = Tools::getValue('search_only_default_category');
$this->search_only_explicit_category = Tools::getValue('search_only_explicit_category');
$this->search_query = Tools::getValue('search_query');
$this->type_search = (int)Tools::getValue('type_search', 0);
$manufacturers = Tools::getValue('manufacturers');
$this->manufacturers = ($manufacturers ? array_map('intval', $manufacturers) : array());
$suppliers = Tools::getValue('suppliers');
$this->suppliers = ($suppliers ? array_map('intval', $suppliers) : array());
$carriers = Tools::getValue('carriers');
$this->carriers = ($carriers ? array_map('intval', $carriers) : array());
$this->features = Tools::getValue('features');
$this->attributes = Tools::getValue('attributes');
$this->id_attribute = Tools::getValue('id_attribute');
$this->id_feature = Tools::getValue('id_feature');
$this->no_feature_value = Tools::getValue('no_feature_value');
$this->how_many_show = (int)Tools::getValue('how_many_show', 20);
$this->active = (int)Tools::getValue('active', 0);
$this->disable = (int)Tools::getValue('disable', 0);
$this->no_image = (int)Tools::getValue('no_image', 0);
$this->yes_image = (int)Tools::getValue('yes_image', 0);
$this->no_discount = (int)Tools::getValue('no_discount', 0);
$this->yes_discount = (int)Tools::getValue('yes_discount', 0);
$this->percent_discout = (int)Tools::getValue('percent_discout', 0);
$this->value_discout = (int)Tools::getValue('value_discout', 0);
$this->log_on = (int)Tools::getValue('log_on', 0);
$this->page = (int)Tools::getValue('page', 1);
$this->mode_or = (int)Tools::getValue('mode_or', 0);
$this->carrier_mode_or = (int)Tools::getValue('carrier_mode_or', 0);
$this->carrier_pre = (int)Tools::getValue('carrier_pre', 0);
$this->mode_or_at = (int)Tools::getValue('mode_or_at', 0);
$exclude_ids = Tools::getValue('exclude_ids', array());
$exclude_ids = $exclude_ids ? array_map('intval', $exclude_ids) : array();
$this->exclude_ids = $exclude_ids;
$this->product_name_type_search = Tools::getValue('product_name_type_search');
$this->qty_from = Tools::getValue('qty_from');
$this->qty_to = Tools::getValue('qty_to');
$this->date_from = Tools::getValue('date_from');
$this->date_to = Tools::getValue('date_to');
$this->custom_feature = Tools::getValue('custom_feature');
$this->type_price = Tools::getValue('type_price');
$this->price_from = Tools::getValue('price_from');
$this->price_to = Tools::getValue('price_to');
$this->orderby = Tools::getValue('orderby');
$this->orderway = Tools::getValue('orderway');
$this->type_visible = Tools::getValue('type_visible');
}
public function updateFinalPrice()
{
$result = Db::getInstance()->executeS('SELECT `id_product` FROM `' . _DB_PREFIX_ . 'product_shop`');
$nothing = null;
foreach ($result as $row) {
$final_price = Product::getPriceStatic(
$row['id_product'],
true,
null,
(int)Configuration::get('PS_PRICE_DISPLAY_PRECISION'),
null,
false,
true,
1,
true,
null,
null,
null,
$nothing
);
Db::getInstance()->update('product_shop', array('final_price' => $final_price), 'id_product = '
. $row['id_product']);
}
}
public function findProducts()
{
if ($this->type_price == 1) {
$this->updateFinalPrice();
}
$products = Db::getInstance()->executeS($this->buildSql());
$country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'));
$address = new Address();
$address->id_country = $country->id;
foreach ($products as &$product) {
$nothing = null;
$advanced_stock_management = (bool)Db::getInstance()->getValue(
'
SELECT `advanced_stock_management`
FROM ' . _DB_PREFIX_ . 'product_shop
WHERE id_product=' . (int)$product['id_product'] . Shop::addSqlRestriction()
);
$log_date = Db::getInstance()->executeS(
'SELECT `date_upd`, `message`, `id_employee`
FROM ' . _DB_PREFIX_ . 'log
WHERE object_id = ' . (int)$product['id_product'] . ' AND object_type = \'Product\'');
$count_last = count($log_date)-1;
if ($count_last < 0) {
$date_upd_last ='';
$message_last = '';
$lastname = "";
$firstname = "";
} else {
$date_upd_last = $log_date[$count_last]['date_upd'];
$message_last = $log_date[$count_last]['message'];
$id_employee = $log_date[$count_last]['id_employee'];
$name_employee = Db::getInstance()->getRow(
'SELECT `lastname`, `firstname`
FROM ' . _DB_PREFIX_ . 'employee
WHERE id_employee = ' . (int)$id_employee
);
$lastname = $name_employee['lastname'];
$firstname = $name_employee['firstname'];
}
$product['price_final'] = Product::getPriceStatic(
$product['id_product'],
true,
null,
(int)Configuration::get('PS_PRICE_DISPLAY_PRECISION'),
null,
false,
true,
1,
true,
null,
null,
null,
$nothing
);
$product['advanced_stock_management'] = ((bool)StockAvailable::dependsOnStock(
(int)$product['id_product']
) && $advanced_stock_management);
$product['image'] = ImageManager::thumbnail(
_PS_PROD_IMG_DIR_ . Image::getImgFolderStatic($product['cover']) . $product['cover'] . '.jpg',
'product_mini_' . $product['id_product'] . '_' . $product['cover'] . '.jpg',
45
);
$id_image = Product::getCover($product['id_product']);
$path = Image::getImgFolderStatic($id_image['id_image']);
if (_PS_VERSION_ >= 1.7) {
$full_patch = '../img/p/' . $path . $id_image['id_image'] . '-' .
ImageType::getFormattedName('small') . '.jpg';
} else {
$full_patch = '../img/p/' . $path . $id_image['id_image'].'-'. 'small_default' .'.jpg';
}
$product['image_small'] = $full_patch;
if ($this->log_on) {
$product['log_on'] = $this->log_on;
$product['date_upd'] = $date_upd_last;
$product['message'] = $message_last;
$product['employee'] = $lastname . ' ' . $firstname;
}
$product['url_product'] = $this->context->link->getAdminLink(
'AdminProducts',
true,
['id_product' => $product['id_product']]
).'&id_product='.$product['id_product'].'&updateproduct';
}
$tmp_products = array();
foreach ($products as $prod) {
$tmp_products[$prod['id_product']] = $prod;
}
return $tmp_products;
}
public function getTotal()
{
return (int)Db::getInstance()->getValue($this->buildSql(true));
}
public function buildSql($get_total = false)
{
$sql_category = false;
if (is_array($this->categories) && count($this->categories)) {
$ids_categories = array();
foreach ($this->categories as $category) {
$ids_categories[] = (int)$category['id'];
}
$sql_category = implode(',', $ids_categories);
}
$qty_query = array();
if ($this->qty_from != '') {
$qty_query[] = 'sa.`quantity` >= ' . (int)$this->qty_from;
}
if ($this->qty_to != '') {
$qty_query[] = 'sa.`quantity` <= ' . (int)$this->qty_to;
}
$date_query = array();
if ($this->date_from != '') {
$date_query[] = 'p.`date_add` >= "' . pSQL($this->date_from) . '"';
}
if ($this->date_to != '') {
$date_query[] = 'p.`date_add` <= "' . pSQL($this->date_to) . '"';
}
if ($this->custom_feature != '') {
$date_query[] = 'fvl.`value` = "' . pSQL($this->custom_feature) . '"';
}
$price_query = array();
if ($this->price_from != '') {
if ($this->type_price == 1) {
$price_query[] = 'pss.`final_price` >= ' . (float)$this->price_from;
} else {
$price_query[] = 'pss.`price` >= ' . (float)$this->price_from;
}
}
if ($this->price_to != '') {
if ($this->type_price == 1) {
$price_query[] = 'pss.`final_price` <= ' . (float)$this->price_to;
} else {
$price_query[] = 'pss.`price` <= ' . (float)$this->price_to;
}
}
$sql_manufactures = false;
if (is_array($this->manufacturers) && count($this->manufacturers)) {
$sql_manufactures = implode(',', $this->manufacturers);
}
$sql_suppliers = false;
if (is_array($this->suppliers) && count($this->suppliers)) {
$sql_suppliers = implode(',', $this->suppliers);
}
$sql_carriers = false;
$sql_carriers_count = count($this->carriers);
if (is_array($this->carriers) && count($this->carriers)) {
$sql_carriers = implode(',', $this->carriers);
}
$sql_search_query = false;
if ($this->search_query) {
$hash = array();
switch ($this->type_search) {
case self::SEARCH_TYPE_ID:
$ids = explode(' ', $this->search_query);
$ids = array_map('intval', $ids);
$sql_search_query = '(' . implode(',', $ids) . ')';
$sql_type_search = 'p.`id_product` IN';
$hash[] = 'type_search-1';
break;
case self::SEARCH_TYPE_NAME:
case self::SEARCH_TYPE_REFERENCE:
if ($this->type_search == 2) {
$ids = explode(' ', $this->search_query);
$ids = array_map('strval', $ids);
foreach ($ids as $key => $elem) {
$ids[$key] = "'" . $elem . "'";
}
$sql_search_query = '(' . implode(',', $ids) . ')';
$sql_type_search = 'p.`reference` IN';
$hash[] = 'type_search-1';
break;
}
case self::SEARCH_TYPE_EAN13:
case self::SEARCH_TYPE_UPC:
case self::SEARCH_TYPE_DESCRIPTION:
case self::SEARCH_TYPE_DESCRIPTION_SHORT:
if ($this->product_name_type_search == self::PRODUCT_NAME_TYPE_SEARCH_EXACT_MATCH) {
$sql_search_query = '"' . pSQL($this->search_query) . '"';
} elseif ($this->product_name_type_search == self::PRODUCT_NAME_TYPE_SEARCH_OCCURRENCE) {
if (stripos($this->search_query, '^&&^')) {
$pos = stripos($this->search_query, '^&&^');
$name = Tools::substr($this->search_query, 0, $pos);
$sql_search_query = pSQL($name);
$no_like_pos = $pos + 4;
$no_like = Tools::substr($this->search_query, $no_like_pos);
$sql_search_query = '"%' . pSQL($sql_search_query) . '%"';
$sql_search_query .= ' AND '. self::$search_type_fields[$this->type_search] .
' NOT LIKE ' . '"%' . pSQL($no_like) . '%"';
} else {
$sql_search_query = '"%' . pSQL($this->search_query) . '%"';
}
}
$sql_type_search = self::$search_type_fields[$this->type_search] . ' LIKE ';
break;
default:
throw new LogicException('Unknown search type');
}
$hash[] = 'search_query-' . urlencode($this->search_query);
}
$id_shop = MassEditTools::getIdShopSql();
$order_by = $this->orderby && $this->orderway ? ' ORDER BY ' . $this->orderby . ' ' . $this->orderway : '';
if ($order_by == "") {
$order_by = ' ORDER BY ' . 'id_product' . ' ' . 'ASC';
}
$sql_carriers_no = 1;
if ($sql_carriers == "-1") {
$sql_carriers_no = 0;
}
$select = 'p.`id_product`,
p.reference,
pss.`active`,
pss.`price`,
pl.`name`, pl.`link_rewrite`,
sa.`quantity`,
cl.`name` as category,
m.`name` as manufacturer,
s.`name` as supplier,' . (($sql_carriers !== false) ?
'c.`name` as carrier,' : '') .
'(SELECT i.`id_image` FROM ' . _DB_PREFIX_ . 'image i
WHERE i.`id_product` = p.`id_product`
ORDER BY i.`cover` DESC LIMIT 0,1) cover';
if ($get_total) {
$select = 'COUNT(p.`id_product`)';
}
$sql = 'SELECT
' . $select . '
FROM ' . _DB_PREFIX_ . 'product p
JOIN `' . _DB_PREFIX_ . 'product_shop` pss ON (p.`id_product` = pss.`id_product`
AND pss.id_shop = ' . pSQL($id_shop) . ')
LEFT JOIN ' . _DB_PREFIX_ . 'tax_rules_group trg ON trg.`id_tax_rules_group` = p.`id_tax_rules_group`
LEFT JOIN ' . _DB_PREFIX_ . 'manufacturer m ON m.`id_manufacturer` = p.`id_manufacturer`
LEFT JOIN ' . _DB_PREFIX_ . 'supplier s ON s.`id_supplier` = p.`id_supplier`';
if ($sql_carriers !== false) {
$sql .= 'LEFT JOIN ' . _DB_PREFIX_ . 'product_carrier pc ON pc.`id_product` = p.`id_product`
LEFT JOIN ' . _DB_PREFIX_ . 'carrier c on c.`id_reference` = pc.`id_carrier_reference`';
}
if ($this->no_image == 1 || $this->yes_image == 1) {
$sql .= 'LEFT JOIN ' . _DB_PREFIX_ . 'image pi ON pi.`id_product` = p.`id_product`';
}
if ($this->no_discount == 1 || $this->yes_discount == 1) {
if ($this->percent_discout > 0 || $this->value_discout > 0) {
$sql .= ' LEFT JOIN ' . _DB_PREFIX_ . 'specific_price sp ON sp.`id_product` = p.`id_product`';
if ($this->percent_discout > 0 && $this->value_discout > 0) {
$sql .= ' AND (sp.`reduction` = ' . $this->percent_discout / 100 . ' AND sp.reduction_type = "percentage")
OR (sp.`reduction` = ' . $this->value_discout . ' AND sp.reduction_type = "amount") ';
} elseif ($this->percent_discout > 0 && $this->value_discout == 0) {
$sql .= ' AND sp.`reduction` = ' . $this->percent_discout / 100 . ' AND sp.reduction_type = "percentage"';
} elseif ($this->value_discout > 0 && $this->percent_discout == 0) {
$sql .= ' AND sp.`reduction` = ' . $this->value_discout . ' AND sp.reduction_type = "amount"';
} else {
$sql .= 'LEFT JOIN ' . _DB_PREFIX_ . 'specific_price sp ON sp.`id_product` = p.`id_product`';
}
}
}
if ($this->custom_feature != "") {
$sql .= 'LEFT JOIN `'._DB_PREFIX_.'feature_product` fp ON fp.`id_product` = p.`id_product` ';
$sql .= 'LEFT JOIN `'._DB_PREFIX_.'feature_value_lang` fvl
ON fp.`id_feature_value` = fvl.`id_feature_value` ';
}
if (!empty($this->features) && $this->mode_or == 0) {
$count_features = count($this->features);
}
if (!empty($this->attributes) && $this->mode_or_at == 0) {
$count_attributes = count($this->attributes);
}
$sql .= 'LEFT JOIN ' . _DB_PREFIX_ . 'tax t ON t.`id_tax` = p.`id_tax_rules_group`
LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl ON p.`id_product` = pl.`id_product`
AND pl.`id_lang` = ' . (int)$this->context->language->id . ' AND pl.`id_shop` = ' . pSQL($id_shop) . '
LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON cl.`id_category` = pss.`id_category_default`
AND cl.`id_lang` = ' . (int)$this->context->language->id . ' AND cl.`id_shop` = ' . pSQL($id_shop) . '
LEFT JOIN ' . _DB_PREFIX_ . 'stock_available sa ON (sa.`id_product` = p.`id_product`
AND sa.`id_product_attribute` = 0
' . StockAvailable::addSqlShopRestriction(null, null, 'sa') . ')
WHERE 1
' . ($this->no_image ? 'AND pi.cover = 1' : '') . '
' . ($this->yes_image ? 'AND cover is null and pi.id_product is null' : '') . '
' . ($this->yes_discount && !$this->no_discount ? 'AND sp.id_product = p.id_product' : '') . '
' . ($this->no_discount && !$this->yes_discount ? 'AND sp.id_product is null' : '') . '
' . ($this->type_visible != -1 ? 'AND p.`visibility` =' . '"'. $this->type_visible . '"' : '') . '
' . ($sql_search_query ? 'AND ' . $sql_type_search . ' ' . $sql_search_query . ' ' : '') . '
' . ($sql_category ? ('AND ' . (
$this->search_only_default_category
? 'p.`id_category_default` IN(' . pSQL($sql_category) . ')'
: ($this->search_only_explicit_category ? '0 = (SELECT COUNT(cp.`id_category`)
FROM ' . _DB_PREFIX_ . 'category_product cp
WHERE cp.`id_product` = p.`id_product` AND cp.`id_category` NOT IN(' . pSQL($sql_category) . '))
AND '.count($ids_categories).' = ' : '').'(SELECT COUNT(cp.`id_category`)
FROM ' . _DB_PREFIX_ . 'category_product cp
WHERE cp.`id_product` = p.`id_product` AND cp.`id_category` IN(' . pSQL($sql_category) . '))'
)) : '') . '
' . ($sql_manufactures !== false ? 'AND p.`id_manufacturer` IN(' . pSQL($sql_manufactures) . ')' : '') . '
' . ($sql_suppliers !== false ? 'AND p.`id_supplier` IN(' . pSQL($sql_suppliers) . ')' : '') . '
' . ($sql_carriers !== false && $sql_carriers_no == 1 && $this->carrier_mode_or == 1 ?
'AND c.`id_carrier` IN(' . pSQL($sql_carriers) . ')' : '') . '
' . ($sql_carriers !== false && $sql_carriers_no == 1 && $this->carrier_mode_or == 0 ?
'AND c.`id_carrier` IN(' . pSQL($sql_carriers) . ')
group by p.`id_product` having count(distinct c.`id_carrier`) = ' . $sql_carriers_count : '') . '
' . ($sql_carriers !== false && $sql_carriers_no == 0 ? 'AND c.`name` IS NULL ' : '') . '
' . ($sql_carriers !== false && $this->carrier_pre == 0 ?
'AND (select count(*) from ' . _DB_PREFIX_ . 'product_carrier cv where cv.`id_product` = p.`id_product`)
= '. $sql_carriers_count : '') .'
' . ($this->active && !$this->disable ? ' AND pss.`active` = 1 ' : '') . '
' . ($this->disable && !$this->active ? ' AND pss.`active` = 0 ' : '') . '
' . (is_array($this->features) && count($this->features) && $this->mode_or == 1 ?
'AND (SELECT fp.`id_feature`
FROM ' . _DB_PREFIX_ . 'feature_product fp WHERE fp.`id_product` = p.`id_product`
AND fp.`id_feature_value` IN (' . implode(',', array_map('intval', $this->features)).')
LIMIT 1) ' : '') . '
' . (is_array($this->features) && count($this->features) && $this->mode_or == 0 ?
'AND (SELECT fp.`id_feature`
FROM ' . _DB_PREFIX_ . 'feature_product fp WHERE fp.`id_product` = p.`id_product`
AND fp.`id_feature_value` IN (' . implode(',', array_map('intval', $this->features)).')
GROUP BY fp.`id_product` having count(distinct fp.`id_feature_value`) = '.$count_features.' ) ' : '').'
' . (is_array($this->attributes) && count($this->attributes) && $this->mode_or_at == 1 ?
'AND (SELECT DISTINCT pa.`id_product` FROM `' . _DB_PREFIX_ . 'product_attribute` pa
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac
ON pac.`id_product_attribute` = pa.`id_product_attribute`
WHERE pa.`id_product` = p.`id_product` AND
pac.`id_attribute` IN (' . implode(',', array_map('intval', $this->attributes)) . ')
LIMIT 1) ' : '') . '
' . (is_array($this->attributes) && count($this->attributes) && $this->mode_or_at == 0 ?
'AND (SELECT DISTINCT pa.`id_product` FROM `' . _DB_PREFIX_ . 'product_attribute` pa
LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac
ON pac.`id_product_attribute` = pa.`id_product_attribute`
WHERE pa.`id_product` = p.`id_product` AND
pac.`id_attribute` IN (' . implode(',', array_map('intval', $this->attributes)) . ')
GROUP BY pa.`id_product` having count(distinct pac.`id_attribute`) = '.$count_attributes.' ) ' : '') . '
' . (is_array($this->no_feature_value) && count($this->no_feature_value) ?
'AND NOT (SELECT COUNT(p2.`id_product`)
FROM ' . _DB_PREFIX_ . 'product p2 LEFT JOIN ' . _DB_PREFIX_ . 'feature_product fp2
ON p2.`id_product`=fp2.`id_product`
WHERE fp2.`id_product` = p.`id_product` AND fp2.id_feature
IN(' . implode(',', array_map('intval', $this->no_feature_value)) . ')) ' : '') . '
' . (count($qty_query) ? ' AND ' . implode(' AND ', $qty_query) : '') . '
' . (count($date_query) ? ' AND ' . implode(' AND ', $date_query) : '') . '
' . (count($price_query) ? ' AND ' . implode(' AND ', $price_query) : '') . '
' . (is_array($this->exclude_ids) && count($this->exclude_ids)
? ' AND pss.`id_product` NOT IN(' . pSQL(implode(',', $this->exclude_ids)) . ')' : '') . '
' . (!$get_total
?
//' GROUP BY p.`id_product` '.
$order_by
. ' LIMIT ' . (((int)$this->page - 1) * (int)$this->how_many_show) . ','
. (int)$this->how_many_show : ' ');
return $sql;
}
public function getHash()
{
$hash = array();
if (is_array($this->categories) && count($this->categories)) {
$ids_categories = array();
foreach ($this->categories as $category) {
$ids_categories[] = (int)$category['id'];
}
$hash[] = 'categories-' . implode('_', $ids_categories);
}
if ($this->qty_from != '') {
$hash[] = 'qty_from-' . (int)$this->qty_from;
}
if ($this->qty_to != '') {
$hash[] = 'qty_to-' . (int)$this->qty_to;
}
if ($this->price_from != '') {
$hash[] = 'price_from-' . str_replace('.', '_', (string)$this->price_from);
}
if ($this->price_to != '') {
$hash[] = 'price_to-' . str_replace('.', '_', (string)$this->price_to);
}
if (is_array($this->manufacturers) && count($this->manufacturers)) {
$hash[] = 'manufacturers-' . implode('_', $this->manufacturers);
}
if (is_array($this->suppliers) && count($this->suppliers)) {
$hash[] = 'suppliers-' . implode('_', $this->suppliers);
}
if (is_array($this->carriers) && count($this->carriers)) {
$hash[] = 'carriers-' . implode('_', $this->carriers);
}
if ($this->search_query) {
switch ($this->type_search) {
case self::SEARCH_TYPE_ID:
$hash[] = 'type_search-1';
break;
case self::SEARCH_TYPE_NAME:
case self::SEARCH_TYPE_REFERENCE:
$hash[] = 'type_search-1';
break;
case self::SEARCH_TYPE_EAN13:
case self::SEARCH_TYPE_UPC:
case self::SEARCH_TYPE_DESCRIPTION:
case self::SEARCH_TYPE_DESCRIPTION_SHORT:
$hash[] = 'type_search-' . $this->type_search;
break;
default:
throw new LogicException('Unknown search type');
}
$hash[] = 'search_query-' . urlencode($this->search_query);
}
if ($this->product_name_type_search == '') {
$this->product_name_type_search = 'exact_match';
}
$hash[] = 'product_name_type_search-' . $this->product_name_type_search;
if ($this->active) {
$hash[] = 'active-1';
}
if ($this->disable) {
$hash[] = 'disable-1';
}
if ($this->no_image) {
$hash[] = 'no_image-1';
}
if ($this->yes_image) {
$hash[] = 'yes_image-1';
}
if ($this->no_discount) {
$hash[] = 'no_discount-1';
}
if ($this->yes_discount) {
$hash[] = 'yes_discount-1';
}
if ($this->page > 1) {
$hash[] = 'page-' . $this->page;
}
if ($this->how_many_show > 20) {
$hash[] = 'how_many_show-' . $this->how_many_show;
}
return $hash;
}
public function getRequestParam($name, $default = null)
{
if (property_exists($this, $name)) {
return $this->{$name};
}
return $default;
}
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class Seochar
{
public static function convertseo($str)
{
$char_array = array(
'ъ' => '-', 'Ь' => '-', 'Ъ' => '-', 'ь' => '-', 'Ă' => 'A', 'À' => 'A', 'Ã' => 'A',
'Á' => 'A', 'Æ' => 'A', 'Â' => 'A', 'Å' => 'A', 'Ä' => 'Ae', 'Þ' => 'B','Ć' => 'C', 'ץ' => 'C',
'Ç' => 'C', 'È' => 'E', 'Ę' => 'E', 'É' => 'E', 'Ë' => 'E', 'Ê' => 'E', 'Ğ' => 'G', 'İ' => 'I',
'Ï' => 'I', 'Î' => 'I', 'Í' => 'I', 'Ì' => 'I', 'Ł' => 'L', 'Ñ' => 'N', 'Ń' => 'N', 'Ø' => 'O',
'Ó' => 'O', 'Ò' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'Oe', 'Ş' => 'S', 'Ś' => 'S', 'Ș' => 'S',
'Š' => 'S', 'Ț' => 'T', 'Ù' => 'U', 'Û' => 'U', 'Ú' => 'U', 'Ü' => 'Ue', 'Ý' => 'Y', 'Ź' => 'Z',
'Ž' => 'Z', 'Ż' => 'Z', 'â' => 'a', 'ǎ' => 'a', 'ą' => 'a', 'á' => 'a', 'ă' => 'a', 'ã' => 'a',
'Ǎ' => 'a', 'а' => 'a', 'А' => 'a', 'å' => 'a', 'à' => 'a', 'א' => 'a', 'Ǻ' => 'a', 'Ā' => 'a',
'ǻ' => 'a', 'ā' => 'a', 'ä' => 'ae', 'æ' => 'ae', 'Ǽ' => 'ae', 'ǽ' => 'ae', 'б' => 'b',
'ב' => 'b', 'Б' => 'b', 'þ' => 'b', 'ĉ' => 'c', 'Ĉ' => 'c', 'Ċ' => 'c', 'ć' => 'c', 'ç' => 'c',
'ц' => 'c', 'צ' => 'c', 'ċ' => 'c', 'Ц' => 'c', 'Č' => 'c', 'č' => 'c', 'Ч' => 'ch', 'ч' => 'ch',
'Ї' =>'yi',
'ד' => 'd', 'ď' => 'd', 'Đ' => 'd', 'Ď' => 'd', 'đ' => 'd', 'д' => 'd', 'Д' => 'D', 'ð' => 'd',
'є' => 'ye', 'ע' => 'e', 'е' => 'e', 'Е' => 'e', 'Ə' => 'e', 'ę' => 'e', 'ĕ' => 'e', 'ē' => 'e',
'Ē' => 'e', 'Ė' => 'e', 'ė' => 'e', 'ě' => 'e', 'Ě' => 'e', 'Є' => 'ye', 'Ĕ' => 'e', 'ê' => 'e',
'ə' => 'e', 'è' => 'e', 'ë' => 'e', 'é' => 'e', 'ф' => 'f', 'ƒ' => 'f', 'Ф' => 'f', 'ġ' => 'g',
'Ģ' => 'g', 'Ġ' => 'g', 'Ĝ' => 'g', 'Г' => 'g', 'г' => 'g', 'ĝ' => 'g', 'ğ' => 'g', 'ג' => 'g',
'Ґ' => 'g', 'ґ' => 'g', 'ģ' => 'g', 'ח' => 'h', 'ħ' => 'h', 'Х' => 'kh', 'Ħ' => 'h', 'Ĥ' => 'h',
'ĥ' => 'h', 'х' => 'kh', 'ה' => 'h', 'î' => 'i', 'ï' => 'i', 'í' => 'i', 'ì' => 'i', 'į' => 'i',
'ĭ' => 'i', 'ı' => 'i', 'Ĭ' => 'i', 'И' => 'i', 'ĩ' => 'i', 'ǐ' => 'i', 'Ĩ' => 'i', 'Ǐ' => 'i',
'и' => 'i', 'Į' => 'i', 'י' => 'i', 'Ї' => 'i', 'Ī' => 'i', 'І' => 'i', 'ї' => 'yi', 'і' => 'i',
'ī' => 'i', 'ij' => 'ij', 'IJ' => 'ij', 'й' => 'j', 'Й' => 'j', 'Ĵ' => 'j', 'ĵ' => 'j',
'я' => 'ja', 'Я' => 'ja', 'Э' => 'je', 'э' => 'je', 'ё' => 'e', 'Ё' => 'E', 'ю' => 'ju',
'Ю' => 'ju', 'ĸ' => 'k', 'כ' => 'k', 'Ķ' => 'k', 'К' => 'k', 'к' => 'k', 'ķ' => 'k', 'ך' => 'k',
'Ŀ' => 'l', 'ŀ' => 'l', 'Л' => 'l', 'ł' => 'l', 'ļ' => 'l', 'ĺ' => 'l', 'Ĺ' => 'l', 'Ļ' => 'l',
'л' => 'l', 'Ľ' => 'l', 'ľ' => 'l', 'ל' => 'l', 'מ' => 'm', 'М' => 'm', 'ם' => 'm', 'м' => 'm',
'ñ' => 'n', 'н' => 'n', 'Ņ' => 'n', 'ן' => 'n', 'ŋ' => 'n', 'נ' => 'n', 'Н' => 'n', 'ń' => 'n',
'Ŋ' => 'n', 'ņ' => 'n', 'ʼn' => 'n', 'Ň' => 'n', 'ň' => 'n', 'о' => 'o', 'О' => 'o', 'ő' => 'o',
'õ' => 'o', 'ô' => 'o', 'Ő' => 'o', 'ŏ' => 'o', 'Ŏ' => 'o', 'Ō' => 'o', 'ō' => 'o', 'ø' => 'o',
'ǿ' => 'o', 'ǒ' => 'o', 'ò' => 'o', 'Ǿ' => 'o', 'Ǒ' => 'o', 'ơ' => 'o', 'ó' => 'o', 'Ơ' => 'o',
'œ' => 'oe', 'Œ' => 'oe', 'ö' => 'oe', 'פ' => 'p', 'ף' => 'p', 'п' => 'p', 'П' => 'p', 'ק' => 'q',
'ŕ' => 'r', 'ř' => 'r', 'Ř' => 'r', 'ŗ' => 'r', 'Ŗ' => 'r', 'ר' => 'r', 'Ŕ' => 'r', 'Р' => 'r',
'р' => 'r', 'ș' => 's', 'с' => 's', 'Ŝ' => 's', 'š' => 's', 'ś' => 's', 'ס' => 's', 'ş' => 's',
'С' => 's', 'ŝ' => 's', 'Щ' => 'sch', 'щ' => 'sch', 'ш' => 'sh', 'Ш' => 'sh', 'ß' => 'ss',
'т' => 't', 'ט' => 't', 'ŧ' => 't', 'ת' => 't', 'ť' => 't', 'ţ' => 't', 'Ţ' => 't', 'Т' => 't',
'ț' => 't', 'Ŧ' => 't', 'Ť' => 't', '™' => 'tm', 'ū' => 'u', 'у' => 'u', 'Ũ' => 'u', 'ũ' => 'u',
'Ư' => 'u', 'ư' => 'u', 'Ū' => 'u', 'Ǔ' => 'u', 'ų' => 'u', 'Ų' => 'u', 'ŭ' => 'u', 'Ŭ' => 'u',
'Ů' => 'u', 'ů' => 'u', 'ű' => 'u', 'Ű' => 'u', 'Ǖ' => 'u', 'ǔ' => 'u', 'Ǜ' => 'u', 'ù' => 'u',
'ú' => 'u', 'û' => 'u', 'У' => 'u', 'ǚ' => 'u', 'ǜ' => 'u', 'Ǚ' => 'u', 'Ǘ' => 'u', 'ǖ' => 'u',
'ǘ' => 'u', 'ü' => 'ue', 'в' => 'v', 'ו' => 'v', 'В' => 'v', 'ש' => 'w', 'ŵ' => 'w', 'Ŵ' => 'w',
'ы' => 'y', 'ŷ' => 'y', 'ý' => 'y', 'ÿ' => 'y', 'Ÿ' => 'y', 'Ŷ' => 'y', 'Ы' => 'y', 'ž' => 'z',
'З' => 'z', 'з' => 'z', 'ź' => 'z', 'ז' => 'z', 'ż' => 'z', 'ſ' => 's', 'Ж' => 'zh', 'ж' => 'zh',
'©'=>'c', '®'=>'', '™' => '', '@'=>'', '€' => '', '$'=>'','₴'=>'','£'=>'','¥'=>'','₽'=>'','₪'=>'',
'₨'=>'','₩'=>'','₦'=>'','฿'=>'','₫'=>'','₭'=>'','៛'=>'','₮'=>'','₱'=>'','﷼'=>'',
'₡'=>'','₲'=>'','؋'=>'','₵'=>'','₸'=>'','₺'=>'','₼'=>'', '`'=>'','`'=>'','#'=>'','&'=>'','='=>'','{'=>'',
'}'=>'',';'=>'',':'=>'','>'=>'','<'=>'','+'=>'','/'=>'','?'=>'','['=>'',']'=>'','|'=>'','%'=>'','^'=>'',
'('=>'',')'=>'','!'=>'','*'=>'','_'=>'','"'=>'','~'=>''
);
$str = strtr($str, $char_array);
$str = str_replace(',', '', $str);
$str = str_replace("\'", '', $str);
$str = str_replace("\.", '', $str);
$str = str_replace(".", '', $str);
$str = Tools::strtolower($str);
return $str;
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TemplateProductsMEP extends ObjectModelMEP
{
/**
* @var string
*/
public $name;
/**
* @var bool
*/
public $is_active;
public $products = array();
public static $definition = array(
'table' => 'mep_template_products',
'primary' => 'id_mep_template_products',
'fields' => array(
'name' => array(
'type' => self::TYPE_STRING,
'validate' => ValidateTypeMEP::IS_STRING
)
)
);
public function __construct($id = null, $id_lang = null, $id_shop = null)
{
parent::__construct($id, $id_lang, $id_shop);
if ($this->id) {
$this->products = TemplateProductsProductMEP::getAllByTemplateProducts($this->id);
}
}
public function toArray()
{
$array = parent::toArray();
$array['products'] = $this->products;
return $array;
}
public function add($auto_date = true, $null_values = false)
{
$result = parent::add($auto_date, $null_values);
if ($result) {
$this->afterSave();
}
return $result;
}
public function update($null_values = false)
{
$result = parent::update($null_values);
if ($result) {
$this->afterSave();
}
return $result;
}
public function afterSave()
{
TemplateProductsProductMEP::deleteByTemplateProducts($this->id);
$insert = array();
foreach ($this->products as $product) {
$insert[] = array(
self::$definition['primary'] => $this->id,
'id_product' => $product['id_product']
);
}
Db::getInstance()->insert(
'mep_template_products_product',
$insert
);
}
}

View File

@@ -0,0 +1,153 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TemplateProductsProductMEP extends ObjectModelMEP
{
/**
* @var int
*/
public $id_mep_template_products;
/**
* @var int
*/
public $id_product;
public static $definition = array(
'table' => 'mep_template_products_product',
'primary' => 'id_mep_template_products_product',
'fields' => array(
'id_mep_template_products' => array(
'type' => self::TYPE_INT,
'validate' => ValidateTypeMEP::IS_INT
),
'id_product' => array(
'type' => self::TYPE_INT,
'validate' => ValidateTypeMEP::IS_INT
)
)
);
public static function getIdShopSql()
{
return Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP
? (int)Context::getContext()->shop->id : 'p.id_shop_default';
}
public static function getAllByTemplateProducts($id_mep_template_products)
{
$id_lang = Context::getContext()->language->id;
$id_shop = self::getIdShopSql();
$result = Db::getInstance()->executeS(
'SELECT
p.`id_product`,
p.reference,
pss.`active`,
pss.`price`,
pl.`name`,
pl.`link_rewrite`,
sa.`quantity`,
cl.`name` as category,
m.`name` as manufacturer,
s.`name` as supplier,
(
SELECT i.`id_image` FROM '._DB_PREFIX_.'image i
WHERE i.`id_product` = p.`id_product`
ORDER BY i.`cover` DESC LIMIT 0,1
) cover
FROM '._DB_PREFIX_.'mep_template_products_product mtpp
LEFT JOIN '._DB_PREFIX_.'product p ON p.`id_product` = mtpp.`id_product`
JOIN `'._DB_PREFIX_.'product_shop` pss
ON (p.`id_product` = pss.`id_product` AND pss.id_shop = '.pSQL($id_shop).')
LEFT JOIN '._DB_PREFIX_.'tax_rules_group trg
ON trg.`id_tax_rules_group` = p.`id_tax_rules_group`
LEFT JOIN '._DB_PREFIX_.'manufacturer m ON m.`id_manufacturer` = p.`id_manufacturer`
LEFT JOIN '._DB_PREFIX_.'supplier s ON s.`id_supplier` = p.`id_supplier`
LEFT JOIN '._DB_PREFIX_.'tax t ON t.`id_tax` = p.`id_tax_rules_group`
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON p.`id_product` = pl.`id_product`
AND pl.`id_lang` = '.(int)$id_lang.' AND pl.`id_shop` = '.pSQL($id_shop).'
LEFT JOIN '._DB_PREFIX_.'category_product cp ON cp.`id_product` = p.`id_product`
LEFT JOIN '._DB_PREFIX_.'category_lang cl
ON cl.`id_category` = pss.`id_category_default` AND cl.`id_lang` = '.(int)$id_lang.'
LEFT JOIN '._DB_PREFIX_.'stock_available sa
ON (sa.`id_product` = p.`id_product` AND sa.`id_product_attribute` = 0
'.StockAvailable::addSqlShopRestriction(null, null, 'sa').')
WHERE mtpp.`id_mep_template_products` = '.(int)$id_mep_template_products.'
GROUP BY p.`id_product`, cl.`name`'
);
if (is_array($result) && count($result)) {
$country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'));
$address = new Address();
$address->id_country = $country->id;
foreach ($result as &$product) {
$nothing = null;
$advanced_stock_management = (bool)Db::getInstance()->getValue('
SELECT `advanced_stock_management`
FROM '._DB_PREFIX_.'product_shop
WHERE id_product='.(int)$product['id_product'].Shop::addSqlRestriction());
$product['price_final'] = Product::getPriceStatic(
$product['id_product'],
true,
null,
(int)Configuration::get('PS_PRICE_DISPLAY_PRECISION'),
null,
false,
true,
1,
true,
null,
null,
null,
$nothing
);
$product['advanced_stock_management'] = (
(bool)StockAvailable::dependsOnStock(
(int)$product['id_product']
) && $advanced_stock_management
);
$product['image'] = ImageManager::thumbnail(
_PS_PROD_IMG_DIR_.Image::getImgFolderStatic($product['cover']).$product['cover'].'.jpg',
'product_mini_'.$product['id_product'].'_'.$product['cover'].'.jpg',
45
);
}
}
return (is_array($result) && count($result) ? $result : array());
}
public static function deleteByTemplateProducts($id_mep_template_products)
{
return Db::getInstance()->delete(
'mep_template_products_product',
'id_mep_template_products = '.(int)$id_mep_template_products
);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,102 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AccessoriesTabMEP extends BaseTabMEP
{
public $accessories;
public $remove_old;
public function __construct()
{
parent::__construct();
$this->accessories = Tools::getValue('accessories');
$this->remove_old = (int)Tools::getValue('remove_old');
}
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
foreach ($products as $product) {
$product_obj = new Product((int)$product);
if (Validate::isLoadedObject($product_obj)) {
$this->addToReIndexSearch((int)$product);
if ($this->remove_old) {
$product_obj->deleteAccessories();
if (!is_array($this->accessories) || !count($this->accessories)) {
continue;
}
}
$products_accessories = Product::getAccessoriesLight(
$this->context->language->id,
$product_obj->id
);
$ids_products_accessories = array();
foreach ($products_accessories as $products_accessory) {
$ids_products_accessories[] = (int)$products_accessory['id_product'];
}
foreach ($this->accessories as $accessory) {
if (!in_array((int)$accessory['id'], $ids_products_accessories)) {
Db::getInstance()->execute(
'INSERT INTO `'._DB_PREFIX_.'accessory` (`id_product_1`, `id_product_2`)
VALUES ('.(int)$product_obj->id.', '.(int)$accessory['id'].')'
);
}
}
}
}
$return_products = array();
return array(
'products' => $return_products,
);
}
public function applyChangeForCombinations($products)
{
}
public function checkBeforeChange()
{
if ((!is_array($this->accessories) || !count($this->accessories)) && !$this->remove_old) {
LoggerMEP::getInstance()->error($this->l('No accessories'));
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function getTitle()
{
return $this->l('Accessories');
}
}

View File

@@ -0,0 +1,163 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ActiveTabMEP extends BaseTabMEP
{
public function applyChangeBoth($products, $combinations)
{
$delete_product = (int)Tools::getValue('delete_product', 0);
$delete_type = (int)Tools::getValue('delete_type', 0);
$delete_combinations = array();
if ($this->checkAccessField('delete_product') && $delete_product && $delete_type) {
foreach ($combinations as $id_pa) {
$combination = new Combination($id_pa);
if (Validate::isLoadedObject($combination)) {
$this->addToReIndexSearch((int)$combination->id_product);
$combination->delete();
$delete_combinations[] = $id_pa;
}
}
}
$this->result['delete_combinations'] = $delete_combinations;
}
public function applyChangeForCombinations($products)
{
}
public function applyChangeForProducts($products)
{
$active = (int)Tools::getValue('active');
$delete_product = (int)Tools::getValue('delete_product', 0);
$delete_type = (int)Tools::getValue('delete_type', 0);
$visibility = Tools::getValue('visibility');
$condition = Tools::getValue('condition');
$available_for_order = (int)Tools::getValue('available_for_order');
$show_price = ($available_for_order ? 1 : (int)Tools::getValue('show_price'));
$online_only = (int)Tools::getValue('online_only');
$on_sale = (int)Tools::getValue('on_sale');
if (_PS_VERSION_ >= 1.7) {
$show_condition = (int)Tools::getValue('show_condition');
}
$return_products = array();
$delete_products = array();
foreach ($products as $product) {
$data_for_update = array();
if ($this->checkAccessField('on_sale')) {
$this->addToReIndexSearch((int)$product);
MassEditTools::updateObjectField(
'Product',
'on_sale',
(int)$product,
$on_sale
);
}
if (_PS_VERSION_ >= 1.7) {
if ($this->checkAccessField('show_condition')) {
$this->addToReIndexSearch((int)$product);
MassEditTools::updateObjectField(
'Product',
'show_condition',
(int)$product,
$show_condition
);
}
}
if ($this->checkAccessField('active') && $active != -1) {
$this->addToReIndexSearch((int)$product);
$data_for_update['active'] = (int)$active;
}
if ($this->checkAccessField('visibility') && $visibility != -1) {
$this->addToReIndexSearch((int)$product);
$data_for_update['visibility'] = pSQL($visibility);
}
if ($this->checkAccessField('condition') && $condition != -1) {
$this->addToReIndexSearch((int)$product);
$data_for_update['condition'] = pSQL($condition);
}
if ($this->checkAccessField('available_for_order')) {
$this->addToReIndexSearch((int)$product);
$data_for_update['available_for_order'] = (int)$available_for_order;
}
if ($this->checkAccessField('show_price')) {
$this->addToReIndexSearch((int)$product);
$data_for_update['show_price'] = (int)$show_price;
}
if ($this->checkAccessField('online_only')) {
$this->addToReIndexSearch((int)$product);
$data_for_update['online_only'] = (int)$online_only;
}
if ($this->checkAccessField('delete_product') && $delete_product && !$delete_type) {
$this->addToReIndexSearch((int)$product);
$product_obj = new Product($product);
if (Validate::isLoadedObject($product_obj)) {
$product_obj->delete();
$delete_products[] = $product;
}
}
if (!Shop::isFeatureActive()) {
Db::getInstance()->update('product', $data_for_update, ' id_product = '.(int)$product);
}
Db::getInstance()->update(
'product_shop',
$data_for_update,
' id_product = '.(int)$product.' '
.(Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop '.$this->sql_shop : '')
);
Db::getInstance()->update(
'product',
$data_for_update,
' id_product = '.(int)$product.' '
.(Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop_default '.$this->sql_shop : '')
);
$return_products[(int)$product] = $active;
}
return array(
'products' => $return_products,
'delete_products' => $delete_products,
);
}
public function getTitle()
{
return $this->l('Active');
}
}

View File

@@ -0,0 +1,115 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AdvancedStockManagementTabMEP extends BaseTabMEP
{
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
$advanced_stock_management = Tools::getValue('advanced_stock_management', false);
$depends_on_stock = Tools::getValue('depends_on_stock', false);
$return_products = array();
foreach ($products as $id_product) {
if ($advanced_stock_management === false) {
LoggerMEP::getInstance()->error($this->l('Undefined value'));
}
if ((int)$advanced_stock_management != 1 && (int)$advanced_stock_management != 0) {
LoggerMEP::getInstance()->error($this->l('Incorrect value'));
}
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$advanced_stock_management == 1) {
LoggerMEP::getInstance()->error($this->l('Not possible if advanced stock management is disabled. '));
}
$product_obj = new Product((int)$id_product);
$product_obj->setAdvancedStockManagement((int)$advanced_stock_management);
if (StockAvailable::dependsOnStock($product_obj->id) == 1 && (int)$advanced_stock_management == 0) {
StockAvailable::setProductDependsOnStock($product_obj->id, 0);
}
if ($depends_on_stock === false) {
{
LoggerMEP::getInstance()->error($this->l('Undefined value'));
}
}
if ((int)$depends_on_stock != 0 && (int)$depends_on_stock != 1) {
LoggerMEP::getInstance()->error($this->l('Incorrect value'));
}
if (!$product_obj->advanced_stock_management && (int)$depends_on_stock == 1) {
LoggerMEP::getInstance()->error($this->l('Not possible if advanced stock management is disabled. '));
}
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& (int)$depends_on_stock == 1
&& (Pack::isPack($product_obj->id)
&& !Pack::allUsesAdvancedStockManagement($product_obj->id)
&& ($product_obj->pack_stock_type == 2 || $product_obj->pack_stock_type == 1 ||
($product_obj->pack_stock_type == 3
&& (Configuration::get('PS_PACK_STOCK_TYPE') == 1
|| Configuration::get('PS_PACK_STOCK_TYPE') == 2))))) {
LoggerMEP::getInstance()->error(
$this->l(
'You cannot use advanced stock management for this
pack because<br />
- advanced stock management is not enabled for these products<br />
- you have chosen to decrement products quantities.'
)
);
}
StockAvailable::setProductDependsOnStock($product_obj->id, (int)$depends_on_stock);
$return_products[(int)$id_product] = (bool)$advanced_stock_management;
}
return array(
'products' => $return_products,
);
}
public function applyChangeForCombinations($products)
{
}
public function checkAvailable()
{
return (int)Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
}
public function getTitle()
{
return $this->l('Stock management');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['product'] = new Product();
return $variables;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AttachmentTabMEP extends BaseTabMEP
{
public $attachments;
public $old_attachment;
public function __construct()
{
parent::__construct();
$this->attachments = $this->getIntvalArrayRequest('attachments');
$this->old_attachment = (int)Tools::getValue('old_attachment');
}
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
foreach ($products as $id_product) {
MassEditTools::attachToProduct(
$id_product,
$this->attachments,
$this->old_attachment
);
}
return array();
}
public function applyChangeForCombinations($products)
{
}
public function checkBeforeChange()
{
if (!is_array($this->attachments) || !count($this->attachments)) {
LoggerMEP::getInstance()->error($this->l('No attachments'));
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function getTitle()
{
return $this->l('Attachments');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['attachments'] = Attachment::getAttachments(
$this->context->language->id,
0,
false
);
return $variables;
}
}

View File

@@ -0,0 +1,255 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class CategoryTabMEP extends BaseTabMEP
{
const ACTION_WITH_CATEGORY_ADD = 0;
const ACTION_WITH_CATEGORY_DELETE = 1;
public $action_with_category;
public $category_default;
public $remove_old_categories;
public $categories;
public $object_category_default;
public function __construct()
{
parent::__construct();
$category = Tools::getValue('category');
$this->action_with_category = (int)Tools::getValue('action_with_category', 0);
$this->category_default = (int)Tools::getValue('id_category_default');
$this->remove_old_categories = (int)Tools::getValue('remove_old_categories');
$this->categories = (
is_array($category) && count($category)
? array_map('intval', $category) : array()
);
$this->object_category_default = new Category(
$this->category_default,
$this->context->language->id
);
}
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
$return_products = array();
if ($this->action_with_category === self::ACTION_WITH_CATEGORY_ADD) {
if ($this->remove_old_categories && $this->action_with_category === self::ACTION_WITH_CATEGORY_ADD) {
Db::getInstance()->delete(
'category_product',
' id_product IN('.pSQL(implode(',', $products)).')'
);
}
$category_product_data = array();
foreach ($this->categories as $cat) {
$sql = 'SELECT MAX(`position`) FROM `'._DB_PREFIX_.'category_product` WHERE `id_category` = '.(int)$cat;
$max_position = Db::getInstance()->getValue($sql);
foreach ($products as $key => $id_product) {
$position = $max_position + $key + 1;
$category_product_data[] = array(
'id_product' => (int)$id_product,
'id_category' => (int)$cat,
'position' => $position
);
}
}
if ($this->category_default) {
Db::getInstance()->update(
'product',
array('id_category_default' => (int)$this->category_default),
' id_product IN('.pSQL(implode(',', $products)).')'
);
Db::getInstance()->update(
'product_shop',
array(
'id_category_default' => (int)$this->category_default,
),
' id_product IN('.pSQL(implode(',', $products)).')'
.(Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop '.pSQL($this->sql_shop) : '')
);
$key = isset($key) ? $key : 0;
foreach ($products as $id_product) {
$category_product_data[] = array(
'id_product' => (int)$id_product,
'id_category' => (int)$this->category_default,
'position' => $key++
);
}
}
Db::getInstance()->insert(
'category_product',
$category_product_data,
false,
true,
Db::INSERT_IGNORE
);
if ($this->category_default) {
foreach ($products as $product) {
$return_products[$product['id']] = $this->object_category_default->name;
}
}
}
if ($this->action_with_category === self::ACTION_WITH_CATEGORY_DELETE) {
if (count($products) && count($this->categories)) {
foreach ($products as $id_product) {
Db::getInstance()->execute(
'DELETE FROM `'._DB_PREFIX_.'category_product` WHERE `id_product` = '.(int)$id_product.'
AND `id_category` IN('.implode(',', array_map('intval', $this->categories)).')
AND NOT (SELECT COUNT(ps.`id_category_default`)
FROM `'._DB_PREFIX_.'product_shop` ps WHERE
ps.`id_shop` = 1
AND ps.`id_category_default` = `'._DB_PREFIX_.'category_product`.`id_category`
AND ps.`id_product` = `'._DB_PREFIX_.'category_product`.`id_product`)'
);
}
}
}
foreach ($this->categories as $id_category) {
$sql = 'SELECT `id_product`, `position` FROM `'._DB_PREFIX_.'category_product`
WHERE `id_category` = '.(int)$id_category.' ORDER BY `position` ASC';
$sort_list = array();
foreach (Db::getInstance()->executeS($sql) as $row) {
$sort_list[$row['id_product']] = $row['position'];
}
$this->sortProductIdList($sort_list, array('filter_category' => $id_category));
}
return array(
'products' => $return_products,
);
}
public function applyChangeForCombinations($products)
{
}
public function checkBeforeChange()
{
if ($this->action_with_category === self::ACTION_WITH_CATEGORY_ADD) {
if ($this->remove_old_categories && !$this->category_default) {
LoggerMEP::getInstance()->error($this->l('Please select category default on!'));
}
if ($this->category_default) {
if (!Validate::isLoadedObject($this->object_category_default)) {
LoggerMEP::getInstance()->error($this->l('Category default not exists'));
}
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
}
return true;
}
public function getTitle()
{
return $this->l('Category');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['categories'] = Category::getCategories($this->context->language->id, false);
$variables['simple_categories'] = Category::getSimpleCategories($this->context->language->id);
return $variables;
}
public function sortProductIdList(array $productList, $filterParams)
{
if (!isset($filterParams['filter_category'])) {
throw new \Exception('Cannot sort when filterParams does not contains \'filter_category\'.', 5010);
}
foreach ($filterParams as $k => $v) {
if ($v == '' || strpos($k, 'filter_') !== 0) {
continue;
}
if ($k == 'filter_category') {
continue;
}
throw new \Exception('Cannot sort when filterParams contains other filter than \'filter_category\'.', 5010);
}
$categoryId = $filterParams['filter_category'];
$maxPosition = max(array_values($productList));
$sortedPositions = array_values($productList);
sort($sortedPositions); // new positions to update
// avoid '0', starts with '1', so shift right (+1)
if ($sortedPositions[1] === 0) {
foreach ($sortedPositions as $k => $v) {
$sortedPositions[$k] = $v + 1;
}
}
// combine old positions with new position in an array
$combinedOldNewPositions = array_combine(array_values($productList), $sortedPositions);
ksort($combinedOldNewPositions); // (keys: old positions starting at '1', values: new positions)
$positionsMatcher = array_replace(array_pad(array(), $maxPosition, 0), $combinedOldNewPositions);
// pad holes with 0
array_shift($positionsMatcher);// shift because [0] is not used in MySQL FIELD()
$fields = implode(',', $positionsMatcher);
// update current pages.
$updatePositions = 'UPDATE `'._DB_PREFIX_.'category_product` cp
INNER JOIN `'._DB_PREFIX_.'product` p ON (cp.`id_product` = p.`id_product`)
'.Shop::addSqlAssociation('product', 'p').'
SET cp.`position` = ELT(cp.`position`, '.$fields.'),
p.`date_upd` = "'.date('Y-m-d H:i:s').'",
product_shop.`date_upd` = "'.date('Y-m-d H:i:s').'"
WHERE cp.`id_category` = '.(int)$categoryId.' AND cp.`id_product`
IN ('.implode(',', array_map('intval', array_keys($productList))).')';
Db::getInstance()->execute($updatePositions);
// Fixes duplicates on all pages
Db::getInstance()->query('SET @i := 0');
$selectPositions = 'UPDATE`'._DB_PREFIX_.'category_product` cp
SET cp.`position` = (SELECT @i := @i + 1)
WHERE cp.`id_category` = '.(int)$categoryId.'
ORDER BY cp.`id_product`
NOT IN ('.implode(',', array_map('intval', array_keys($productList))).'), cp.`position` ASC';
Db::getInstance()->execute($selectPositions);
return true;
}
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class CreateproductsTabMEP extends BaseTabMEP
{
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
}
public function apply()
{
$result = array();
$name_lang_default = pSQL(Tools::getValue('name_'.$this->context->language->id));
if (!$name_lang_default) {
$name_lang_default = pSQL(Tools::getValue('name_'.Configuration::get('PS_LANG_DEFAULT')));
}
if (!$name_lang_default) {
foreach (${'_POST'} as $key => $post) {
if (Tools::substr($key, 0, 5) == 'name_' && !empty($post)) {
$name_lang_default = $post;
}
}
}
if (empty($name_lang_default)) {
die('Empty product name.');
}
$id_attribute_group = (int)Tools::getValue('attribute');
$attributes = Db::getInstance()->executeS(
'SELECT * FROM `'._DB_PREFIX_.'attribute`
WHERE `id_attribute_group` ='.(int)$id_attribute_group
);
if (!$attributes) {
$attributes = array(array());
}
foreach ($attributes as $attribute) {
$product = new Product();
$name = array();
$languages = Language::getLanguages(false);
$language_ids = array();
foreach ($languages as $language) {
$language_ids[] = (int)$language['id_lang'];
}
foreach ($language_ids as $id_lang) {
if (count($attribute)) {
$attribute_group = new AttributeGroup($id_attribute_group, $id_lang);
$attribute_obj = new Attribute($attribute['id_attribute']);
}
$post_name_lang = Tools::getValue('name_'.$id_lang);
$name_lang = empty($post_name_lang)
? $name_lang_default : pSQL(Tools::getValue('name_'.$id_lang));
$name[$id_lang] = $name_lang.
(count($attribute) ? '-'.$attribute_group->name.': '.$attribute_obj->name[$id_lang] : '');
}
$product->name = $name;
foreach ($product->name as $id_lang => $name_lang) {
$product->link_rewrite[$id_lang] = Tools::link_rewrite($name_lang);
}
if (Tools::getIsset('unit_price') != null) {
$product->unit_price = str_replace(',', '.', Tools::getValue('unit_price'));
}
$product->id_category_default = (int)Tools::getValue('id_category_default');
if (!$product->add()) {
die('An error occurred while creating an object.');
}
$product->addToCategories(Tools::getValue('categoryBox'));
}
if (LoggerMEP::getInstance()->hasError()) {
return array();
} else {
$this->reindexSearch();
return $result;
}
}
public function applyChangeForCombinations($products)
{
}
public function getTitle()
{
return $this->l('Create products');
}
public function getAttributes()
{
return array('data-action' => 'create_products');
}
public function renderFormCreateProducts()
{
$fields_form = array(
'form' => array(
'legend' => array(
'title' => '',
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name').':',
// 'hint' => $this->l('Invalid characters:').' &lt;&gt;;=#{}',
'name' => 'name',
'class' => 'class',
'lang' => true,
// 'required' => true,
),
array(
'type' => 'select',
'label' => $this->l('Attribute for name suffix').':',
// 'hint' => $this->l('The name of the attribute will be added to the title'),
'name' => 'attribute',
'options' => array(
'default' => array('value' => 0, 'label' => '--'),
'query' => AttributeGroup::getAttributesGroups($this->context->language->id),
'id' => 'id_attribute_group',
'name' => 'name',
),
),
),
),
);
$helper = new HelperForm();
$helper->module = $this;
$helper->override_folder = 'override/';
$helper->show_toolbar = false;
$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
$helper->default_form_language = $lang->id;
$helper->allow_employee_form_lang = $this->context->controller->allow_employee_form_lang;
$this->fields_form = array();
$languages = ToolsModuleMEP::getLanguages(false);
$name = array();
foreach ($languages as $language) {
$name[$language['id_lang']] = '';
}
$helper->tpl_vars = array(
'fields_value' => array('name' => $name, 'attribute' => ''),
'languages' => $languages,
'id_language' => $this->context->language->id,
);
return $helper->generateForm(array($fields_form));
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['form_create_products'] = $this->renderFormCreateProducts();
$variables['currency2'] = $this->context->currency;
return $variables;
}
}

View File

@@ -0,0 +1,163 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class CustomizationTabMEP extends BaseTabMEP
{
public function applyChangeForCombinations($products)
{
}
public function applyChangeForProducts($products)
{
$labels = Tools::getValue('label');
if (!is_array($labels) || !count($labels)) {
LoggerMEP::getInstance()->error($this->l('Not labels'));
return array();
}
$file_fields = (array_key_exists(Product::CUSTOMIZE_FILE, $labels)
&& is_array($labels[Product::CUSTOMIZE_FILE]) ? $labels[Product::CUSTOMIZE_FILE] : array());
$text_fields = (array_key_exists(Product::CUSTOMIZE_TEXTFIELD, $labels)
&& is_array($labels[Product::CUSTOMIZE_TEXTFIELD]) ? $labels[Product::CUSTOMIZE_TEXTFIELD] : array());
if ($this->checkAccessField('delete_customization_fields') && Tools::getValue('delete_customization_fields')) {
Db::getInstance()->execute(
'DELETE cf, cfl
FROM `'._DB_PREFIX_.'customization_field` cf
LEFT JOIN `'._DB_PREFIX_.'customization_field_lang` cfl
ON cf.`id_customization_field` = cfl.`id_customization_field`
WHERE cf.`id_product` IN('.implode(',', array_map('intval', $products)).')'
);
Db::getInstance()->execute(
'UPDATE '._DB_PREFIX_.'product p, '._DB_PREFIX_.'product_shop ps
SET p.`uploadable_files` = 0,
p.`text_fields` = 0,
ps.`uploadable_files` = 0,
ps.`text_fields` = 0
WHERE p.`id_product` = ps.`id_product`
AND p.`id_product` IN('.implode(',', array_map('intval', $products)).')'
);
}
$fields = array(
'uploadable_files' => 0,
'text_fields' => 0,
);
if ($this->checkAccessField('customization_file_labels')) {
$fields['uploadable_files'] = count($file_fields);
}
if ($this->checkAccessField('customization_text_labels')) {
$fields['text_fields'] = count($text_fields);
}
Db::getInstance()->execute(
'UPDATE '._DB_PREFIX_.'product p, '._DB_PREFIX_.'product_shop ps
SET p.`uploadable_files` = ('.$fields['uploadable_files'].' + p.`uploadable_files`),
p.`text_fields` =('.$fields['text_fields'].' + p.`text_fields`),
ps.`uploadable_files` = ('.$fields['uploadable_files'].' + ps.`uploadable_files`),
ps.`text_fields` =('.$fields['text_fields'].' + ps.`text_fields`)
WHERE p.`id_product` = ps.`id_product`
AND p.`id_product` IN('.implode(',', array_map('intval', $products)).')'
);
$customizable = false;
foreach ($products as $id_product) {
$has_required_fields = 0;
if ($this->checkAccessField('customization_file_labels')) {
$customizable = true;
foreach ($file_fields as $file_field) {
$customization_field = new CustomizationField();
$customization_field->id_product = $id_product;
$customization_field->type = Product::CUSTOMIZE_FILE;
if (array_key_exists('required', $file_field)) {
$customization_field->required = (int)$file_field['required'];
} else {
$customization_field->required = false;
}
$has_required_fields |= $customization_field->required;
$customization_field->name = $file_field['name'];
$customization_field->save();
}
}
if ($this->checkAccessField('customization_text_labels')) {
$customizable = true;
foreach ($text_fields as $text_field) {
$customization_field = new CustomizationField();
$customization_field->id_product = $id_product;
$customization_field->type = Product::CUSTOMIZE_TEXTFIELD;
if (array_key_exists('required', $text_field)) {
$customization_field->required = (int)$text_field['required'];
} else {
$customization_field->required = false;
}
$has_required_fields |= $customization_field->required;
$customization_field->name = $text_field['name'];
$customization_field->save();
}
}
if ($has_required_fields) {
ObjectModel::updateMultishopTable(
'product',
array('customizable' => 2),
'a.id_product = '.(int)$id_product
);
}
Configuration::updateGlobalValue(
'PS_CUSTOMIZATION_FEATURE_ACTIVE',
Customization::isCurrentlyUsed()
);
}
if ($customizable) {
Db::getInstance()->execute(
'UPDATE '._DB_PREFIX_.'product p, '._DB_PREFIX_.'product_shop ps
SET p.`customizable` = 1,
ps.`customizable` = 1
WHERE p.`id_product` = ps.`id_product`
AND p.`id_product` IN('.implode(',', array_map('intval', $products)).')'
);
}
return array();
}
public function applyChangeBoth($products, $combinations)
{
}
public function getTitle()
{
return $this->l('Customization fields');
}
}

View File

@@ -0,0 +1,186 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class DeliveryTabMEP extends BaseTabMEP
{
public $width;
public $height;
public $depth;
public $weight;
public $additional_shipping_cost;
public $carriers;
public $weight_change_for_combination;
public $additional_delivery_times;
public $delivery_in_stock = array();
public $delivery_out_stock;
public $del_carrier;
public function __construct()
{
parent::__construct();
$this->width = (float)Tools::getValue('width');
$this->height = (float)Tools::getValue('height');
$this->depth = (float)Tools::getValue('depth');
$this->weight = (float)Tools::getValue('weight');
$this->additional_shipping_cost = (float)Tools::getValue('additional_shipping_cost');
$this->carriers = array_map('intval', Tools::getValue('id_carrier', array()));
$this->weight_change_for_combination = Tools::getValue('change_for');
$this->additional_delivery_times = Tools::getValue('additional_delivery_times');
$this->del_carrier = (int)Tools::getValue('del_carrier');
}
public function applyChangeBoth($products, $combinations)
{
foreach ($products as $id_product) {
$product = new Product((int)$id_product);
if (Validate::isLoadedObject($product)) {
if ($this->checkAccessField('width')) {
$product->width = $this->width;
}
if ($this->checkAccessField('height')) {
$product->height = $this->height;
}
if ($this->checkAccessField('depth')) {
$product->depth = $this->depth;
}
if ($this->checkAccessField('weight')) {
if ($this->weight_change_for_combination == 1) {
foreach ($combinations as $id_pa) {
MassEditTools::updateObjectField(
'Combination',
'weight',
(int)$id_pa,
$this->weight
);
}
} else {
$product->weight = $this->weight;
}
}
if ($this->checkAccessField('additional_shipping_cost')) {
$product->additional_shipping_cost = $this->additional_shipping_cost;
}
/** 1.7 */
if ($this->checkAccessField('additional_delivery_times')) {
$product->additional_delivery_times = $this->additional_delivery_times;
}
if ($this->checkAccessField('delivery_in_stock')) {
foreach (ToolsModuleMEP::getLanguages(false) as $language) {
$this->delivery_in_stock[$language['id_lang']]
= Tools::getValue('delivery_in_stock_'.$language['id_lang']);
}
$product->delivery_in_stock = $this->delivery_in_stock;
}
if ($this->checkAccessField('delivery_out_stock')) {
foreach (ToolsModuleMEP::getLanguages(false) as $language) {
$this->delivery_out_stock[$language['id_lang']]
= Tools::getValue('delivery_out_stock_'.$language['id_lang']);
}
$product->delivery_out_stock = $this->delivery_out_stock;
}
$product->save();
if (is_array($this->carriers) && count($this->carriers)
&& $this->checkAccessField('id_carrier') && $this->del_carrier == 0) {
$product->setCarriers($this->carriers);
} elseif ($this->checkAccessField('id_carrier')) {
$res = Db::getInstance()->executeS('SELECT id_reference
FROM `'._DB_PREFIX_.'carrier`
WHERE id_carrier IN ('.pSQL(implode(',', $this->carriers)).')');
if (empty($res)) {
return;
}
$referrences = array();
foreach ($res as $ref) {
$referrences[] = $ref['id_reference'];
}
Db::getInstance()->execute(
'DELETE FROM `'._DB_PREFIX_.'product_carrier`
WHERE id_product = '.(int)$product->id.'
AND id_shop = '.(int)Context::getContext()->shop->id.' AND id_carrier_reference
IN ('.pSQL(implode(',', $referrences)).')'
);
}
}
}
}
public function applyChangeForProducts($products)
{
return array();
}
public function applyChangeForCombinations($products)
{
}
public function checkBeforeChange()
{
$combinations = $this->getCombinationsIdsFromRequest();
if ($this->checkAccessField('weight') && $this->weight_change_for_combination
&& (!is_array($combinations) || !count($combinations))) {
LoggerMEP::getInstance()->error($this->l('No combinations for change weight'));
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function getTitle()
{
return $this->l('Delivery');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['carriers'] = Carrier::getCarriers(
Context::getContext()->language->id,
false,
false,
false,
null,
Carrier::ALL_CARRIERS
);
return $variables;
}
public function checkOptionForCombination()
{
$change_for = (int)Tools::getValue('change_for');
return $change_for == self::CHANGE_FOR_COMBINATION;
}
}

View File

@@ -0,0 +1,172 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class DescriptionTabMEP extends BaseTabMEP
{
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
$description = Tools::getValue('description');
$description_short = Tools::getValue('description_short');
$replace_description_short = Tools::getValue('replace_description_short');
$replace_description = Tools::getValue('replace_description');
$language = (int)Tools::getValue('language');
$product_name = Tools::getValue('product_name');
$location_description_short = Tools::getValue('location_description_short');
$location_description = Tools::getValue('location_description');
$location_name = Tools::getValue('location_name');
foreach ($products as $id_product) {
if (!$language) {
$languages = Language::getLanguages(true);
} else {
$languages = array(array('id_lang' => $language));
}
foreach ($languages as $lang) {
$data_for_update = array();
$product = new Product($id_product);
$product->description[$lang['id_lang']] = $product->description[$lang['id_lang']];
$product->description_short[$lang['id_lang']] = $product->description_short[$lang['id_lang']];
if ($this->checkAccessField('description')) {
$this->addToReIndexSearch((int)$id_product);
$description_update = MassEditTools::renderMetaTag(
$description,
(int)$id_product,
$lang['id_lang']
);
$description_update = addslashes($description_update);
$product_desc = addslashes($product->description[$lang['id_lang']]);
switch ($location_description) {
case 1:
$data_for_update['description']=$description_update.$product_desc;
break;
case 2:
$data_for_update['description']=$product_desc.$description_update;
break;
case 3:
$temp_desc = str_replace($replace_description, $description_update, $product->description[$lang['id_lang']]);
$data_for_update['description'] = addslashes($temp_desc);
break;
default:
$data_for_update['description'] = $description_update;
}
}
if ($this->checkAccessField('description_short')) {
$this->addToReIndexSearch((int)$id_product);
$description_short_update2 = MassEditTools::renderMetaTag(
$description_short,
(int)$id_product,
$lang['id_lang']
);
$description_short_update = addslashes($description_short_update2);
$product_short_desc = addslashes($product->description_short[$lang['id_lang']]);
switch ($location_description_short) {
case 1:
$data_for_update['description_short'] =
$description_short_update.$product_short_desc;
break;
case 2:
$data_for_update['description_short'] =
$product_short_desc.$description_short_update;
break;
case 3:
$temp_desc_s = str_replace($replace_description_short, $description_short_update, $product->description_short[$lang['id_lang']]);
$data_for_update['description_short'] = addslashes($temp_desc_s);
break;
default:
$data_for_update['description_short'] = $description_short_update;
}
}
if ($this->checkAccessField('product_name')) {
$data_for_update2 = array();
$this->addToReIndexSearch((int)$id_product);
$product_name_update = MassEditTools::renderMetaTag(
$product_name,
(int)$id_product,
$lang['id_lang']
);
$name_product = addslashes($product->name[$lang['id_lang']]);
switch ($location_name) {
case 1:
$data_for_update2['name']=$product_name_update.$name_product;
break;
case 2:
$data_for_update2['name']=$name_product.$product_name_update;
break;
default:
$data_for_update2['name'] = $product_name_update;
}
$data_for_update['name'] = addslashes($data_for_update2['name']);
}
if (count($data_for_update)) {
Db::getInstance()->update(
'product_lang',
$data_for_update,
' id_product = '.(int)$id_product
.($lang['id_lang'] ? ' AND id_lang = '.(int)$lang['id_lang'] : '')
.' '.(Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop '.$this->sql_shop : '')
);
}
}
}
return array();
}
public function applyChangeForCombinations($products)
{
}
public function getTitle()
{
return $this->l('Description');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['static_for_name'] = array(
'{title}' => $this->l('title'),
'{name}' => $this->l('name product'),
'{price}' => $this->l('price final'),
'{manufacturer}' => $this->l('manufacturer'),
'{category}' => $this->l('default category'),
'{reference}' => $this->l('product reference'),
);
return $variables;
}
}

View File

@@ -0,0 +1,576 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class DiscountTabMEP extends BaseTabMEP
{
public $id_currency;
public $id_country;
public $id_group;
public $from_quantity;
public $reduction;
public $delete_old_discount;
public $reduction_type;
public $reduction_tax;
public $from;
public $price;
public $leave_base_price;
public $to;
public $id_shop;
public $currency;
public $action_for_sp;
public $action_discount;
public function __construct()
{
parent::__construct();
$this->id_currency = Tools::getValue('sp_id_currency');
$this->id_country = Tools::getValue('sp_id_country');
$this->id_group = Tools::getValue('sp_id_group');
$this->from_quantity = Tools::getValue('sp_from_quantity');
$this->reduction_type = !Tools::getValue('sp_reduction_type') ? 'amount' : Tools::getValue('sp_reduction_type');
$this->reduction_tax = Tools::getValue('sp_reduction_tax');
$this->reduction = (float)($this->reduction_type == 'amount'
? Tools::getValue('sp_reduction') : Tools::getValue('sp_reduction') / 100);
$this->discount_price_reduction_type = !Tools::getValue('discount_price_reduction_type')
? 'amount' : Tools::getValue('discount_price_reduction_type');
$this->discount_price_reduction = (float)($this->discount_price_reduction_type == 'amount'
? Tools::getValue('price') : Tools::getValue('price') / 100);
$this->delete_old_discount = (int)Tools::getValue('delete_old_discount');
$this->delete_old_discount_all = (int)Tools::getValue('delete_old_discount_all');
$this->from = Tools::getValue('sp_from');
$this->to = Tools::getValue('sp_to');
$this->price = (float)Tools::getValue('price');
$this->leave_base_price = (int)Tools::getValue('leave_base_price');
$this->action_for_sp = Tools::getValue('action_for_sp');
$this->action_discount = Tools::getValue('action_discount');
// if ($this->leave_base_price) {
// $this->price = -1;
// }
if (!$this->from) {
$this->from = '0000-00-00 00:00:00';
}
if (!$this->to) {
$this->to = '0000-00-00 00:00:00';
}
$this->id_shop = $this->context->cookie->__get('shopContext');
$this->id_shop = !$this->id_shop ? 0 : $this->context->shop->id;
$this->currency = Currency::getCurrency(Configuration::get('PS_CURRENCY_DEFAULT'));
}
public function applyChangeBoth($products, $combinations)
{
}
public function deleteOldDiscount($id_product)
{
if ($this->delete_old_discount && $this->checkAccessField('delete_specific_price')) {
SpecificPrice::deleteByProductId((int)$id_product);
}
}
public function getPrice($id_product)
{
return Db::getInstance()->getValue('SELECT price FROM `'._DB_PREFIX_.'product`
WHERE `id_product` = ' . $id_product);
}
public function addSpecificPrice($products)
{
$return_products = array();
$discount_price_reduction_type = Tools::getValue('discount_price_reduction_type');
$g = null;
foreach ($products as $id_product) {
$this->deleteOldDiscount($id_product);
if (Tools::getValue('discount_price') == 0) {
if ($discount_price_reduction_type == 'amount') {
$this->price = $this->discount_price_reduction + $this->getPrice($id_product);
}
if ($discount_price_reduction_type == 'percentage') {
$temp_price = $this->getPrice($id_product) * $this->discount_price_reduction;
$this->price = $this->getPrice($id_product) + $temp_price;
}
}
if (Tools::getValue('discount_price') == 1) {
if ($discount_price_reduction_type == 'amount') {
$this->price = $this->getPrice($id_product) - $this->discount_price_reduction;
}
if ($discount_price_reduction_type == 'percentage') {
$temp_price =$this->getPrice($id_product) * $this->discount_price_reduction;
$this->price = $this->getPrice($id_product) - $temp_price;
}
}
if ($this->validateSpecificPrice(
(int)$id_product,
$this->id_shop,
$this->id_currency,
$this->id_country,
$this->id_group,
0,
$this->price,
$this->from_quantity,
$this->reduction,
$this->reduction_type,
$this->from,
$this->to,
0
)) {
$specific_price = new SpecificPrice();
$specific_price->id_product = (int)$id_product;
$specific_price->id_product_attribute = (int)0;
$specific_price->id_shop = (int)$this->id_shop;
$specific_price->id_currency = (int)$this->id_currency;
$specific_price->id_country = (int)$this->id_country;
$specific_price->id_group = (int)$this->id_group;
$specific_price->id_customer = 0;
$specific_price->price = (float)$this->price;
$specific_price->from_quantity = (int)$this->from_quantity;
$specific_price->reduction = (float)$this->reduction;
$specific_price->reduction_tax = (float)$this->reduction_tax;
$specific_price->reduction_type = $this->reduction_type;
$specific_price->from = $this->from;
$specific_price->to = $this->to;
if (!$specific_price->add()) {
LoggerMEP::getInstance()->error(
sprintf(
$this->l('Product №%s: an error occurred while updating the specific price.'),
$id_product
)
);
}
}
if (version_compare(_PS_VERSION_, '1.7.6.8', '>=')) {
$return_products[$id_product] = array(
'price' => Tools::getContextLocale($this->context)->formatPrice(
Product::getPriceStatic($id_product, false),
$this->context->currency->iso_code
),
'price_final' => Tools::getContextLocale($this->context)->formatPrice(
Product::getPriceStatic($id_product, true),
$this->context->currency->iso_code
),
);
} else {
$return_products[$id_product] = array(
'price' => Tools::displayPrice(Product::getPriceStatic($id_product, false), $this->currency),
'price_final' => Tools::displayPrice(Product::getPriceStatic($id_product, true), $this->currency),
);
}
}
return $return_products;
}
public function updateSpecificPrice($products)
{
$where = $this->getWhereFilter($products);
$ids_sp = Db::getInstance()->executeS('SELECT `id_specific_price` FROM `'._DB_PREFIX_.'specific_price` '.
$where);
if (!$this->checkOptionForCombination()) {
$in = implode(array_map('intval', $products), ', ');
}
$test = Db::getInstance()->getValue('SELECT * FROM `'._DB_PREFIX_.'specific_price`
WHERE `id_product` IN ('.pSQL($in).') AND `from_quantity` = ' . $this->from_quantity);
if ($test == false) {
return true;
}
$price = function ($specific_price, $price) {
$discount_price_reduction_type = Tools::getValue('discount_price_reduction_type');
if (Tools::getValue('discount_price') === '0') {
if ($discount_price_reduction_type == 'amount') {
return $specific_price->price + $price;
} elseif ($discount_price_reduction_type == 'percentage') {
return $specific_price->price + ($specific_price->price * $price / 100);
}
} elseif (Tools::getValue('discount_price') === '1') {
if ($discount_price_reduction_type == 'amount') {
$new_price = $specific_price->price - $price;
return ($new_price > 0) ? $new_price : $specific_price->price;
} elseif ($discount_price_reduction_type == 'percentage') {
return $specific_price->price - ($specific_price->price * $price / 100);
}
} elseif (Tools::getValue('discount_price') === '2') {
return $price;
}
return $specific_price->price;
};
$reduction = function ($specific_price, $reduction, $reduction_type) {
if (Tools::getValue('discount_discount') === '0') {
if ($reduction_type == $specific_price->reduction_type) {
return $specific_price->reduction + $reduction;
}
} elseif (Tools::getValue('discount_discount') === '1') {
if ($reduction_type == $specific_price->reduction_type) {
return $specific_price->reduction - $reduction;
}
} elseif (Tools::getValue('discount_discount') === '2') {
$specific_price->reduction_type = $reduction_type;
return $reduction;
}
return $specific_price->reduction;
};
$return_products = array();
foreach ($ids_sp as $value) {
$sp = new SpecificPrice($value['id_specific_price']);
if (!Validate::isLoadedObject($sp)) {
continue;
}
$sp->id_currency = (int)$this->id_currency;
$sp->id_country = (int)$this->id_country;
$sp->id_group = (int)$this->id_group;
$sp->from = $this->from;
$sp->to = $this->to;
$sp->price = $price($sp, $this->price);
$sp->reduction = $reduction($sp, $this->reduction, $this->reduction_type);
$sp->from_quantity = (int)$this->from_quantity;
if (!$sp->update()) {
LoggerMEP::getInstance()->error(
sprintf(
$this->l(
'Product №%s / Specific price №%s: an error
occurred while updating the specific price.'
),
$sp->id_product,
$sp->id
)
);
} else {
$return_products[$sp->id_product] = true;
}
}
return $return_products;
}
private function getWhereFilter($products)
{
$where = 'WHERE 1';
if (count(Shop::getCompleteListOfShopsID()) > 1) {
$where .= ' AND `id_shop` = '.(int)$this->id_shop;
}
if (!$this->checkOptionForCombination()) {
$in = implode(array_map('intval', $products), ', ');
$where .= ' AND `id_product` IN ('.pSQL($in).')';
}
if ($this->checkOptionForCombination()) {
$ids_combination = array();
foreach ($products as $id_product => $combinations) {
foreach ($combinations as $id_combination) {
$ids_combination[] = $id_combination;
}
}
if (count($ids_combination) == 1) {
$where .= ' AND `id_product_attribute` = '.(int)$ids_combination[0];
} else {
$in = implode($ids_combination, ', ');
$where .= ' AND `id_product_attribute` IN ('.pSQL($in).')';
}
}
if (Tools::getValue('search_id_currency')) {
$where .= ' AND `id_currency` = '.(int)Tools::getValue('search_id_currency');
}
if (Tools::getValue('search_id_country')) {
$where .= ' AND `id_country` = '.(int)Tools::getValue('search_id_country');
}
if (Tools::getValue('search_id_group')) {
$where .= ' AND `id_group` = '.(int)Tools::getValue('search_id_group');
}
if (Tools::getValue('search_from')) {
$where .= ' AND `from` >= "'.MassEditTools::roundFromDate(Tools::getValue('search_from')).'"';
}
if (Tools::getValue('search_to')) {
$where .= ' AND `to` <= "'.MassEditTools::roundToDate(Tools::getValue('search_to')).'"';
}
if (Tools::getValue('search_from_quantity')) {
$where .= ' AND `from_quantity` = "'.(int)Tools::getValue('search_from_quantity').'"';
}
return $where;
}
public function applyChangeForProducts($products)
{
$return_products = array();
if ($this->checkAccessField('specific_price') && $this->action_for_sp == 0) {
$return_products = $this->addSpecificPrice($products);
} elseif ($this->checkAccessField('specific_price') && $this->action_for_sp == 1) {
$return_products = $this->deleteSpecificPrice($products);
} elseif ($this->checkAccessField('specific_price') && $this->action_for_sp == 2) {
$return_products = $this->updateSpecificPrice($products);
} elseif ($this->checkAccessField('delete_specific_price_all') && $this->delete_old_discount_all) {
foreach ($products as $id_product) {
if (SpecificPrice::deleteByProductId((int)$id_product)) {
$return_products[$id_product] = true;
}
}
}
return array(
'products' => $return_products
);
}
public function addSpecificPriceCombination($products)
{
$return_combinations = array();
foreach ($products as $id_product => $combinations) {
foreach ($combinations as $id_pa) {
if ($this->validateSpecificPrice(
(int)$id_product,
$this->id_shop,
$this->id_currency,
$this->id_country,
$this->id_group,
$id_pa,
$this->price,
$this->from_quantity,
$this->reduction,
$this->reduction_type,
$this->from,
$this->to,
0
)) {
$specific_price = new SpecificPrice();
$specific_price->id_product = (int)$id_product;
$specific_price->id_product_attribute = (int)$id_pa;
$specific_price->id_shop = (int)$this->id_shop;
$specific_price->id_currency = (int)$this->id_currency;
$specific_price->id_country = (int)$this->id_country;
$specific_price->id_group = (int)$this->id_group;
$specific_price->id_customer = 0;
$specific_price->price = (float)$this->price;
$specific_price->from_quantity = (int)$this->from_quantity;
$specific_price->reduction = (float)$this->reduction;
$specific_price->reduction_tax = $this->reduction_tax;
$specific_price->reduction_type = $this->reduction_type;
$specific_price->from = $this->from;
$specific_price->to = $this->to;
if (!$specific_price->add()) {
$logger = LoggerMEP::getInstance();
$logger->error(
sprintf(
$this->module->l(
'Product №%s: an error occurred while updating the specific price.'
),
$id_product
)
);
}
}
if (version_compare(
_PS_VERSION_,
'1.7.6',
'>='
)) {
$return_combinations[$id_pa] = array(
'price' => Tools::getContextLocale($this->context)->formatPrice(
Product::getPriceStatic($id_product, false, $id_pa),
$this->context->currency->iso_code
),
'price_final' => Tools::getContextLocale($this->context)->formatPrice(
Product::getPriceStatic($id_product, true, $id_pa),
$this->context->currency->iso_code
),
);
} else {
$return_combinations[$id_pa] = array(
'price' => Tools::displayPrice(
Product::getPriceStatic($id_product, false, $id_pa),
$this->currency
),
'price_final' => Tools::displayPrice(
Product::getPriceStatic($id_product, true, $id_pa),
$this->currency
)
);
}
}
}
return $return_combinations;
}
public function applyChangeForCombinations($products)
{
$return_products = array();
if ($this->checkAccessField('specific_price') && $this->action_for_sp == 0) {
$return_products = $this->addSpecificPriceCombination($products);
} elseif ($this->checkAccessField('specific_price') && $this->action_for_sp == 1) {
$return_products = $this->deleteSpecificPrice($products);
} elseif ($this->checkAccessField('specific_price') && $this->action_for_sp == 2) {
$return_products = $this->updateSpecificPrice($products);
} elseif ($this->checkAccessField('delete_specific_price_all') && $this->delete_old_discount_all) {
foreach ($products as $id_product) {
if (SpecificPrice::deleteByProductId((int)$id_product)) {
$return_products[$id_product] = true;
}
}
}
return array(
'products' => $return_products
);
}
protected function deleteSpecificPrice($products)
{
if (Db::getInstance(_PS_USE_SQL_SLAVE_)->execute(
'
DELETE FROM `'._DB_PREFIX_.'specific_price` '.$this->getWhereFilter($products)
)) {
Configuration::updateGlobalValue(
'PS_SPECIFIC_PRICE_FEATURE_ACTIVE',
ObjectModel::isCurrentlyUsed('specific_price')
);
}
return ($this->checkOptionForCombination() ? array_keys($products) : $products);
}
public function checkBeforeChange()
{
if ($this->reduction_type == 'percentage'
&& ((float)$this->reduction <= 0
|| (float)$this->reduction > 100)) {
LoggerMEP::getInstance()->error($this->l('Product №%s: submitted reduction value (0-100) is out-of-range'));
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function checkOptionForCombination()
{
$change_for = (int)Tools::getValue('change_for');
if ($change_for == self::CHANGE_FOR_COMBINATION) {
return true;
}
return false;
}
public function validateSpecificPrice(
$id_product,
$id_shop,
$id_currency,
$id_country,
$id_group,
$id_customer,
$price,
$from_quantity,
$reduction,
$reduction_type,
$from,
$to,
$id_combination = 0
) {
if (!Validate::isUnsignedId($id_shop)
|| !Validate::isUnsignedId($id_currency)
|| !Validate::isUnsignedId($id_country) || !Validate::isUnsignedId($id_group) || !Validate::isUnsignedId(
$id_customer
)) {
LoggerMEP::getInstance()->error(sprintf($this->l('Product №%s: wrong IDs'), $id_product));
} elseif ((!isset($price)
&& !isset($reduction))
|| (isset($price)
&& !Validate::isNegativePrice($price))
|| (isset($reduction) && !Validate::isPrice($reduction))) {
LoggerMEP::getInstance()->error(
sprintf($this->l('Product №%s: invalid price/discount amount'), $id_product)
);
} elseif (!Validate::isUnsignedInt($from_quantity)) {
LoggerMEP::getInstance()->error(sprintf($this->l('Product №%s: invalid quantity'), $id_product));
} elseif ($reduction && !Validate::isReductionType($reduction_type)) {
LoggerMEP::getInstance()->error(
sprintf(
$this->l('Product №%s: please select a discount type (amount or percentage).'),
$id_product
)
);
} elseif ($from && $to && (!Validate::isDateFormat($from) || !Validate::isDateFormat($to))) {
LoggerMEP::getInstance()->error(
sprintf($this->l('Product №%s: the from/to date is invalid.'), $id_product)
);
} elseif (SpecificPrice::exists(
(int)$id_product,
$id_combination,
$id_shop,
$id_group,
$id_country,
$id_currency,
0,
$from_quantity,
$from,
$to,
false
)) {
LoggerMEP::getInstance()->error(
sprintf($this->l('Product №%s: speicifc price already exists.'), $id_product)
);
return false;
} else {
return true;
}
return false;
}
public function getTitle()
{
return $this->l('Discount');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['currencies'] = Currency::getCurrencies(false, true);
$variables['countries'] = Country::getCountries($this->context->language->id, true);
$variables['groups'] = Group::getGroups($this->context->language->id);
return $variables;
}
}

View File

@@ -0,0 +1,507 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class FeaturesTabMEP extends BaseTabMEP
{
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
$error = array();
$product_obj = new Product(null);
$disabled = Tools::getValue('disabled');
$delete_old = Tools::getValue('delete_old');
$extended_features = Tools::getValue('extendedfeatures', array());
$features = Feature::getFeatures(Context::getContext()->employee->id_lang);
$multi_features = Tools::getIsset('form') && ($form = Tools::getValue('form')) && isset($form['features']);
foreach ($products as $id_product) {
if ($multi_features) {
if (Validate::isLoadedObject($product = new Product($id_product))) {
if ((bool)$delete_old) {
$product->deleteFeatures();
}
// add new objects
$languages = Language::getLanguages(false);
$features = isset($form['features']) ? $form['features'] : array();
if (is_array($features)) {
foreach ($features as $key => $feature) {
// dump($feature);
$delete_feature = Tools::getValue('delete_form_features_'.$key);
if ($delete_feature == 1 && empty($feature['value']) && !empty($feature['feature'])) {
self::deleteFeaturesId($product->id, $feature['feature']);
} elseif ($delete_feature == 1 && !empty($feature['value'])) {
self::deleteFeaturesvalueId($product->id, $feature['feature'], $feature['value']);
} else {
if (!empty($feature['value'])) {
$product->addFeaturesToDB($feature['feature'], $feature['value']);
} elseif ($defaultValue = $this->checkFeaturesMulti($languages, $feature, $error)) {
$idValue = $product->addFeaturesToDB($feature['feature'], 0, 1);
foreach ($languages as $language) {
$valueToAdd = (isset($feature['custom_value'][$language['id_lang']]))
? $feature['custom_value'][$language['id_lang']]
: $defaultValue;
$product->addFeaturesCustomToDB(
$idValue,
(int)$language['id_lang'],
$valueToAdd
);
}
}
}
}
}
} else {
$error[] = $this->l('A product must be created before adding features.');
}
continue;
}
$product_obj->id = $id_product;
$languages = Language::getLanguages(false);
if (Validate::isLoadedObject($product_obj)) {
$this->addToReIndexSearch((int)$product_obj->id);
if (Module::isEnabled('seosaextendedfeatures')) {
foreach ($features as $feature) {
if ($disabled['feature'][$feature['id_feature']]) {
continue;
}
if ($delete_old['feature'][$feature['id_feature']]) {
MassEditTools::deleteFeatures($id_product, array($feature['id_feature']));
}
$feature_name = str_replace(array('[', ']', '(', ')', ' '), '_', $feature['name']);
if (!key_exists($feature_name, $extended_features)
&& !key_exists($feature['name'], $extended_features)) {
continue;
}
$max_position = Db::getInstance()->getValue(
'SELECT MAX(position) FROM `' . _DB_PREFIX_ . 'feature_product`
WHERE `id_feature` = ' . (int)$feature['id_feature']
);
if ($feature['name'] != $feature_name) {
foreach ($extended_features[$feature['name']] as $key => $value) {
if ($key == 'default') {
foreach ($value as $k => $val) {
$id_feature_value = str_replace('number:', '', $val);
$position = $max_position + $k;
$this->addFeatureValueToProduct(
$id_product,
$feature['id_feature'],
$id_feature_value,
$position
);
}
} elseif ($key == 'custom') {
foreach ($value as $k => $val) {
$feature_value = new FeatureValue();
$feature_value->id_feature = $feature['id_feature'];
$feature_value->custom = 1;
$feature_value->value = array();
foreach ($val as $iso => $v) {
$id_lang = Db::getInstance()->getValue(
'SELECT `id_lang` FROM `' . _DB_PREFIX_ . 'lang`
WHERE `iso_code` = "' . pSQL($iso) . '"'
);
$feature_value->value[(string)$id_lang] = $v;
}
$feature_value->save();
if (!$feature_value->id) {
return false;
}
$position = $max_position + $k;
$this->addFeatureValueToProduct(
$id_product,
$feature['id_feature'],
$feature_value->id,
$position
);
}
}
}
foreach ($extended_features[$feature_name] as $key => $value) {
if ($key == 'default') {
foreach ($value as $k => $val) {
$id_feature_value = str_replace('number:', '', $val);
$position = $max_position + $k;
$this->addFeatureValueToProduct(
$id_product,
$feature['id_feature'],
$id_feature_value,
$position
);
}
} elseif ($key == 'custom') {
foreach ($value as $k => $val) {
$feature_value = new FeatureValue();
$feature_value->id_feature = $feature['id_feature'];
$feature_value->custom = 1;
$feature_value->value = array();
foreach ($val as $iso => $v) {
$id_lang = Db::getInstance()->getValue(
'SELECT `id_lang` FROM `' . _DB_PREFIX_ . 'lang`
WHERE `iso_code` = "' . pSQL($iso) . '"'
);
$feature_value->value[(string)$id_lang] = $v;
}
$feature_value->save();
if (!$feature_value->id) {
return false;
}
$position = $max_position + $k;
$this->addFeatureValueToProduct(
$id_product,
$feature['id_feature'],
$feature_value->id,
$position
);
}
}
}
} else {
foreach ($extended_features[$feature_name] as $key => $value) {
if ($key == 'default') {
foreach ($value as $k => $val) {
$id_feature_value = str_replace('number:', '', $val);
$position = $max_position + $k;
$this->addFeatureValueToProduct(
$id_product,
$feature['id_feature'],
$id_feature_value,
$position
);
}
} elseif ($key == 'custom') {
foreach ($value as $k => $val) {
$feature_value = new FeatureValue();
$feature_value->id_feature = $feature['id_feature'];
$feature_value->custom = 1;
$feature_value->value = array();
foreach ($val as $iso => $v) {
$id_lang = Db::getInstance()->getValue(
'SELECT `id_lang` FROM `' . _DB_PREFIX_ . 'lang`
WHERE `iso_code` = "' . pSQL($iso) . '"'
);
$feature_value->value[(string)$id_lang] = $v;
}
$feature_value->save();
if (!$feature_value->id) {
return false;
}
$position = $max_position + $k;
$this->addFeatureValueToProduct(
$id_product,
$feature['id_feature'],
$feature_value->id,
$position
);
}
}
}
}
}
} else {
if ($delete_old) {
MassEditTools::deleteFeatures($product_obj->id, $this->getEnabledFeatures());
}
$exists_features = array_map(
function ($a) {
return $a['id_feature'];
},
$product_obj->getFeatures()
);
foreach ($_POST as $key => $val) {
if (preg_match('/^feature_([0-9]+)_value/i', $key, $match)) {
if (!in_array($match[1], $this->getEnabledFeatures())) {
continue;
}
if ($val) {
if (!in_array($match[1], $exists_features)) {
$product_obj->addFeaturesToDB($match[1], $val);
}
} else {
if ($default_value = $this->checkFeatures($languages, $match[1], $error)) {
if (!array_key_exists($match[1], $this->check_features)) {
$this->check_features[$match[1]] = $default_value;
}
$id_value = $product_obj->addFeaturesToDB($match[1], 0, 1);
foreach ($languages as $language) {
if ($cust = Tools::getValue(
'custom_' . $match[1] . '_' . (int)$language['id_lang']
)) {
$product_obj->addFeaturesCustomToDB(
$id_value,
(int)$language['id_lang'],
$cust
);
} else {
$product_obj->addFeaturesCustomToDB(
$id_value,
(int)$language['id_lang'],
$default_value
);
}
}
}
}
}
}
}
}
}
return array();
}
public function applyChangeForCombinations($products)
{
}
/**
* @param $id_product
* @param $id_feature
* @param $id_feature_value
* @param $max_position
* @return bool
*/
private function addFeatureValueToProduct($id_product, $id_feature, $id_feature_value, $position)
{
$id_product = (int)$id_product;
$id_feature = (int)$id_feature;
$id_feature_value = (int)$id_feature_value;
$position = (int)$position;
$data = array(
'id_product' => $id_product,
'id_feature' => $id_feature,
'id_feature_value' => $id_feature_value,
'position' => $position,
);
return Db::getInstance()->insert('feature_product', $data, false, true, Db::INSERT_IGNORE);
}
protected $check_features = array();
protected function checkFeatures($languages, $feature_id, &$errors)
{
if (array_key_exists($feature_id, $this->check_features)) {
return $this->check_features[$feature_id];
}
$rules = call_user_func(array('FeatureValue', 'getValidationRules'), 'FeatureValue');
$feature = Feature::getFeature((int)Configuration::get('PS_LANG_DEFAULT'), $feature_id);
$val = 0;
foreach ($languages as $language) {
if ($val = Tools::getValue('custom_' . $feature_id . '_' . $language['id_lang'])) {
$current_language = new Language($language['id_lang']);
if (Tools::strlen($val) > $rules['sizeLang']['value']) {
$errors[] = sprintf(
$this->l('The name for feature %1$s is too long in %2$s.'),
' <b>' . $feature['name'] . '</b>',
$current_language->name
);
} elseif (!call_user_func(array('Validate', $rules['validateLang']['value']), $val)) {
$errors[] = sprintf(
$this->l('A valid name required for feature. %1$s in %2$s.'),
' <b>' . $feature['name'] . '</b>',
$current_language->name
);
}
if (count($this->errors)) {
return 0;
}
// Getting default language
if ($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT')) {
return $val;
}
}
}
return 0;
}
protected function checkFeaturesMulti($languages, $featureInfo, &$error)
{
$rules = call_user_func(array('FeatureValue', 'getValidationRules'), 'FeatureValue');
$feature = Feature::getFeature((int) Configuration::get('PS_LANG_DEFAULT'), $featureInfo['feature']);
foreach ($languages as $language) {
if (isset($featureInfo['custom_value'][$language['id_lang']])) {
$val = $featureInfo['custom_value'][$language['id_lang']];
$current_language = new Language($language['id_lang']);
if (Tools::strlen($val) > $rules['sizeLang']['value']) {
$error[] = sprintf(
$this->l('The name for feature %1$s is too long in %2$s.'),
' <b>' . $feature['name'] . '</b>',
$current_language->name
);
} elseif (!call_user_func(array('Validate', $rules['validateLang']['value']), $val)) {
$error[] = sprintf(
$this->l('A valid name required for feature. %1$s in %2$s.'),
' <b>' . $feature['name'] . '</b>',
$current_language->name
);
}
if (count($error)) {
return 0;
}
// Getting default language
if ($language['id_lang'] == Configuration::get('PS_LANG_DEFAULT')) {
return $val;
}
}
}
return 0;
}
public function getTitle()
{
return $this->l('Features');
}
public function assignVariables()
{
$variables = parent::assignVariables();
if (version_compare(_PS_VERSION_, '1.7.5', '>=')) {
$kernel = ${'GLOBALS'}['kernel'];
$container = $kernel->getContainer();
$product = new Product();
$modelMapper = $container->get('prestashop.adapter.admin.model.product');
$formBuilder = $container->get('form.factory')->createBuilder(
Symfony\Component\Form\Extension\Core\Type\FormType::class,
(!empty($product->id)) ? $modelMapper->getFormData($product):null,
['allow_extra_fields' => true]
)
->add('features', Symfony\Component\Form\Extension\Core\Type\CollectionType::class, [
'entry_type' => PrestaShopBundle\Form\Admin\Feature\ProductFeature::class,
'prototype' => true,
'allow_add' => true,
'allow_delete' => true,
]);
$variables['form_multi_features'] = $container->get('twig')->render(
'@PrestaShop/Admin/Product/ProductPage/Forms/form_feature.html.twig',
[
'form' => $formBuilder->getForm()->get('features')->createView()->vars['prototype']
]
);
$text = '<a class="btn tooltip-link delete pl-0 pr-0"><i class="material-icons">delete</i></a>';
$variables['form_multi_features'] = str_replace($text, '<a class="btn tooltip-link delete pl-0 pr-0">
<i class="material-icons">delete</i></a>
<input type="checkbox" name="delete_form_features___name__">'.$this->l('Del').'</input>
</div></div>', $variables['form_multi_features']);
}
$features = MassEditTools::getFeatures($this->context->language->id, true, 1, true);
$variables['features'] = $features;
$variables['total_features'] = MassEditTools::getTotalFeatures();
$variables['count_feature_view'] = MassEditTools::LIMIT_FEATURES;
$variables['link'] = $this->context->link;
$variables['feature_tab_html'] = Module::isEnabled('seosaextendedfeatures');
return $variables;
}
public function deleteFeaturesId($id_product, $id_featurer)
{
$all_shops = Context::getContext()->shop->getContext() == Shop::CONTEXT_ALL ? true : false;
// List products features
$features = Db::getInstance()->executeS(
'
SELECT p.*, f.*
FROM `' . _DB_PREFIX_ . 'feature_product` as p
LEFT JOIN `' . _DB_PREFIX_ . 'feature_value` as f ON (f.`id_feature_value` = p.`id_feature_value`)
' . (!$all_shops ?
'LEFT JOIN `' . _DB_PREFIX_ . 'feature_shop` fs ON (f.`id_feature` = fs.`id_feature`)' : null) . '
WHERE `id_product` = ' . (int) $id_product . ' AND `id_feature = ` . $id_featurer . '
. (!$all_shops ? ' AND fs.`id_shop` = ' . (int) Context::getContext()->shop->id : '')
);
foreach ($features as $tab) {
// Delete product custom features
if ($tab['custom']) {
Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'feature_value`
WHERE `id_feature_value` = ' . (int) $tab['id_feature_value']);
Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'feature_value_lang`
WHERE `id_feature_value` = ' . (int) $tab['id_feature_value']);
}
}
// Delete product features
Db::getInstance()->execute('
DELETE `' . _DB_PREFIX_ . 'feature_product` FROM `' . _DB_PREFIX_ . 'feature_product`
WHERE `id_product` = ' . (int) $id_product . ' AND id_feature = ' . $id_featurer . (!$all_shops ? '
AND `id_feature` IN (
SELECT `id_feature`
FROM `' . _DB_PREFIX_ . 'feature_shop`
WHERE `id_shop` = ' . (int) Context::getContext()->shop->id . '
)' : ''));
SpecificPriceRule::applyAllRules(array((int) $id_product));
}
public function deleteFeaturesvalueId($id_product, $id_featurer, $id_value)
{
$all_shops = Context::getContext()->shop->getContext() == Shop::CONTEXT_ALL ? true : false;
// List products features
$features = Db::getInstance()->executeS(
'
SELECT p.*, f.*
FROM `' . _DB_PREFIX_ . 'feature_product` as p
LEFT JOIN `' . _DB_PREFIX_ . 'feature_value` as f ON (f.`id_feature_value` = p.`id_feature_value`)
' . (!$all_shops ?
'LEFT JOIN `' . _DB_PREFIX_ . 'feature_shop` fs ON (f.`id_feature` = fs.`id_feature`)' : null) . '
WHERE `id_product` = ' . (int) $id_product . '
AND id_feature = ' . $id_featurer . 'AND id_feature_value = ' . $id_value
. (!$all_shops ? ' AND fs.`id_shop` = ' . (int) Context::getContext()->shop->id : '')
);
foreach ($features as $tab) {
// Delete product custom features
if ($tab['custom']) {
Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'feature_value`
WHERE `id_feature_value` = ' . (int) $tab['id_feature_value']);
Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'feature_value_lang`
WHERE `id_feature_value` = ' . (int) $tab['id_feature_value']);
}
}
// Delete product features
Db::getInstance()->execute('
DELETE `' . _DB_PREFIX_ . 'feature_product` FROM `' . _DB_PREFIX_ . 'feature_product`
WHERE `id_product` = ' . (int) $id_product . '
AND id_feature = ' . $id_featurer . ' AND id_feature_value = ' . $id_value . (!$all_shops ? '
AND `id_feature` IN (
SELECT `id_feature`
FROM `' . _DB_PREFIX_ . 'feature_shop`
WHERE `id_shop` = ' . (int) Context::getContext()->shop->id . '
)' : ''));
}
}

View File

@@ -0,0 +1,217 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ImageTabMEP extends BaseTabMEP
{
public $response_images;
public $delete_images;
public function __construct()
{
parent::__construct();
$this->response_images = Tools::getValue('responseImages');
$this->delete_images = (int)Tools::getValue('delete_images');
}
public function applyChangeBoth($products, $combinations)
{
if ($this->checkAccessField('disable_image_caption')) {
$in = implode(
',',
array_map('intval', $products)
);
$sub_sql = 'SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image_shop`
WHERE `id_product` IN(' . pSQL($in) . ') AND `id_shop` = ' . (int)$this->context->shop->id;
if (Tools::getValue('delete_captions')) {
$sql = 'UPDATE `'. _DB_PREFIX_ .'image_lang` SET `legend` = "" WHERE `id_image` IN('.pSQL($sub_sql).')';
if (!Db::getInstance()->execute($sql)) {
LoggerMEP::getInstance()->error($this->l('Failed to remove caption'));
}
}
$reg = '|{([^{}]{4,})}|u';
foreach (Language::getLanguages(true, false, true) as $lang) {
$legend = Tools::getValue('legend_' . $lang);
$where_position = Tools::getValue('position')
? ' AND `position` = ' . (int)Tools::getValue('position') : '';
$sub_sql .= $where_position;
$join = '';
preg_match_all($reg, $legend, $matches);
if (count($matches[1])) {
foreach ($matches[1] as $column) {
switch ($column) {
case 'name':
$legend = str_replace('{name}', '\', pl.name, \'', $legend);
$join .= ' JOIN `'. _DB_PREFIX_ .'product_lang` pl
ON p.`id_product` = pl.`id_product` and pl.`id_lang` = ' . $lang .'';
break;
case 'category':
$legend = str_replace('{category}', '\', cl.name, \'', $legend);
$join .= ' JOIN `' . _DB_PREFIX_
. 'category_lang` cl
ON p.`id_category_default` = cl.`id_category` and cl.`id_lang` = ' . $lang .'';
break;
case 'manufacturer':
$legend = str_replace('{manufacturer}', '\', m.name, \'', $legend);
$join .= ' JOIN `' . _DB_PREFIX_
. 'manufacturer` m ON p.`id_manufacturer` = m.`id_manufacturer`';
break;
}
}
}
if ($legend && $legend[0] !== ',') {
$legend = '\'' . $legend;
} else {
$legend = ltrim($legend, ', \'');
}
if ($legend && $legend[Tools::strlen($legend) - 3] !== ',') {
$legend = $legend . '\'';
} else {
$legend = rtrim($legend, ', \'');
}
$column_legend = $legend ? 'CONCAT(' . $legend . ')' : '" "';
$sql = 'UPDATE `' . _DB_PREFIX_ . 'image_lang` il,
(SELECT i.`id_image`, ' . $column_legend . ' as legend
FROM `'. _DB_PREFIX_ .'product` p JOIN `'. _DB_PREFIX_ .'image` i
ON p.`id_product` = i.`id_product` '. $join .'
WHERE p.`id_product` IN(' . pSQL($in) . ')' . $where_position . ') temp
SET il.`legend` = temp.`legend`
WHERE il.`id_image` = temp.`id_image` AND il.`id_lang` = ' . $lang;
if (!Db::getInstance()->execute($sql)) {
LoggerMEP::getInstance()->error($this->l('Failed to change caption'));
}
}
}
}
public function applyChangeForProducts($products)
{
if ($this->checkAccessField('disable_image')) {
foreach ($products as $id_product) {
$this->applyImages($id_product);
}
MassEditTools::clearTmpFolder();
}
return array();
}
public function applyChangeForCombinations($products)
{
if ($this->checkAccessField('disable_image')) {
foreach ($products as $id_product => $combinations) {
$this->applyImages($id_product, $combinations);
}
MassEditTools::clearTmpFolder();
}
return array();
}
public function checkBeforeChange()
{
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function checkOptionForCombination()
{
$change_for = (int)Tools::getValue('change_for');
if ($change_for == self::CHANGE_FOR_COMBINATION) {
return true;
}
return false;
}
public function applyImages($id_product, $combinations = null)
{
$types = ImageType::getImagesTypes('products');
$product_obj = new Product((int)$id_product);
if ($this->delete_images) {
$product_obj->deleteImages();
}
if (is_array($this->response_images)) {
$cover = $product_obj->getCoverWs();
foreach ($this->response_images as $response_image) {
if (array_key_exists('original', $response_image)) {
$image = new Image();
$image->id_product = (int)$id_product;
if (!$cover) {
$image->cover = 1;
}
if ($image->save()) {
if (!$cover) {
$cover = $image->id;
}
$image->createImgFolder();
call_user_func(
'copy',
MassEditTools::getPath() . $response_image['original'],
_PS_PROD_IMG_DIR_ . $image->getImgPath() . '.jpg'
);
foreach ($types as $type) {
if (array_key_exists($type['name'], $response_image)) {
call_user_func(
'copy',
MassEditTools::getPath() . $response_image[$type['name']],
_PS_PROD_IMG_DIR_ . $image->getImgPath() . '-' . $type['name'] . '.jpg'
);
}
}
if (!is_null($combinations)) {
$product_attribute_image = array();
foreach ($combinations as $id_pa) {
$product_attribute_image[] = array(
'id_image' => $image->id,
'id_product_attribute' => (int)$id_pa,
);
}
Db::getInstance()->insert('product_attribute_image', $product_attribute_image);
}
}
}
}
}
MassEditTools::removeTmpImageProduct($product_obj->id);
}
public function getTitle()
{
return $this->l('Image');
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ManufacturerTabMEP extends BaseTabMEP
{
public $id_manufacturer;
public $manufacturer;
public function __construct()
{
parent::__construct();
$this->id_manufacturer = (int)Tools::getValue('id_manufacturer');
if ($this->id_manufacturer === 0) {
$this->manufacturer = new Manufacturer();
$this->manufacturer->name = '';
} else {
$this->manufacturer = new Manufacturer(
$this->id_manufacturer,
$this->context->language->id
);
}
}
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
Db::getInstance()->update(
'product',
array(
'id_manufacturer' => (int)$this->manufacturer->id,
),
' id_product IN(' . pSQL(implode(',', $products)) . ')'
);
$return_products = array();
foreach ($products as $product) {
$return_products[(int)$product] = $this->manufacturer->name;
}
return array(
'products' => $return_products,
);
}
public function applyChangeForCombinations($products)
{
}
public function checkBeforeChange()
{
if (!$this->manufacturer->id) {
$this->manufacturer->id = 0;
return true;
}
if (!Validate::isLoadedObject($this->manufacturer)) {
LoggerMEP::getInstance()->error($this->l('Manufacturer not exists'));
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function getTitle()
{
return $this->l('Manufacturer');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['manufacturers'] = Manufacturer::getManufacturers(
false,
0,
true,
false,
false,
false,
true
);
return $variables;
}
}

View File

@@ -0,0 +1,258 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class MetaTabMEP extends BaseTabMEP
{
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
${'_POST'}['products'] = false;
$meta_title = Tools::getValue('meta_title');
$meta_description = Tools::getValue('meta_description');
$meta_keywords = Tools::getValue('meta_keywords');
$meta_chpu = Tools::getValue('meta_chpu');
$tags = trim(Tools::getValue('tags'));
$language = (int)Tools::getValue('language');
$edit_tags = (int)Tools::getValue('edit_tags');
$meta_redirect = Tools::getValue('meta_redirect');
$category_redirect = Tools::getValue('category_redirect');
$product_redirect = Tools::getValue('product_redirect');
if ($this->checkAccessField('tags') && $edit_tags == 2) {
$array_tags = explode(",", $tags);
$data_for_tag = '';
foreach ($products as $id_product) {
foreach ($array_tags as $tag) {
if (Tools::substr($tag, 0, 1) == '{' && Tools::substr($tag, -1) == '}') {
$data_for_tag = $data_for_tag . '"' . MassEditTools::renderMetaTag(
$tag,
(int)$id_product,
$language
) . '"' . ',';
} else {
$data_for_tag = $data_for_tag . '"' . $tag . '",';
}
}
}
$tags = $tags_sql = Tools::substr($data_for_tag, 0, -1);
if ($tags) {
$sql = 'SELECT * FROM `' . _DB_PREFIX_ . 'tag` WHERE `name` IN (' .$tags .')';
$res = Db::getInstance()->executeS($sql);
}
$where = 'id_product IN (' . pSQL(implode(',', $products)) . ')';
$tag_list = array();
if (isset($res) && is_array($res)) {
$in = '';
foreach ($res as $tag) {
$in .= $tag['id_tag'] . ', ';
}
$in = rtrim($in, ', ');
if (strpos($in, ',')) {
$where .= ' AND id_tag IN (' . pSQL($in) . ')';
} else {
if ($in != 0) {
$where .= ' AND id_tag="' . (int)$in . '"';
}
}
foreach ($res as $tag_removed) {
$tag_list[] = $tag_removed['id_tag'];
}
} else {
$tags_removed = Db::getInstance()->executeS(
'SELECT id_tag FROM ' . _DB_PREFIX_ . 'product_tag WHERE ' . pSQL($where)
);
$tag_list = array();
foreach ($tags_removed as $tag_removed) {
$tag_list[] = $tag_removed['id_tag'];
}
}
Db::getInstance()->delete('product_tag', $where);
Db::getInstance()->delete(
'tag',
'NOT EXISTS (SELECT 1 FROM ' . _DB_PREFIX_ . 'product_tag
WHERE ' . _DB_PREFIX_ . 'product_tag.id_tag = ' . _DB_PREFIX_ . 'tag.id_tag)'
);
if ($tag_list != array()) {
Tag::updateTagCount($tag_list);
}
}
foreach ($products as $id_product) {
$data_for_update = array();
if ($this->checkAccessField('meta_title')) {
$meta_title_result = MassEditTools::renderMetaTag($meta_title, (int)$id_product, $language);
$data_for_update['meta_title'] = $meta_title_result;
}
if ($this->checkAccessField('meta_redirect') && $meta_redirect != "--") {
$red = tools::getvalue('meta_redirect');
if ($red == '301-product' || $red == '302-product') {
$red_type = $product_redirect;
}
if ($red == '301-category' || $red == '302-category') {
$red_type = $category_redirect;
}
if ($red == '404') {
$red_type = 0;
}
Db::getInstance()->execute('
UPDATE `' . _DB_PREFIX_ . 'product_shop` p
SET p.redirect_type = "' . $red . '", p.id_type_redirected = ' . (int)$red_type . '
WHERE p.id_product = ' . (int)$id_product . '');
}
if ($this->checkAccessField('meta_description')) {
$meta_description_result = MassEditTools::renderMetaTag(
$meta_description,
(int)$id_product,
$language
);
$data_for_update['meta_description'] = addslashes($meta_description_result);
}
if ($this->checkAccessField('meta_keywords')) {
$meta_keywords_result = MassEditTools::renderMetaTag($meta_keywords, (int)$id_product, $language);
$data_for_update['meta_keywords'] = $meta_keywords_result;
}
if ($this->checkAccessField('meta_chpu')) {
$meta_chpu_result = MassEditTools::renderMetaTag($meta_chpu, (int)$id_product, $language);
$meta_chpu_result = preg_replace('/\s+/', '-', $meta_chpu_result);
$meta_chpu_result = str_replace("'", '-', $meta_chpu_result);
if (Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL') == ''
|| Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL') == 0) {
$meta_chpu_result = Seochar::convertseo($meta_chpu_result);
}
$data_for_update['link_rewrite'] = $meta_chpu_result;
}
if ($this->checkAccessField('tags') && $edit_tags != 2) {
if ($edit_tags == 0 || $edit_tags == 1) {
if ($edit_tags == 1) {
Tag::deleteTagsForProduct((int)$id_product);
}
if ($edit_tags == 0 || $edit_tags == 1) {
$data_for_tag = '';
$tags2 = trim(Tools::getValue('tags'));
$array_tags = explode(",", $tags2);
foreach ($array_tags as $tag) {
if (Tools::substr($tag, 0, 1) == '{' && Tools::substr($tag, -1) == '}') {
$data_for_tag = $data_for_tag . '"' . MassEditTools::renderMetaTag(
$tag,
(int)$id_product,
$language
) . '"' . ',';
} else {
$data_for_tag = $data_for_tag . '"' . $tag . '",';
}
}
$tags_sql = Tools::substr($data_for_tag, 0, -1);
$where = strpos($tags_sql, ',') ?
' WHERE `name` IN (' . $tags_sql . ')' : ' WHERE `name`="' . $tags_sql . '"';
$matching_tags = Db::getInstance()->executeS(
'SELECT * FROM `' . _DB_PREFIX_ . 'tag` p
JOIN `' . _DB_PREFIX_ . 'product_tag` pt ON p.`id_tag`=pt.`id_tag`' . $where
);
$tags = str_replace('"', '', $tags_sql);
// if (strpbrk($tags, '!<;>;?=+#"{}_$%')) {
// LoggerMEP::getInstance()->error($this->l('Invalid characters for tag'));
// return array();
// }
// if ($matching_tags) {
// $temp_tags = trim(Tools::getValue('tags'));
// foreach ($matching_tags as $mt) {
// if ($mt['id_product'] == $id_product) {
// $temp_tags = preg_replace('/,?' . $mt['name'] . '/i', '', $temp_tags);
// }
// }
// $tags = trim($temp_tags, ',');
// }
}
if ($tags) {
foreach (Language::getLanguages(false) as $lang) {
Tag::addTags((int)$lang['id_lang'], (int)$id_product, $tags);
}
}
}
}
if (count($data_for_update)) {
Db::getInstance()->update(
'product_lang',
$data_for_update,
' id_product = ' . (int)$id_product
. ($language ? ' AND id_lang = ' . (int)$language : '')
. ' ' . (Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop ' . $this->sql_shop : '')
);
}
}
return array();
}
public function applyChangeForCombinations($products)
{
}
public function getTitle()
{
return $this->l('Meta');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['static_for_name'] = array(
'{title}' => $this->l('title'),
'{name}' => $this->l('name product'),
'{price}' => $this->l('price final'),
'{manufacturer}' => $this->l('manufacturer'),
'{category}' => $this->l('default category'),
'{reference}' => $this->l('product reference'),
);
return $variables;
}
}

View File

@@ -0,0 +1,720 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class PriceTabMEP extends BaseTabMEP
{
const TYPE_PRICE_BASE = 0;
const TYPE_PRICE_FINAL = 1;
const TYPE_PRICE_WHOLESALE = 2;
const CHANGE_FOR_PRODUCT = 0;
const CHANGE_FOR_COMBINATION = 1;
public $currency;
public $type_price;
public $action_price;
public $price_value;
public $not_change_final_price;
public $country;
public $address;
public $id_shop;
public $unity;
public $unity_price;
public $type_price_r;
public $action_direction;
public $action_rounding_value;
public function __construct()
{
parent::__construct();
$this->currency = Currency::getCurrency(Configuration::get('PS_CURRENCY_DEFAULT'));
$this->currency['decimals'] = 1;
$this->type_price = (int)Tools::getValue('type_price');
$this->action_price = (int)Tools::getValue('action_price');
$this->price_value = (float)Tools::getValue('price_value');
$this->not_change_final_price = Tools::getValue('not_change_final_price');
$this->country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'));
$this->address = new Address();
$this->address->id_country = $this->country->id;
$this->id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP
? (int)$this->context->shop->id : 'p.id_shop_default';
$this->unity = Tools::getValue('unity');
$this->unity_price = Tools::getValue('unity_price');
$this->type_price_r = Tools::getValue('type_price_r');
$this->action_direction = Tools::getValue('action_direction');
$this->action_rounding_value = Tools::getValue('action_rounding_value');
}
public function checkBeforeChange()
{
if ($this->checkAccessField('price') && !(float)$this->price_value) {
LoggerMEP::getInstance()->error($this->l('Write value'));
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function getQueryProducts($ids)
{
$query_products = Db::getInstance()->executeS(
'SELECT
p.`id_product`,
pss.`price`,
pss.`wholesale_price`,
p.`unity`
FROM ' . _DB_PREFIX_ . 'product p
JOIN `' . _DB_PREFIX_ . 'product_shop` pss ON (p.`id_product` = pss.`id_product` AND pss.id_shop = ' . pSQL(
$this->id_shop
) . ')
WHERE p.`id_product` IN (' . pSQL(
implode(',', array_map('intval', $ids))
) . ')'
);
return (is_array($query_products) ? $query_products : array());
}
public function applyChangeForProducts($products)
{
$return_products = array();
$query_products = $this->getQueryProducts($products);
if ($this->checkAccessField('price')) {
foreach ($query_products as $product) {
if ($this->type_price === self::TYPE_PRICE_WHOLESALE) {
$wholesale_price = $product['wholesale_price'];
$new_price = MassEditTools::actionPrice(
$wholesale_price,
$this->action_price,
$this->price_value
);
// Подключить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.9', '>=')) {
$return_products[$product['id_product']] = array(
'wholesale_price' => $this->context->currentLocale->formatPrice(
$new_price,
$this->context->currency->iso_code
),
);
} else {
$return_products[$product['id_product']] = array(
'wholesale_price' => Tools::displayPrice($new_price, $this->currency),
);
}
MassEditTools::updateWholePriceProduct(
$product['id_product'],
$new_price
);
} else {
$price = 0;
if ((int)Configuration::get('PS_TAX')) {
$tax_manager = TaxManagerFactory::getManager(
$this->address,
Product::getIdTaxRulesGroupByIdProduct((int)$product['id_product'], $this->context)
);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product['price_final'] = $product_tax_calculator->addTaxes($product['price']);
$product['rate'] = $tax_manager->getTaxCalculator()->getTotalRate();
} else {
$product['price_final'] = $product['price'];
$product['rate'] = 0;
}
if ($this->type_price === self::TYPE_PRICE_BASE) {
$price = $product['price'];
} else {
if ($this->type_price === self::TYPE_PRICE_FINAL) {
$price = $product['price_final'];
}
}
$price = MassEditTools::actionPrice(
$price,
$this->action_price,
$this->price_value
);
$final_price = 0;
if ($this->type_price === self::TYPE_PRICE_FINAL) {
$final_price = $price;
if (Configuration::get('PS_TAX')) {
$price = $price / (100 + (float)$product['rate']) * 100;
}
} else {
if ($this->type_price === self::TYPE_PRICE_BASE) {
if (Configuration::get('PS_TAX')) {
$final_price = $price + ($price / 100 * (float)$product['rate']);
} else {
$final_price = $price;
}
}
}
MassEditTools::updatePriceProduct($product['id_product'], $price);
// Заменить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.8', '>=')) {
$return_products[$product['id_product']] = array(
'price' => $this->context->currentLocale->formatPrice(
$price,
$this->context->currency->iso_code
),
'price_final' => $this->context->currentLocale->formatPrice(
$final_price,
$this->context->currency->iso_code
),
);
} else {
$return_products[$product['id_product']] = array(
'price' => Tools::displayPrice($price, $this->currency),
'price_final' => Tools::displayPrice($final_price, $this->currency),
);
}
}
}
} elseif ($this->checkAccessField('tax_rule_group') && is_array($query_products)) {
foreach ($query_products as $query_product) {
$price = $query_product['price'];
if ($this->not_change_final_price) {
$product_obj = new Product((int)$query_product['id_product']);
$new_tax_rule_arr = TaxRule::getTaxRulesByGroupId(
Configuration::get('PS_LANG_DEFAULT'),
(int)Tools::getValue('id_tax_rules_group')
);
$price = (100 + $product_obj->getTaxesRate())
/ (100 + $new_tax_rule_arr[0]['rate']) * $product_obj->price;
MassEditTools::updateObjectField(
'Product',
'price',
(int)$query_product['id_product'],
Tools::ps_round($price, 6)
);
}
MassEditTools::updateObjectField(
'Product',
'id_tax_rules_group',
(int)$query_product['id_product'],
(int)Tools::getValue('id_tax_rules_group')
);
$product = new Product($query_product['id_product']);
$final_price = $product->getPrice(true, null, 6);
// Заменить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.9', '>=')) {
$return_products[(int)$query_product['id_product']] = array(
'price' => $this->context->currentLocale->formatPrice(
$price,
$this->context->currency->iso_code
),
'price_final' => $this->context->currentLocale->formatPrice(
$final_price,
$this->context->currency->iso_code
),
);
} else {
$return_products[(int)$query_product['id_product']] = array(
'price' => Tools::displayPrice($price, $this->currency),
'price_final' => Tools::displayPrice($final_price, $this->currency),
);
}
}
} elseif ($this->checkAccessField('unity')) {
$final_price = 0;
foreach ($query_products as $query_product) {
$product = new Product($query_product['id_product']);
if (version_compare(_PS_VERSION_, '1.7', '>')) {
$final_price = $product->price / Tools::getValue('unity_price');
} else {
$final_price = Tools::ps_round($product->price / Tools::getValue('unity_price'), 6);
}
MassEditTools::updateObjectField(
'Product',
'unit_price_ratio',
(int)$query_product['id_product'],
(float)$final_price
);
if (Tools::getValue('unity') != "") {
MassEditTools::updateObjectField(
'Product',
'unity',
(int)$query_product['id_product'],
Tools::getValue('unity')
);
}
}
} elseif ($this->checkAccessField('price_round')) {
foreach ($query_products as $product_r) {
$product = new Product($product_r['id_product']);
if ((int)Configuration::get('PS_TAX')) {
$tax_manager = TaxManagerFactory::getManager(
$this->address,
Product::getIdTaxRulesGroupByIdProduct((int)$product_r['id_product'], $this->context)
);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product_r['price_final'] = $product_tax_calculator->addTaxes($product_r['price']);
$product_r['rate'] = $tax_manager->getTaxCalculator()->getTotalRate();
} else {
$product_r['price_final'] = $product_r['price'];
$product_r['rate'] = 0;
}
if ((int)$this->type_price_r === self::TYPE_PRICE_BASE) {
$type_price = $product_r['price'];
} elseif ((int)$this->type_price_r === self::TYPE_PRICE_FINAL) {
$type_price = $product_r['price_final'];
} else {
$type_price = $product_r['wholesale_price'];
}
$price_round = MassEditTools::actionPriceRound(
$type_price,
(int)$this->action_direction,
$this->action_rounding_value
);
if ((int)$this->type_price_r === self::TYPE_PRICE_BASE) {
MassEditTools::updatePriceProduct($product_r['id_product'], $price_round);
} elseif ((int)$this->type_price_r === self::TYPE_PRICE_FINAL) {
if ((int)Configuration::get('PS_TAX')) {
$price_round = $price_round / (1 + $product_r['rate'] / 100);
}
MassEditTools::updatePriceProduct($product_r['id_product'], $price_round);
} else {
MassEditTools::updateWholePriceProduct($product_r['id_product'], $price_round);
}
$final_price = $product->getPrice(true, null, 6);
// Заменить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.9', '>=')) {
$return_products[$product_r['id_product']] = array(
'price' => $this->context->currentLocale->formatPrice(
$price_round,
$this->context->currency->iso_code
),
'price_final' => $this->context->currentLocale->formatPrice(
$final_price,
$this->context->currency->iso_code
),
);
} else {
$return_products[$product_r['id_product']] = array(
'price' => Tools::displayPrice($price_round, $this->currency),
'price_final' => Tools::displayPrice($final_price, $this->currency),
);
}
}
}
return array(
'products' => $return_products
);
}
public function applyChangeForCombinations($products)
{
$return_products = array();
$return_combinations = array();
$query_products = $this->getQueryProducts(
array_keys($products)
);
if ($this->checkAccessField('price')) {
foreach ($query_products as $product) {
if ($this->type_price === self::TYPE_PRICE_WHOLESALE) {
$wholesale_price = $product['wholesale_price'];
$new_price = MassEditTools::actionPrice(
$wholesale_price,
$this->action_price,
$this->price_value
);
// Заменить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.9', '>=')) {
$return_products[$product['id_product']] = array(
'wholesale_price' => $this->context->currentLocale->formatPrice(
$new_price,
$this->context->currency->iso_code
),
);
} else {
$return_products[$product['id_product']] = array(
'wholesale_price' => Tools::displayPrice($new_price, $this->currency),
);
}
if (array_key_exists(
$product['id_product'],
$products
)) {
$combinations = MassEditTools::getCombinationsByIds(
$products[$product['id_product']],
$this->id_shop
);
$update_combinations = array();
foreach ($combinations as $combination) {
$combination_wholesale = $combination['wholesale_price'];
$new_combination_wholesale = MassEditTools::actionPrice(
$combination_wholesale,
$this->action_price,
$this->price_value
);
// Заменить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.9', '>=')) {
$return_combinations[$combination['id_product_attribute']] = array(
'wholesale_price' => $this->context->currentLocale->formatPrice(
$new_combination_wholesale,
$this->context->currency->iso_code
),
);
} else {
$return_combinations[$combination['id_product_attribute']] = array(
'wholesale_price' => Tools::displayPrice(
$new_combination_wholesale,
$this->currency
),
);
}
$update_combinations[$combination['id_product_attribute']] = $new_combination_wholesale;
}
}
if (isset($update_combinations) && count(
$update_combinations
)) {
foreach ($update_combinations as $id_pa => $pa_price) {
MassEditTools::updateWholePriceCombination($id_pa, $pa_price);
}
}
} else {
$price = 0;
if ((int)Configuration::get('PS_TAX')) {
$tax_manager = TaxManagerFactory::getManager(
$this->address,
Product::getIdTaxRulesGroupByIdProduct(
(int)$product['id_product'],
$this->context
)
);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product['price_final'] = $product_tax_calculator->addTaxes($product['price']);
$product['rate'] = $tax_manager->getTaxCalculator()->getTotalRate();
} else {
$product['price_final'] = $product['price'];
$product['rate'] = 0;
}
$update_combinations = array();
if ($this->type_price === self::TYPE_PRICE_BASE) {
$price = $product['price'];
} else {
if ($this->type_price === self::TYPE_PRICE_FINAL) {
$price = $product['price_final'];
}
}
if (array_key_exists(
$product['id_product'],
$products
)) {
$combinations = MassEditTools::getCombinationsByIds(
$products[$product['id_product']],
$this->id_shop
);
foreach ($combinations as $combination) {
$price_pa = $combination['price'];
$price_pa_final = $price_pa;
$product_price = $combination['product_price'];
$product_price_final = $combination['product_price_final'];
if ($this->type_price === self::TYPE_PRICE_BASE) {
$new_price_pa = MassEditTools::actionPrice(
$price_pa,
$this->action_price,
$this->price_value
);
if (isset($tax_manager)) {
$price_pa_final = $product_tax_calculator->addTaxes(
MassEditTools::actionPrice(
$new_price_pa,
$this->action_price,
$this->price_value
)
);
}
} else {
if ($this->type_price === self::TYPE_PRICE_FINAL) {
$new_price_pa = MassEditTools::actionPrice(
$price_pa,
$this->action_price,
$this->price_value
);
$price_pa_final = $new_price_pa;
$new_price_pa = ($new_price_pa / (100 + (float)$product['rate']) * 100);
}
}
// Заменить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.9', '>=')) {
$return_combinations[$combination['id_product_attribute']] = array(
'price' => $this->context->currentLocale->formatPrice(
$new_price_pa,
$this->context->currency->iso_code
),
'total_price' => $this->context->currentLocale->formatPrice(
$product_price + $new_price_pa,
$this->context->currency->iso_code
),
'price_final' => $this->context->currentLocale->formatPrice(
$price_pa_final,
$this->context->currency->iso_code
),
'total_price_final' => $this->context->currentLocale->formatPrice(
$product_price_final + $price_pa_final,
$this->context->currency->iso_code
),
);
} else {
$return_combinations[$combination['id_product_attribute']] = array(
'price' => Tools::displayPrice($new_price_pa, $this->currency),
'total_price' => Tools::displayPrice($product_price + $new_price_pa, $this->currency),
'price_final' => Tools::displayPrice($price_pa_final, $this->currency),
'total_price_final' => Tools::displayPrice(
$product_price_final + $price_pa_final,
$this->currency
),
);
}
$update_combinations[$combination['id_product_attribute']] = $new_price_pa;
}
}
$final_price = 0;
if ($this->type_price === self::TYPE_PRICE_FINAL) {
$final_price = $price;
if (Configuration::get('PS_TAX')) {
$price = $price / (100 + (float)$product['rate']) * 100;
}
} else {
if ($this->type_price === self::TYPE_PRICE_BASE) {
if (Configuration::get('PS_TAX')) {
$final_price = $price + ($price / 100 * (float)$product['rate']);
} else {
$final_price = $price;
}
}
}
if (count($combinations)) {
foreach ($combinations as $id) {
// увеличить на значение
if ($this->action_price == 2) {
if ($this->type_price == 1) {
$rest = (($id['total_price_final'] + $this->price_value)
- $id['product_price_final']) / (1 + (float)$product['rate'] / 100);
$pa_price = $rest;
$id_pa = $id['id_product_attribute'];
} else {
$rest = ($id['price'] + $this->price_value);
$pa_price = $rest;
$id_pa = $id['id_product_attribute'];
}
}
// Уменьшить на значение
if ($this->action_price == 4) {
if ($this->type_price == 1) {
$rest = (($id['total_price_final'] - $this->price_value)
- $id['product_price_final']) / (1 + (float)$product['rate'] / 100);
$pa_price = $rest;
$id_pa = $id['id_product_attribute'];
} else {
$rest = ($id['price'] - $this->price_value);
$pa_price = $rest;
$id_pa = $id['id_product_attribute'];
}
}
// Увеличить на процент
if ($this->action_price == 1) {
if ($this->type_price == 1) {
$rest = ($id['total_price_final'] + ($id['total_price_final'] / 100
* $this->price_value) - $id['product_price_final'])
/ (1 + (float)$product['rate'] / 100);
$pa_price = $rest;
$id_pa = $id['id_product_attribute'];
} else {
$rest = $id['price'] + ($id['price']/100)*$this->price_value;
$pa_price = $rest;
$id_pa = $id['id_product_attribute'];
}
}
// Уменьшить на процент
if ($this->action_price == 3) {
if ($this->type_price == 1) {
$rest = ($id['total_price_final'] - ($id['total_price_final']/100
* $this->price_value)
- $id['product_price_final']) / (1 + (float)$product['rate'] / 100);
$pa_price = $rest;
$id_pa = $id['id_product_attribute'];
} else {
$rest = $id['price'] - ($id['price']/100)*$this->price_value;
$pa_price = $rest;
$id_pa = $id['id_product_attribute'];
}
}
// перезаписать значение
if ($this->action_price == 5) {
if ($this->type_price == 1) {
$pa_price = $this->price_value / (1 + (float)$product['rate'] / 100);
$id_pa = $id['id_product_attribute'];
} else {
$pa_price = $this->price_value;
$id_pa = $id['id_product_attribute'];
}
}
MassEditTools::updatePriceCombination($id_pa, $pa_price);
}
}
// Заменить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.9', '>=')) {
$return_products[$product['id_product']] = array(
'price' => $this->context->currentLocale->formatPrice(
$price,
$this->context->currency->iso_code
),
'price_final' => $this->context->currentLocale->formatPrice(
$final_price,
$this->context->currency->iso_code
),
);
} else {
$return_products[$product['id_product']] = array(
'price' => Tools::displayPrice($price, $this->currency),
'price_final' => Tools::displayPrice($final_price, $this->currency),
);
}
}
}
} elseif ($this->checkAccessField('tax_rule_group') && is_array($query_products)) {
foreach ($query_products as $query_product) {
$price = $query_product['price'];
if ($this->not_change_final_price) {
$product_obj = new Product((int)$query_product['id_product']);
$new_tax_rule_arr = TaxRule::getTaxRulesByGroupId(
Configuration::get('PS_LANG_DEFAULT'),
(int)Tools::getValue('id_tax_rules_group')
);
$price = (100 + $product_obj->getTaxesRate())
/ (100 + $new_tax_rule_arr[0]['rate']) * $product_obj->price;
MassEditTools::updateObjectField(
'Product',
'price',
(int)$query_product['id_product'],
Tools::ps_round($price, 6)
);
}
MassEditTools::updateObjectField(
'Product',
'id_tax_rules_group',
(int)$query_product['id_product'],
(int)Tools::getValue('id_tax_rules_group')
);
$product = new Product($query_product['id_product']);
$final_price = $product->getPrice(true, null, 6);
// Заменить если не работает на версии 1768
// $this->context->currentLocale на Tools::getContextLocale($this->context)
if (version_compare(_PS_VERSION_, '1.7.6.9', '>=')) {
$return_products[(int)$query_product['id_product']] = array(
'price' => $this->context->currentLocale->formatPrice(
$price,
$this->context->currency->iso_code
),
'price_final' => $this->context->currentLocale->formatPrice(
$final_price,
$this->context->currency->iso_code
),
);
} else {
$return_products[(int)$query_product['id_product']] = array(
'price' => Tools::displayPrice($price, $this->currency),
'price_final' => Tools::displayPrice($final_price, $this->currency),
);
}
}
}
return array(
'products' => $return_products,
'combinations' => $return_combinations,
);
}
public function applyChangeBoth($products, $combinations)
{
}
public function checkOptionForCombination()
{
$change_for = (int)Tools::getValue('change_for');
return $change_for == self::CHANGE_FOR_COMBINATION;
}
public function getTitle()
{
return $this->l('Price');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$tax_rules_groups = TaxRulesGroup::getTaxRulesGroups(true);
$variables['tax_rules_groups'] = $tax_rules_groups;
$variables['tax_exclude_taxe_option'] = Tax::excludeTaxeOption();
$variables['currency'] = $this->context->currency;
return $variables;
}
}

View File

@@ -0,0 +1,397 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class QuantityTabMEP extends BaseTabMEP
{
const CHANGE_TYPE_QUANTITY = 'quantity';
const CHANGE_TYPE_WAREHOUSE = 'warehouse';
public $quantity;
public $action_quantity;
public $change_type;
public $language;
public $available_now;
public $available_later;
public $change_available_date;
public $available_date;
public $out_of_stock;
public $minimal_quantity;
public $id_warehouse;
public $action_warehouse;
public $warehouse;
public $stock_manager;
public $check_access_field_quantity;
public $low_stock_threshold;
public $low_stock_alert;
public $location;
public function __construct()
{
parent::__construct();
$this->quantity = (int)Tools::getValue('quantity', 0);
$this->action_quantity = (int)Tools::getValue('action_quantity');
$this->change_type = Tools::getValue('change_type');
$this->language = Tools::getValue('language');
$this->language2 = Tools::getValue('language2');
$this->available_now = Tools::getValue('available_now');
$this->available_later = Tools::getValue('available_later');
$this->change_available_date = (int)Tools::getValue('change_available_date');
$this->available_date = Tools::getValue('available_date');
$this->out_of_stock = Tools::getValue('out_of_stock');
$this->minimal_quantity = Tools::getValue('minimal_quantity');
$this->low_stock_threshold = Tools::getValue('low_stock_threshold');
$this->low_stock_alert = Tools::getValue('low_stock_alert');
$this->location = Tools::getValue('location');
$this->id_warehouse = (int)Tools::getValue('warehouse');
$this->action_warehouse = (int)Tools::getValue('action_warehouse');
$this->warehouse = new Warehouse($this->id_warehouse);
$this->stock_manager = new StockManager();
$this->check_access_field_quantity = $this->checkAccessField('quantity');
$this->check_access_field_location = $this->checkAccessField('location');
$this->check_access_field_low_stock_alert = $this->checkAccessField('low_stock_alert');
}
public function checkBeforeChange()
{
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$this->change_type = self::CHANGE_TYPE_QUANTITY;
}
if (!$this->change_type) {
LoggerMEP::getInstance()->error($this->l('Please, set option "Management quantity in"'));
}
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && !Validate::isLoadedObject($this->warehouse)
&& $this->change_type == 'warehouse') {
LoggerMEP::getInstance()->error($this->l('Selected warehouse not found!'));
}
if ($this->checkAccessField('available_date') && !Validate::isDateFormat($this->available_date)) {
LoggerMEP::getInstance()->error($this->l('Available date invalid!'));
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function applyChangeForCombinations($products)
{
$return_combinations = array();
$id_shop = null;
foreach ($products as $id_product => $combinations) {
foreach ($combinations as $id_pa) {
// if (!$this->check_access_field_quantity) {
// continue;
// }
if ($this->check_access_field_location || $this->check_access_field_low_stock_alert) {
$combination = new Combination((int)$id_pa);
if ($this->check_access_field_location) {
if (!empty($this->low_stock_threshold)) {
$combination->low_stock_threshold = $this->low_stock_threshold;
} else {
$combination->low_stock_threshold = null;
}
}
if ($this->check_access_field_low_stock_alert) {
if (!empty($this->low_stock_alert)) {
$combination->low_stock_alert = $this->low_stock_alert;
} else {
$combination->low_stock_alert = 0;
}
}
$combination->save();
}
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') || $this->change_type == 'quantity') {
$return_combinations[$id_pa] = MassEditTools::setQuantity(
(int)$id_product,
$id_pa,
$this->quantity,
$this->action_quantity,
$id_shop,
$this->location
);
} else {
if (Warehouse::getProductLocation($id_product, $id_pa, $this->warehouse->id) === false) {
Warehouse::setProductLocation($id_product, $id_pa, $this->warehouse->id, '');
}
if ($this->action_warehouse) {
$this->stock_manager->addProduct(
(int)$id_product,
$id_pa,
$this->warehouse,
$this->quantity,
0,
Product::getPriceStatic(
(int)$id_product,
false,
$id_pa,
6,
null,
false,
false
)
);
} else {
$quantity_warehouse = $this->stock_manager->getProductRealQuantities(
(int)$id_product,
$id_pa,
$this->warehouse->id
);
$quantity = min($quantity_warehouse, $this->quantity);
$this->stock_manager->removeProduct(
(int)$id_product,
$id_pa,
$this->warehouse,
$quantity,
0
);
}
StockAvailable::synchronize((int)$id_product);
$return_combinations[$id_pa] = Product::getQuantity((int)$id_product, $id_pa);
}
}
}
return array(
'combinations' => $return_combinations,
);
}
public function applyChangeForProducts($products)
{
$return_products = array();
foreach ($products as $id_product) {
if (count(MassEditTools::getShopIds())) {
foreach (MassEditTools::getShopIds() as $id_shop) {
// if (!$this->check_access_field_quantity) {
// continue;
// }
if ($this->check_access_field_location || $this->check_access_field_low_stock_alert) {
$prod = new Product($id_product);
if ($this->check_access_field_location) {
if (!empty($this->low_stock_threshold)) {
$prod->low_stock_threshold = $this->low_stock_threshold;
} else {
$prod->low_stock_threshold = null;
}
}
if ($this->check_access_field_low_stock_alert) {
if (!empty($this->low_stock_alert)) {
$prod->low_stock_alert = $this->low_stock_alert;
} else {
$prod->low_stock_alert = 0;
}
}
$prod->save();
}
if (!Product::usesAdvancedStockManagement((int)$id_product)
&& $this->change_type == self::CHANGE_TYPE_QUANTITY && $this->checkAccessField('quantity')) {
$return_products[(int)$id_product] = MassEditTools::setQuantity(
(int)$id_product,
0,
$this->quantity,
$this->action_quantity,
$id_shop,
$this->location
);
}
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')
&& Product::usesAdvancedStockManagement((int)$id_product)
&& $this->change_type == self::CHANGE_TYPE_WAREHOUSE) {
if (Warehouse::getProductLocation($id_product, 0, $this->warehouse->id) === false) {
Warehouse::setProductLocation($id_product, 0, $this->warehouse->id, '');
}
if ($this->action_warehouse) {
$this->stock_manager->addProduct(
(int)$id_product,
0,
$this->warehouse,
$this->quantity,
0,
Product::getPriceStatic(
(int)$id_product,
false,
null,
6,
null,
false,
false
)
);
} else {
$quantity_warehouse = $this->stock_manager->getProductRealQuantities(
(int)$id_product,
0,
$this->warehouse->id
);
$quantity = min($quantity_warehouse, $this->quantity);
$this->stock_manager->removeProduct(
(int)$id_product,
0,
$this->warehouse,
$quantity,
0
);
}
StockAvailable::synchronize((int)$id_product);
$return_products[(int)$id_product] = Product::getQuantity((int)$id_product);
}
}
}
}
return array(
'products' => $return_products
);
}
public function applyChangeBoth($products, $combinations)
{
foreach ($products as $id_product) {
$data_for_update = array();
$data_for_update2 = array();
// if ($this->checkAccessField('available_now')) {
// $data_for_update['available_now'] = addslashes(pSQL($this->available_now));
// }
// if ($this->checkAccessField('available_later')) {
// $data_for_update['available_later'] = addslashes(pSQL($this->available_later));
// }
if ($this->checkAccessField('available_date')) {
if ($this->change_available_date) {
if (!Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE')) {
Db::getInstance()->update(
'product_attribute',
array('available_date' => $this->available_date),
' id_product = ' . (int)$id_product
);
}
Db::getInstance()->update(
'product_attribute_shop',
array('available_date' => $this->available_date),
' id_product = ' . (int)$id_product
. (Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop ' . $this->sql_shop : '')
);
} else {
HelperDbMEP::updateObjectFieldByClass(
'Product',
'available_date',
(int)$id_product,
$this->available_date
);
}
}
if ($this->checkAccessField('out_of_stock')) {
StockAvailable::setProductOutOfStock((int)$id_product, $this->out_of_stock);
}
if ($this->checkAccessField('available_now')) {
$data_for_update['available_now'] = addslashes(pSQL($this->available_now));
}
if ($this->checkAccessField('available_later')) {
$data_for_update2['available_later'] = addslashes(pSQL($this->available_later));
Db::getInstance()->update(
'product_lang',
$data_for_update2,
' id_product = ' . (int)$id_product
. ($this->language2 ? ' AND id_lang = ' . (int)$this->language2 : '')
. ' ' . (Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop ' . $this->sql_shop : '')
);
}
if (count($data_for_update)) {
Db::getInstance()->update(
'product_lang',
$data_for_update,
' id_product = ' . (int)$id_product
. ($this->language ? ' AND id_lang = ' . (int)$this->language : '')
. ' ' . (Shop::isFeatureActive() && $this->sql_shop ? ' AND id_shop ' . $this->sql_shop : '')
);
}
}
if ($this->checkAccessField('minimal_quantity')) {
if ($this->checkOptionForCombination()) {
$table = 'product_attribute_shop';
$field = '`id_product_attribute`';
$ids = $combinations;
} else {
$table = 'product_shop';
$field = '`id_product`';
$ids = $products;
}
foreach ($ids as $id) {
Db::getInstance()->update(
$table,
array(
'minimal_quantity' => MassEditTools::getMinimalQuantityForUpdate(
$id,
$this->minimal_quantity,
$table,
$this->action_quantity
),
),
$field . ' = ' . (int)$id
);
}
}
}
public function checkOptionForCombination()
{
$change_for = (int)Tools::getValue('change_for');
return $change_for == self::CHANGE_FOR_COMBINATION;
}
public function getTitle()
{
return $this->l('Quantity');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['advanced_stock_management'] = (int)Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
$variables['warehouses'] = Warehouse::getWarehouses();
$variables['pack_stock_type'] = Configuration::get('PS_PACK_STOCK_TYPE');
$variables['token_preferences'] = Tools::getAdminTokenLite('AdminPPreferences');
return $variables;
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ReferenceTabMEP extends BaseTabMEP
{
public $assignment;
public $reference;
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
$sql = 'UPDATE `' . _DB_PREFIX_ . 'product` '
. 'SET ' . implode(', ', $this->assignment)
. ' WHERE `id_product` IN (\'' . implode('\', \'', $products) . '\')';
if (!Db::getInstance()->execute($sql)) {
LoggerMEP::getInstance()->error($this->l('Error writing to database'));
return array();
}
return array(
'ids_product' => $products,
'reference' => $this->reference
);
}
public function applyChangeForCombinations($products)
{
$sql = 'UPDATE `' . _DB_PREFIX_ . 'product_attribute` '
. 'SET ' . implode(', ', $this->assignment)
. ' WHERE `id_product_attribute`
IN (\'' . implode('\', \'', $this->getCombinationsIdsFromRequest()) . '\')';
if (!Db::getInstance()->execute($sql)) {
LoggerMEP::getInstance()->error($this->l('Error writing to database'));
return array();
}
return array(
'ids_product' => array_keys($products),
'reference' => $this->reference
);
}
public function checkOptionForCombination()
{
$change_for_property = (int)Tools::getValue('change_for_property');
if ($change_for_property == self::CHANGE_FOR_COMBINATION) {
return true;
}
return false;
}
public function checkBeforeChange()
{
if ($this->checkAccessField('selected_reference')) {
$this->reference = Tools::getValue('reference');
$this->assignment[] = '`reference` = \'' . pSQL($this->reference) . '\'';
}
if ($this->checkAccessField('selected_ean13')) {
$this->assignment[] = '`ean13` = \'' . pSQL(Tools::getValue('ean13')) . '\'';
}
if ($this->checkAccessField('selected_upc')) {
$this->assignment[] = '`upc` = \'' . pSQL(Tools::getValue('upc')) . '\'';
}
if (!count($this->assignment)) {
LoggerMEP::getInstance()->error($this->l('Not selected field'));
return array();
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function getTitle()
{
return $this->l('Reference');
}
}

View File

@@ -0,0 +1,346 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class RuleCombinationTabMEP extends BaseTabMEP
{
public $exact_match;
public $delete_attribute;
public $add_attribute;
public $force_delete_attribute;
public $selected_attributes;
public $rc_apply_change_for;
public function __construct()
{
parent::__construct();
$this->exact_match = (int)Tools::getValue('exact_match');
$this->rc_apply_change_for = (int)Tools::getValue('rc_apply_change_for');
$this->delete_attribute = (int)Tools::getValue('delete_attribute');
$this->add_attribute = (int)Tools::getValue('add_attribute');
$this->force_delete_attribute = (int)Tools::getValue('force_delete_attribute');
$this->selected_attributes = (is_array(Tools::getValue('selected_attributes')) ?
array_map('intval', Tools::getValue('selected_attributes'))
: array());
}
public function checkOptionForCombination()
{
return $this->rc_apply_change_for;
}
public function applyChangeBoth($products, $combinations)
{
$change_combinations = array();
if ($this->rc_apply_change_for == 1) {
$change_combinations = $combinations;
}
if ($this->checkAccessField('selected_attributes')) {
$ids_product_attributes = array();
if (count($change_combinations)) {
$ids_product_attribute = $change_combinations;
}
foreach ($this->selected_attributes as $selected_attribute) {
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$result = Db::getInstance()->executeS(
'SELECT pac.`id_product_attribute`, p.`id_product`
FROM ' . _DB_PREFIX_ . 'product_attribute_combination pac
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas
ON pas.`id_product_attribute` = pac.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa
ON pac.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product p
ON p.`id_product` = pa.`id_product`
WHERE pac.`id_attribute` = ' . (int)$selected_attribute . ' AND pas.`id_shop`
IN(' . implode(',', array_map('intval', $this->ids_shop)) . ')
AND p.`id_product` IN(' . implode(',', array_map('intval', $products)) . ')'
. (count($ids_product_attributes) ?
' AND pac.`id_product_attribute` IN(' . implode(
',',
array_map('intval', $ids_product_attributes)
) . ') ' : '')
);
} else {
$result = Db::getInstance()->executeS(
'SELECT pac.`id_product_attribute`
FROM ' . _DB_PREFIX_ . 'product_attribute_combination pac
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas
ON pas.`id_product_attribute` = pac.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product p ON p.`id_product` = pas.`id_product`
WHERE pac.`id_attribute` = ' . (int)$selected_attribute . ' AND pas.`id_shop`
IN(' . implode(',', array_map('intval', $this->ids_shop)) . ')
AND p.`id_product` IN(' . implode(',', array_map('intval', $products)) . ')'
. (count($ids_product_attributes) ?
' AND pac.`id_product_attribute` IN(' . implode(
',',
array_map('intval', $ids_product_attributes)
) . ') ' : '')
);
}
if (is_array($result)) {
$ids_product_attributes = array();
foreach ($result as $item) {
$ids_product_attributes[] = (int)$item['id_product_attribute'];
}
$ids_product_attributes = array_unique($ids_product_attributes);
}
}
if (count($ids_product_attributes)) {
foreach ($ids_product_attributes as $ids_product_attribute) {
$combination = new Combination($ids_product_attribute);
$attributes = $combination->getAttributesName($this->context->language->id);
if (count($this->selected_attributes) == count($attributes) || !$this->exact_match) {
$combination->delete();
}
}
}
}
if ($this->checkAccessField('delete_attribute')) {
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$result = Db::getInstance()->executeS(
'SELECT pac.`id_product_attribute`, p.`id_product`
FROM ' . _DB_PREFIX_ . 'product_attribute_combination pac
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas
ON pas.`id_product_attribute` = pac.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa
ON pac.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product p ON p.`id_product` = pa.`id_product`
WHERE pac.`id_attribute` = ' . (int)$this->delete_attribute . '
AND pas.`id_shop` IN(' . implode(',', array_map('intval', $this->ids_shop)) . ')
AND p.`id_product` IN(' . implode(',', array_map('intval', $products)) . ')'
. (count($change_combinations) ? ' AND pas.`id_product_attribute` IN(' . implode(
',',
array_map('intval', $change_combinations)
) . ')' : '')
);
} else {
$result = Db::getInstance()->executeS(
'SELECT pac.`id_product_attribute`, p.`id_product`
FROM ' . _DB_PREFIX_ . 'product_attribute_combination pac
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas
ON pas.`id_product_attribute` = pac.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product p ON p.`id_product` = pas.`id_product`
WHERE pac.`id_attribute` = ' . (int)$this->delete_attribute . '
AND pas.`id_shop` IN(' . implode(',', array_map('intval', $this->ids_shop)) . ')
AND p.`id_product` IN(' . implode(',', array_map('intval', $products)) . ')'
. (count($change_combinations) ? ' AND pas.`id_product_attribute` IN(' . implode(
',',
array_map('intval', $change_combinations)
) . ')' : '')
);
}
$tmp_products = $products;
$product_attributes = array();
if (is_array($result)) {
foreach ($result as $item) {
$key = array_search($item['id_product'], $tmp_products);
if ($key !== false) {
unset($tmp_products[$key]);
}
$product_attributes[(int)$item['id_product_attribute']] = $item;
}
}
if (count($product_attributes)) {
foreach ($product_attributes as $product_attribute) {
if ($this->force_delete_attribute
|| !($choice_pa = MassEditTools::checkProductOnChoiceAttributes(
$product_attribute['id_product'],
$product_attribute['id_product_attribute'],
$this->delete_attribute
))) {
Db::getInstance()->delete(
'product_attribute_combination',
' `id_attribute` = ' . (int)$this->delete_attribute
. ' AND `id_product_attribute` = ' . (int)$product_attribute['id_product_attribute']
);
} else {
LoggerMEP::getInstance()->error(
sprintf(
$this->l('For product with ids %s found choice combination with id %s'),
$product_attribute['id_product'],
$choice_pa
)
);
}
}
}
if (count($tmp_products)) {
LoggerMEP::getInstance()->error(
sprintf(
$this->l('No attribute applied to products with id %s'),
implode(', ', $tmp_products)
)
);
}
}
if ($this->checkAccessField('add_attribute')) {
$change_combinations = $combinations;
if (empty($change_combinations)) {
LoggerMEP::getInstance()->error(
sprintf(
$this->l('No attribute applied to products with id %s'),
implode(', ', $tmp_products)
)
);
return false;
}
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$result = Db::getInstance()->executeS(
'SELECT pac.`id_product_attribute`, p.`id_product`
FROM ' . _DB_PREFIX_ . 'product_attribute_combination pac
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas
ON pas.`id_product_attribute` = pac.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute pa
ON pac.`id_product_attribute` = pa.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product p
ON p.`id_product` = pa.`id_product`
WHERE pac.`id_attribute`
AND pas.`id_shop` IN(' . implode(',', array_map('intval', $this->ids_shop)) . ')
AND p.`id_product` IN(' . implode(',', array_map('intval', $products)) . ')'
. (count($change_combinations) ? ' AND pas.`id_product_attribute` IN(' . implode(
',',
array_map('intval', $change_combinations)
) . ')' : '')
);
} else {
$result = Db::getInstance()->executeS(
'SELECT pac.`id_product_attribute`, p.`id_product`
FROM ' . _DB_PREFIX_ . 'product_attribute_combination pac
LEFT JOIN ' . _DB_PREFIX_ . 'product_attribute_shop pas
ON pas.`id_product_attribute` = pac.`id_product_attribute`
LEFT JOIN ' . _DB_PREFIX_ . 'product p
ON p.`id_product` = pas.`id_product`
WHERE pac.`id_attribute`
AND pas.`id_shop` IN(' . implode(',', array_map('intval', $this->ids_shop)) . ')
AND p.`id_product` IN(' . implode(',', array_map('intval', $products)) . ')'
. (count($change_combinations) ? ' AND pas.`id_product_attribute` IN(' . implode(
',',
array_map('intval', $change_combinations)
) . ')' : '')
);
}
$tmp_products = $products;
$product_attributes = array();
if (is_array($result)) {
foreach ($result as $item) {
$key = array_search($item['id_product'], $tmp_products);
if ($key !== false) {
unset($tmp_products[$key]);
}
$product_attributes[(int)$item['id_product_attribute']] = $item;
}
}
if (count($product_attributes)) {
foreach ($product_attributes as $product_attribute) {
if (!MassEditTools::checkProductOnChoiceAttributesReverse(
$product_attribute['id_product'],
$product_attribute['id_product_attribute'],
$this->add_attribute
)) {
Db::getInstance()->insert(
'product_attribute_combination',
array(
'id_attribute' => (int)$this->add_attribute,
'id_product_attribute' => (int)$product_attribute['id_product_attribute'],
)
);
} else {
LoggerMEP::getInstance()->error(
sprintf(
$this->l('Product with id %s combination id %s has this attribute'),
$product_attribute['id_product'],
$product_attribute['id_product_attribute']
)
);
}
}
}
if (count($tmp_products)) {
LoggerMEP::getInstance()->error(
sprintf(
$this->l('No attribute applied to products with id %s'),
implode(', ', $tmp_products)
)
);
}
}
return array();
}
public function applyChangeForCombinations($products)
{
}
public function applyChangeForProducts($products)
{
}
public function checkBeforeChange()
{
if ($this->checkAccessField('selected_attributes') && !count($this->selected_attributes)) {
LoggerMEP::getInstance()->error($this->l('No selected attributes'));
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function getTitle()
{
return $this->l('Combinations');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$attribute_groups = AttributeGroup::getAttributesGroups($this->context->language->id);
if (is_array($attribute_groups) && count($attribute_groups)) {
foreach ($attribute_groups as &$attribute_group) {
$attribute_group['attributes'] = AttributeGroup::getAttributes(
$this->context->language->id,
(int)$attribute_group['id_attribute_group']
);
}
}
$variables['attribute_groups'] = $attribute_groups;
return $variables;
}
}

View File

@@ -0,0 +1,175 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class SupplierTabMEP extends BaseTabMEP
{
public $supplier;
public $id_supplier_default;
public $object_supplier;
public function __construct()
{
parent::__construct();
$this->supplier = Tools::getValue('supplier');
$this->id_supplier_default = (int)Tools::getValue('id_supplier_default');
$this->object_supplier = new Supplier(
$this->id_supplier_default,
$this->context->language->id
);
}
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
if ($this->checkAccessField('supplier')) {
foreach ($products as $product) {
$this->addToReIndexSearch((int)$product);
$product = new Product((int)$product);
if (Validate::isLoadedObject($product)) {
$product->deleteFromSupplier();
foreach ($this->supplier as $sup) {
$product->addSupplierReference($sup, 0);
}
$this->updateDateUpdProduct($product->id);
}
}
}
$return_products = array();
if ($this->checkAccessField('id_supplier_default')) {
Db::getInstance()->update(
'product',
array(
'id_supplier' => (int)$this->object_supplier->id,
),
' id_product IN('.pSQL(implode(',', $products)).')'
);
foreach ($products as $product) {
$return_products[(int)$product] = $this->object_supplier->name;
}
}
if ($this->checkAccessField('supplier_reference')) {
$associated_suppliers = Tools::getValue('suppliers_sr');
$combinations = Tools::getValue('combinations');
if (!is_array($associated_suppliers) || !count($associated_suppliers)) {
LoggerMEP::getInstance()->error($this->l('No suppliers'));
}
$reference = pSQL(Tools::getValue('supplier_reference', ''));
$id_currency = (int)Tools::getValue('product_price_currency');
$price = (float)str_replace(
array(' ', ','),
array('', '.'),
Tools::getValue('product_price', 0)
);
if (!empty($associated_suppliers[0])) {
foreach ($products as $product) {
$product = new Product((int)$product);
foreach ($associated_suppliers as $sup) {
$product->addSupplierReference($sup, 0, $reference, $price, $id_currency);
}
if ($combinations !== false) {
$comb = preg_grep('/^('.$product->id.'_)+/', $combinations);
if (is_array($comb) && !empty($combinations)) {
foreach ($comb as $val_comb) {
$id_product_attribute = Tools::substr($val_comb, Tools::strpos($val_comb, '_') + 1);
foreach ($associated_suppliers as $supplier) {
$product->addSupplierReference(
$supplier,
(int)$id_product_attribute,
$reference,
$price,
$id_currency
);
}
}
}
}
}
}
}
return array(
'products' => $return_products,
);
}
public function applyChangeForCombinations($products)
{
}
public function checkBeforeChange()
{
if ($this->checkAccessField('supplier')) {
if (!is_array($this->supplier) || !count($this->supplier)) {
LoggerMEP::getInstance()->error($this->l('No suppliers'));
}
}
if ($this->checkAccessField('id_supplier_default')) {
if (!$this->id_supplier_default) {
LoggerMEP::getInstance()->error($this->l('Supplier default no selected'));
}
if (!Validate::isLoadedObject($this->object_supplier) && $this->id_supplier_default) {
LoggerMEP::getInstance()->error($this->l('Supplier not exists'));
}
}
if (LoggerMEP::getInstance()->hasError()) {
return false;
}
return true;
}
public function getTitle()
{
return $this->l('Supplier');
}
public function assignVariables()
{
$variables = parent::assignVariables();
$variables['suppliers'] = Supplier::getSuppliers(
false,
0,
false
);
$variables['currencies'] = Currency::getCurrencies(false, true);
$variables['id_default_currency'] = Configuration::get('PS_CURRENCY_DEFAULT');
return $variables;
}
}

View File

@@ -0,0 +1,155 @@
<?php
/**
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author SeoSA <885588@bk.ru>
* @copyright 2012-2018 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class VirtualTabMEP extends BaseTabMEP
{
public $object_virtual;
public function __construct()
{
parent::__construct();
if (Tools::getValue('action_virtual') == 'false') {
$this->object_virtual = new ProductDownload();
$this->object_virtualdisplay_filename = Tools::getValue('name_file');
$this->object_virtual->date_expiration = Tools::getValue('expiration_date');
$this->object_virtual->nb_days_accessible = Tools::getValue('amount_of_days');
$this->object_virtual->nb_downloadable = Tools::getValue('number_downloads');
}
}
public function applyChangeBoth($products, $combinations)
{
}
public function applyChangeForProducts($products)
{
$products2 = explode(",", $products);
$data = array();
$this->object_virtual = new ProductDownload();
$data['name'] = Tools::getValue('name_file');
$data['expiration_date'] = Tools::getValue('expiration_date') ? Tools::getValue('expiration_date') : "";
$data['nb_days'] = Tools::getValue('amount_of_days');
$data['nb_downloadable'] = Tools::getValue('number_downloads');
$data['is_virtual_file'] = 1;
$data['date_add'] = date('Y-m-d H:i:s');
$data['file'] = !empty($_FILES['file']['tmp_name']) ? $_FILES['file']['tmp_name'] : "";
$data['action_for_virtual'] = Tools::getValue('action_for_virtual');
$action_virtual = Tools::getValue('action_virtual');
foreach ($products2 as $id_product) {
$test_Product = new Product($id_product);
if ($test_Product->getType() == 2 && $action_virtual == 'false') {
$yes_record = $this->object_virtual->getIdFromIdProduct((int)$id_product);
$fileName = ProductDownload::getNewFilename();
$this->object_virtual->id_product = (int)$id_product;
$this->object_virtual->display_filename = $data['name'];
$this->object_virtual->filename = $fileName ? $fileName : $this->object_virtual->filename;
$this->object_virtual->date_expiration = $data['expiration_date'] ? $data['expiration_date'] : '';
$this->object_virtual->nb_days_accessible = (int)$data['nb_days'];
$this->object_virtual->nb_downloadable = (int)$data['nb_downloadable'];
$this->object_virtual->date_add = $data['date_add'];
$this->object_virtual->active = 1;
$this->object_virtual->is_shareable = 0;
$file_old = $this->object_virtual->getFilenameFromIdProduct($id_product);
if ($data['expiration_date'] == "" || $data['expiration_date'] == "0000-00-00") {
$message = Context::getContext()->getTranslator()->trans('No date expiration');
LoggerMEP::getInstance()->error($message);
die(Tools::jsonEncode(array(
'hasError' => true,
'log' => LoggerMEP::getInstance()->getMessages()
)));
}
if ($this->object_virtual->display_filename == "") {
$message = Context::getContext()->getTranslator()->trans('This value should not be blank.');
LoggerMEP::getInstance()->error($message);
die(Tools::jsonEncode(array(
'hasError' => true,
'log' => LoggerMEP::getInstance()->getMessages()
)));
}
if (!is_numeric($data['nb_days']) || !is_numeric($data['nb_downloadable'])) {
$message = Context::getContext()->getTranslator()->trans('This value is not valid');
LoggerMEP::getInstance()->error($message);
die(Tools::jsonEncode(array(
'hasError' => true,
'log' => LoggerMEP::getInstance()->getMessages()
)));
}
$yes_file = 0;
foreach (scandir(_PS_DOWNLOAD_DIR_) as $name_file) {
if ($name_file == $file_old) {
$yes_file = 1;
break;
}
}
if ($file_old != false && $yes_file == 1) {
unlink(_PS_DOWNLOAD_DIR_ . $file_old);
}
Db::getInstance()->delete('product_download', 'id_product_download = ' . (int)$yes_record);
$this->object_virtual->add((int)$id_product);
if ($data['file'] != "") {
if (!copy($data['file'], _PS_DOWNLOAD_DIR_ . $fileName)) {
$message = 'No file save!';
LoggerMEP::getInstance()->error($message);
die(Tools::jsonEncode(array(
'hasError' => true,
'log' => LoggerMEP::getInstance()->getMessages()
)));
}
}
}
if ($action_virtual == 'true') {
if ($data['action_for_virtual'] == 2) {
$test_Product->is_virtual = 1;
if ($test_Product->getDefaultAttribute($id_product) == 0) {
$test_Product->save();
}
} elseif ($data['action_for_virtual'] == 0) {
$test_Product->is_virtual = 0;
if ($test_Product->getDefaultAttribute($id_product) == 0) {
$test_Product->save();
}
}
}
}
die(Tools::jsonEncode(array(
'hasError' => false
)));
}
public function applyChangeForCombinations($products)
{
}
public function getTitle()
{
return $this->l('Virtual');
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,121 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class AngularAppMEP
{
protected $path_angular_app = null;
protected $context = null;
protected $autoload = array(
'modules' => false,
'app' => false,
'filters' => false,
'directives' => false,
'controllers' => false,
'services' => false
);
/**
* @var AngularAppMEP
*/
protected static $instance = array();
public static function getInstance($path)
{
if (!array_key_exists($path, self::$instance)) {
self::$instance[$path] = new self($path);
}
return self::$instance[$path];
}
public function __construct($path)
{
$this->context = Context::getContext();
$this->path_angular_app = $path;
}
public function autoloadApp()
{
if (is_array($this->autoload) && count($this->autoload)) {
foreach (array_keys($this->autoload) as $type) {
$this->autoloadComponents($type);
}
}
}
protected function checkAutoloadModules()
{
return $this->checkAutoloadComponents('modules');
}
protected function checkAutoloadComponents($component)
{
return array_key_exists($component, $this->autoload) ? $this->autoload[$component] : false;
}
public function checkAutoloadDirectives()
{
return $this->checkAutoloadComponents('directives');
}
public function checkAutoloadFilters()
{
return $this->checkAutoloadComponents('filters');
}
public function checkAutoloadControllers()
{
return $this->checkAutoloadComponents('controllers');
}
public function checkAutoloadServices()
{
return $this->checkAutoloadComponents('services');
}
protected function autoloadComponents($type)
{
if (!array_key_exists($type, $this->autoload) || $this->autoload[$type]) {
return false;
}
if ($type == 'app') {
$this->context->controller->addJS($this->path_angular_app . $type . '.js');
} else {
$full_path = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . ToolsModuleMEP::strReplaceFirst(
__PS_BASE_URI__,
'',
$this->path_angular_app
);
$files = glob($full_path . $type . '/**.js');
if (is_array($files) && count($files)) {
foreach ($files as $file) {
$this->context->controller->addJS($this->path_angular_app . $type . '/' . basename($file));
}
}
}
$this->autoload[$type] = true;
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class self
*/
class AutoloaderMEP
{
private $folder = false;
private $class_map = null;
/**
* self constructor.
* @param bool $folder
*/
private function __construct($folder)
{
$this->folder = $folder;
}
/**
* @param $folder
* @return bool
*/
public static function create($folder)
{
$instance = new self($folder);
return spl_autoload_register(array($instance, 'autoload'));
}
/**
* @void
*/
protected function buildClassMap()
{
$this->class_map = array();
$path = realpath($this->folder);
$files = self::globRecursive($path . '/*.php');
foreach ($files as $file) {
$class = str_replace('.php', '', basename($file));
$this->class_map[$class] = $file;
}
}
/**
* @param string $classname
* @void
*/
public function autoload($classname)
{
if (class_exists($classname)) {
return;
}
if (null === $this->class_map) {
$this->buildClassMap();
}
if (array_key_exists($classname, $this->class_map)) {
/** @noinspection PhpIncludeInspection */
require_once($this->class_map[$classname]);
}
}
/**
* @param string $pattern
* @param int $flags
* @return array
*/
private static function globRecursive($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
$dirs = glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT);
if (is_array($dirs) && count($dirs)) {
foreach ($dirs as $dir) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$files = array_merge($files, self::globRecursive($dir . '/' . basename($pattern), $flags));
}
}
return $files;
}
}

View File

@@ -0,0 +1,293 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class CategoryToolsMEP
{
public static $category_field_map = array(
'id_category',
'id_parent',
'name',
'description',
'link_rewrite',
'meta_title',
'meta_keywords',
'meta_description',
'id_lang',
'position',
'active'
);
protected static function generateSelectFields()
{
$category_definition = self::getCategoryDefinition();
$select = array();
foreach (self::$category_field_map as $field) {
if (array_key_exists($field, $category_definition)) {
if ($field == 'position') {
$select[] = 'cs.`' . $field . '`';
} elseif (array_key_exists('lang', $category_definition[$field])
&& $category_definition[$field]['lang']) {
$select[] = 'cl.`' . $field . '`';
} else {
$select[] = 'c.`' . $field . '`';
}
}
}
return $select;
}
protected static function fillLangArrayElement(&$element, $item)
{
$category_definition = self::getCategoryDefinition();
foreach (self::$category_field_map as $field) {
if (array_key_exists($field, $category_definition) && array_key_exists($field, $item)) {
if (array_key_exists('lang', $category_definition[$field]) && $category_definition[$field]['lang']) {
if (!array_key_exists($field, $element)) {
$element[$field] = array();
}
$element[$field][$item['id_lang']] = $item[$field];
} else {
if (!array_key_exists($field, $element)) {
$element[$field] = $item[$field];
}
}
}
}
}
protected static function rebuildIndexCategories(&$categories)
{
foreach ($categories as &$category) {
$tmp = array();
if (count($category)) {
foreach ($category as $c) {
$tmp[] = $c;
}
}
$category = $tmp;
}
}
public static function getCategories()
{
$query = new DbQuery();
$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ?
(int)Context::getContext()->shop->id : 'c.id_shop_default';
$query->select(implode(', ', self::generateSelectFields()));
$query->from('category', 'c');
$query->leftJoin('category_lang', 'cl', 'c.`id_category` = cl.`id_category`');
$query->leftJoin(
'category_shop',
'cs',
'c.`id_category` = cs.`id_category` AND cs.`id_shop` = c.`id_shop_default`'
);
$query->where('c.`id_shop_default` = ' . pSQL($id_shop));
$query->orderBy('cs.`position` ASC');
$result = Db::getInstance()->executeS($query->build());
$ids_category = array();
if (is_array($result) && count($result)) {
foreach ($result as $item) {
$ids_category[] = (int)$item['id_category'];
}
}
$categories_groups = array();
if (count($ids_category)) {
$result2 = Db::getInstance()->executeS(
'SELECT * FROM ' . _DB_PREFIX_ . 'category_group
WHERE id_category IN(' . implode(',', $ids_category) . ')'
);
if (is_array($result2) && count($result2)) {
foreach ($result2 as $item2) {
if (!array_key_exists($item2['id_category'], $categories_groups)) {
$categories_groups[$item2['id_category']] = array();
}
$categories_groups[$item2['id_category']][] = $item2['id_group'];
}
}
}
$categories = array();
if (is_array($result) && count($result)) {
foreach ($result as $item) {
if (file_exists(_PS_CAT_IMG_DIR_ . $item['id_category'] . '.jpg')) {
$item['image'] = _PS_IMG_ . 'c/' . $item['id_category'] . '.jpg';
} else {
$item['image'] = null;
}
if (!array_key_exists($item['id_category'], $categories)) {
$categories[$item['id_category']] = array();
}
if (!array_key_exists($item['id_parent'], $categories)) {
$categories[$item['id_parent']] = array();
}
$index = count($categories[$item['id_parent']]);
if (count($categories[$item['id_parent']])) {
foreach ($categories[$item['id_parent']] as $index_category => $category) {
if ($category['id_category'] == $item['id_category']) {
$index = $index_category;
}
}
}
if (!array_key_exists($index, $categories[$item['id_parent']])) {
$categories[$item['id_parent']][$index] = array();
}
self::fillLangArrayElement($categories[$item['id_parent']][$index], $item);
$categories[$item['id_parent']][$index]['image'] = $item['image'];
if (array_key_exists($item['id_category'], $categories_groups)) {
$categories[$item['id_parent']][$index]['groups'] = $categories_groups[$item['id_category']];
} else {
$categories[$item['id_parent']][$index]['groups'] = array();
}
}
}
//self::rebuildIndexCategories($categories);
return $categories;
}
public static function getRootCategoryId()
{
$id_root_category = Db::getInstance()->getValue(
'SELECT c.`id_category` FROM ' . _DB_PREFIX_ . 'category c
WHERE c.`is_root_category` = 1'
);
return $id_root_category;
}
protected static $category_definition = null;
protected static function getCategoryDefinition()
{
if (!is_null(self::$category_definition)) {
return self::$category_definition;
}
self::$category_definition = Category::$definition['fields'];
//Fix definition
self::$category_definition['id_category'] = array();
self::$category_definition['id_lang'] = array('lang' => true);
return self::$category_definition;
}
public static function cleanPosition($id_parent)
{
$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ?
(int)Context::getContext()->shop->id : 'c.id_shop_default';
$categories = Db::getInstance()->executeS(
'SELECT cs.`id_category`, cs.`id_shop` FROM ' . _DB_PREFIX_ . 'category c
LEFT JOIN ' . _DB_PREFIX_ . 'category_shop cs ON cs.`id_category` = c.`id_category`
AND cs.`id_shop` = ' . $id_shop . '
WHERE c.`id_parent` = ' . (int)$id_parent . '
ORDER BY cs.`position` ASC'
);
if (is_array($categories) && count($categories)) {
foreach ($categories as $key => $category) {
Db::getInstance()->update(
'category_shop',
array(
'position' => $key
),
'id_category = ' . (int)$category['id_category'] . ' AND id_shop = ' . (int)$category['id_shop']
);
}
}
}
public static function updatePosition($id_category, $position, $id_parent, $way)
{
$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ?
(int)Context::getContext()->shop->id : 'c.id_shop_default';
$category = Db::getInstance()->getRow(
'SELECT cs.`id_category`, cs.`position` FROM ' . _DB_PREFIX_ . 'category c
LEFT JOIN ' . _DB_PREFIX_ . 'category_shop cs ON cs.`id_category` = c.`id_category`
AND cs.`id_shop` = ' . $id_shop . '
WHERE c.`id_category` = ' . (int)$id_category
);
if (!is_array($category) || !count($category)) {
return false;
}
$old_position = (int)$category['position'];
Db::getInstance()->execute(
'UPDATE ' . _DB_PREFIX_ . 'category c
LEFT JOIN ' . _DB_PREFIX_ . 'category_shop cs ON c.`id_category` = cs.`id_category`
AND cs.`id_shop` = ' . $id_shop . '
SET c.`position` = c.`position` ' . ($way ? '- 1' : '+ 1') . ',
cs.`position` = cs.`position` ' . ($way ? '- 1' : '+ 1') . '
WHERE cs.`position`' . ($way ? '> ' . (int)$old_position . ' AND cs.`position` <= ' . (int)$position
: '< ' . (int)$old_position . ' AND cs.`position` >= ' . (int)$position) . '
AND c.`id_parent` = ' . (int)$id_parent
);
Db::getInstance()->execute(
'UPDATE ' . _DB_PREFIX_ . 'category c
LEFT JOIN ' . _DB_PREFIX_ . 'category_shop cs ON cs.`id_category` = c.`id_category`
AND cs.`id_shop` = ' . $id_shop . '
SET c.`position` = ' . (int)$position . ' , cs.`position` = ' . (int)$position . '
WHERE c.`id_category` = ' . (int)$id_category
);
}
public static function moveCategory($id_category, $id_parent, $position)
{
$category = new Category($id_category);
$old_id_parent = (int)$category->id_parent;
$category->id_parent = $id_parent;
$category->save();
CategoryToolsMEP::cleanPosition($old_id_parent);
CategoryToolsMEP::cleanPosition($id_parent);
$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ?
(int)Context::getContext()->shop->id : 'c.id_shop_default';
$category = Db::getInstance()->getRow(
'SELECT cs.`id_category`, cs.`position`
FROM ' . _DB_PREFIX_ . 'category c
LEFT JOIN ' . _DB_PREFIX_ . 'category_shop cs ON cs.`id_category` = c.`id_category`
AND cs.`id_shop` = ' . $id_shop . '
WHERE c.`id_category` = ' . (int)$id_category
);
if (!is_array($category) || !count($category)) {
return false;
}
$old_position = (int)$category['position'];
$way = ($position > $old_position ? 1 : 0);
return $way;
}
}

View File

@@ -0,0 +1,118 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2021 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ConfMEP
*/
class ConfMEP
{
protected static $module_prefix = 'MEP';
protected static $prefix_length = null;
protected static $conf_length = null;
protected static $prefix = null;
public static function getPrefix()
{
if (!is_null(self::$prefix)) {
return self::$prefix;
}
$prefix = 'PS_' . self::$module_prefix . '_';
if (is_null(self::$prefix_length)) {
self::$prefix_length = Tools::strlen($prefix);
}
self::$prefix = $prefix;
return $prefix;
}
public static function formatConfName($name)
{
if (is_null(self::$conf_length)) {
self::$conf_length = (int)Configuration::$definition['fields']['name']['size'];
}
$prefix = self::getPrefix();
$name = Tools::strtoupper($name);
$name = md5($name);
$name_length = Tools::strlen($name);
$difference = self::$conf_length - $name_length - self::$prefix_length;
if ($difference < 0) {
$name = Tools::substr($name, 0, $name_length + $difference);
}
return $prefix . $name;
}
const TYPE_STRING = 1;
const TYPE_ARRAY = 2;
public static function getConf($name, $type = self::TYPE_STRING)
{
$value = Configuration::get(self::formatConfName($name));
switch ($type) {
case self::TYPE_ARRAY:
$value = Tools::jsonDecode($value, true);
break;
}
return $value;
}
public static function setConf($name, $value, $type = self::TYPE_STRING)
{
switch ($type) {
case self::TYPE_ARRAY:
$value = Tools::jsonEncode($value);
break;
}
return Configuration::updateValue(self::formatConfName($name), $value);
}
public static function deleteConf($name)
{
$name = Tools::strtoupper($name);
return Configuration::deleteByName(self::formatConfName($name));
}
public static function installConf($config)
{
foreach ($config as $name => $value) {
self::setConf($name, $value);
}
}
public static function uninstallConf($config)
{
foreach (array_keys($config) as $name) {
self::deleteConf($name);
}
}
public static function setPrefix($name)
{
self::$prefix = $name;
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2021 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class DocumentationMEP
{
public static function assignDocumentation()
{
SmartyMEP::registerSmartyFunctions();
$context = Context::getContext();
HelperModuleMEP::addCSS('documentation.css');
$documentation_folder = _PS_MODULE_DIR_ . ToolsModuleMEP::getModNameForPath(__FILE__)
. '/views/templates/admin/documentation';
$documentation_pages = ToolsModuleMEP::globRecursive($documentation_folder . '/**.tpl');
natsort($documentation_pages);
$tree = array();
if (is_array($documentation_pages) && count($documentation_pages)) {
foreach ($documentation_pages as &$documentation_page) {
$name = str_replace(array($documentation_folder . '/', '.tpl'), '', $documentation_page);
$path = explode('/', $name);
$tmp_tree = &$tree;
foreach ($path as $key => $item) {
$part = $item;
if ($key == (count($path) - 1)) {
$tmp_tree[$part] = $name;
} else {
if (!isset($tmp_tree[$part])) {
$tmp_tree[$part] = array();
}
}
$tmp_tree = &$tmp_tree[$part];
}
}
}
$context->smarty->assign('tree', $tree);
$context->smarty->assign('documentation_pages', $documentation_pages);
$context->smarty->assign('documentation_folder', $documentation_folder);
}
}

View File

@@ -0,0 +1,137 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ErrorHandlerMEP
{
public static function setErrorHandler()
{
if (!_PS_MODE_DEV_) {
ini_set('display_errors', 'off');
}
restore_error_handler();
set_error_handler(array(__CLASS__, 'errorHandler'));
register_shutdown_function(array(__CLASS__, 'shutdown'));
}
public static function errorHandler($errno, $errstr, $errfile, $errline)
{
if (error_reporting() === 0) {
return false;
}
if (!defined('E_RECOVERABLE_ERROR')) {
define('E_RECOVERABLE_ERROR', 4096);
}
switch ($errno) {
case E_RECOVERABLE_ERROR:
case E_USER_ERROR:
case E_ERROR:
throw new Exception('Fatal error: ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
//no break
case E_USER_WARNING:
case E_WARNING:
// throw new Exception('Error: ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
//no break
case E_USER_NOTICE:
case E_NOTICE:
if (_PS_MODE_DEV_) {
throw new Exception('Notice: ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
}
return true;
default:
throw new Exception('Unknown error: ' . $errstr . ' in ' . $errfile . ' on line ' . $errline);
}
}
public static function shutdown()
{
$l = TransModMEP::getInstance();
if (function_exists('error_get_last')) {
$error = error_get_last();
if ($error && $error['type'] === E_ERROR) {
$message = $error['message'];
$memory_regex = '/^Allowed memory size of (\d+) bytes exhausted \(tried to allocate (\d+) bytes\)$/u';
$time_regex = '/^Maximum execution time of (\d+) second exceeded/u';
if (preg_match($memory_regex, $message, $matches)) {
$message = $l->l('Allowed memory size of', __FILE__) . ' ';
$message .= self::convertMemory($matches[1]) . ' ';
$message .= $l->l('exhausted', __FILE__) . ' (';
$message .= $l->l('tried to allocate', __FILE__) . ' ';
$message .= self::convertMemory($matches[2]) . ' ';
$message .= ')';
LoggerMEP::getInstance()->error($message);
LoggerMEP::getInstance()->error(
$l->l('Your web-server is too slow, not enough RAM.', __FILE__)
);
LoggerMEP::getInstance()->error(
$l->l('Try to reduce some of expert\'s settings.', __FILE__)
);
} elseif (preg_match($time_regex, $message, $matches)) {
$message = $l->l('Maximum execution time of', __FILE__) . ' ';
$message .= (int)$matches[1] . ' ';
$message .= $l->l('second exceeded', __FILE__);
LoggerMEP::getInstance()->error($message);
LoggerMEP::getInstance()->error(
$l->l('Your web-server is too slow, increase PHP execution time limit.', __FILE__)
);
LoggerMEP::getInstance()->error(
$l->l('Try to reduce some of expert\'s settings.', __FILE__)
);
} else {
LoggerMEP::getInstance()->error($message);
}
die(Tools::jsonEncode(array(
'hasError' => LoggerMEP::getInstance()->hasError(),
'log' => LoggerMEP::getInstance()->getMessages()
)));
}
}
exit;
}
public static $memory_units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
/**
* @param $size
* @return bool
*/
public static function convertMemory($size)
{
if (!$size) {
return '0B';
}
$i = floor(log($size, 1024));
$size = round($size / pow(1024, $i), 2);
return $size . ' ' . self::$memory_units[(int)$i];
}
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ErrorLoggerMEP
{
protected $filename = 'error.log';
protected $handler;
protected function __construct()
{
$this->handler = $this->createHandler();
}
protected static $self = null;
public static function getInstance()
{
if (is_null(self::$self)) {
self::$self = new self();
}
return self::$self;
}
protected function getLogFilePath()
{
return _PS_MODULE_DIR_ . ToolsModuleMEP::getModNameForPath(__FILE__) . '/' . $this->filename;
}
protected function createHandler()
{
$handler = fopen($this->getLogFilePath(), 'a');
return $handler;
}
protected function getHandler()
{
return $this->handler;
}
public function add($string)
{
if (is_array($string)) {
$string = var_export($string, true);
}
fwrite($this->getHandler(), $this->getDate() . $string . PHP_EOL);
}
protected function getDate()
{
return date('H:i:s d-m-Y: ');
}
public function clear()
{
unlink($this->getLogFilePath());
$this->handler = $this->createHandler();
}
}

View File

@@ -0,0 +1,305 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class FixtureMEP
{
/**
* @var string
*/
protected $name;
protected function __construct($module_name)
{
$this->name = $module_name;
}
/**
* @var LoggerMEP
*/
protected static $instance = null;
public static function getInstance($module_name)
{
if (is_null(self::$instance)) {
self::$instance = new self($module_name);
}
return self::$instance;
}
/**
* @var array $primary_entities
*/
protected $primary_entities = array();
/**
* @var array $entities
*/
protected $entities = array();
/**
* @param string $class_name
* @throws PrestaShopException
*/
public function importEntity($class_name)
{
$relations = array();
$definition = ObjectModel::getDefinition($class_name);
if (array_key_exists('fixture', $definition)) {
$fixture = $definition['fixture'];
if (array_key_exists('relations', $fixture)) {
$relations = $fixture['relations'];
foreach ($relations as $relation) {
if (is_array($relation)) {
foreach ($relation['variations'] as $variation) {
if (strpos($variation, '::') === false && !in_array($variation, $this->entities)) {
if ($definition['table'] != $relation) {
$this->importEntity(ToolsModuleMEP::toCamelCase($variation, true));
}
}
}
} else {
if (strpos($relation, '::') === false && !in_array($relation, $this->entities)) {
if ($definition['table'] != $relation) {
$this->importEntity(ToolsModuleMEP::toCamelCase($relation, true));
}
}
}
}
}
}
$data = array();
$fixture = _PS_MODULE_DIR_ . $this->name . '/fixtures/data/' . $definition['table'] . '.json';
if (file_exists($fixture)) {
$data = Tools::jsonDecode(Tools::file_get_contents($fixture), true);
}
$lang_fixtures = array();
$languages = ToolsModuleMEP::getLanguages(false);
$fixture_lang_path = _PS_MODULE_DIR_ . $this->name . '/fixtures/langs/';
foreach ($languages as $l) {
$lang_fixtures[$l['iso_code']] = array();
$fixture_lang = $fixture_lang_path . $l['iso_code'] . '/data/' . $definition['table'] . '.json';
if (file_exists($fixture_lang)) {
$lang_fixtures[$l['iso_code']] = Tools::jsonDecode(Tools::file_get_contents($fixture_lang), true);
}
}
$this->prepareArray($data, $relations, $definition);
$current_auto_increment = $this->getCurrentAutoIncrementTable($definition['table']);
$old_data = $data;
foreach ($data as &$row) {
$id = $row['id'];
unset($row['id']);
$this->primary_entities[$id] = $current_auto_increment;
$current_auto_increment++;
}
if ($this->checkFixtureImageManager($definition)) {
foreach ($old_data as $old_row) {
$this->copyImageEntity($definition, $old_row);
}
}
if (!Db::getInstance()->insert(
$definition['table'],
$data,
false,
true,
Db::INSERT_IGNORE
)) {
throw new PrestaShopException(
'An SQL error occurred for entity <i>%1$s</i>: <i>%2$s</i>',
$definition['table'],
Db::getInstance()->getMsgError()
);
}
unset($data);
foreach ($lang_fixtures as $iso_code => &$data_lang) {
$id_lang = Language::getIdByIso($iso_code);
foreach ($data_lang as &$row) {
$id = null;
if (array_key_exists($row['id'], $this->primary_entities)) {
$id = $this->primary_entities[$row['id']];
}
unset($row['id']);
$row['id_lang'] = $id_lang;
$row[$definition['primary']] = $id;
}
$this->prepareArrayLang($data_lang, $definition);
}
$merge_data_lang = call_user_func_array('array_merge', array_values($lang_fixtures));
if (count($merge_data_lang)) {
if (!Db::getInstance()->insert(
$definition['table'] . '_lang',
$merge_data_lang,
false,
true,
Db::INSERT_IGNORE
)) {
throw new PrestaShopException(
'An SQL error occurred for entity <i>%1$s</i>: <i>%2$s</i>',
$definition['table'] . '_lang',
Db::getInstance()->getMsgError()
);
}
}
$this->entities[] = $definition['table'];
}
public function prepareArray(&$data, $relations, $definition)
{
foreach ($data as &$row) {
foreach ($row as $field_name => &$col) {
if (array_key_exists($field_name, $relations)) {
$relation = $relations[$field_name];
if (is_array($relation)) {
$relation = $relation['variations'][$row[$relation['field']]];
}
if (strpos($relation, '::') !== false) {
list($class_name, $property) = explode('::', $relation);
$class_name = ToolsModuleMEP::toCamelCase($class_name, true);
$id_lang = null;
$definition = ObjectModel::getDefinition($class_name);
if (array_key_exists('multilang', $definition)
&& $definition['multilang']) {
$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
}
$definition_field = $definition['fields'][$property];
if (isset($definition_field['lang']) && $definition_field['lang']) {
$sql = 'SELECT `' . pSQL($definition['primary']) . '`
FROM `' . _DB_PREFIX_ . pSQL($definition['table']) . '_lang`
WHERE `' . pSQL($property) . '` = "' . pSQl($col) . '" AND `id_lang` = ' . (int)$id_lang;
} else {
$sql = 'SELECT `' . pSQL($definition['primary']) . '`
FROM `' . _DB_PREFIX_ . $definition['table'] . '`
WHERE `' . pSQL($property) . '` = "' . pSQl($col) . '"';
}
$col = (int)Db::getInstance()->getValue($sql);
} else {
if (array_key_exists($col, $this->primary_entities)) {
$col = $this->primary_entities[$col];
}
}
}
if (array_key_exists($field_name, $definition['fields'])) {
$def_field = $definition['fields'][$field_name];
if (in_array($def_field['type'], array(ObjectModel::TYPE_HTML, ObjectModel::TYPE_NOTHING))) {
$col = str_replace('\'', '\\\'', $col);
} else {
$col = pSQL($col);
}
}
}
}
}
public function prepareArrayLang(&$data, $definition)
{
foreach ($data as &$row) {
foreach ($row as $field_name => &$col) {
if (array_key_exists($field_name, $definition['fields'])) {
$def_field = $definition['fields'][$field_name];
if (in_array(
$def_field['type'],
array(ObjectModel::TYPE_HTML, ObjectModel::TYPE_NOTHING)
)) {
$col = str_replace('\'', '\\\'', $col);
} else {
$col = pSQL($col);
}
}
}
}
}
public function getCurrentAutoIncrementTable($table)
{
return (int)Db::getInstance()->getValue(
'SELECT `AUTO_INCREMENT`
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = "' . _DB_NAME_ . '"
AND TABLE_NAME = "' . _DB_PREFIX_ . pSQL($table) . '";'
);
}
public function copyImageEntity($definition, $row)
{
$class_image = ToolsModuleMEP::toCamelCase($definition['table'], true);
$fixture_img_path = _PS_MODULE_DIR_ . $this->name . '/fixtures/img/' . $definition['table'] . '/';
$images = glob($fixture_img_path . $row['id'] . '*\.jpg');
if (is_array($images) && count($images)) {
/**
* @var WidgetImage $object_image
*/
$object_image = new $class_image();
$object_image->id = $this->primary_entities[$row['id']];
$object_image->type = $row['type'];
$object_image->createImgFolder();
foreach ($images as $image) {
$image_name = basename($image);
$image_name = str_replace($row['id'], $this->primary_entities[$row['id']], $image_name);
copy($image, $object_image->getPathAbsolute() . $image_name);
}
}
}
public function checkFixtureImageManager($definition)
{
if (array_key_exists('fixture', $definition)) {
$fixture = $definition['fixture'];
if (array_key_exists('image_manager', $fixture)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class FormBuilderMEP
{
protected $form = array(
'tinymce' => false,
'legend' => array(
'title' => 'Nothing'
),
'input' => array()
);
public function __construct($title)
{
$this->form['legend'] = array('title' => $title);
return $this;
}
public function addField(
$label,
$name,
$type,
$required = null,
$lang = null,
$desc = null,
$hint = null,
$suffix = null,
$options = null,
$values = null,
$is_bool = null,
$empty_message = null,
$additional_params = array()
) {
if ($type == 'switch'
&& version_compare(_PS_VERSION_, '1.6.0.0', '<')) {
$type = 'radio';
if (!isset($additional_params['class'])) {
$additional_params['class'] = 't';
} else {
$additional_params['class'] .= ' t';
}
}
$field = array(
'label' => $label,
'name' => $name,
'type' => $type
);
$t = TransModMEP::getInstance();
foreach (array(
'required',
'lang',
'desc',
'hint',
'suffix',
'options',
'values',
'is_bool',
'empty_message'
) as $arg_func) {
if (!is_null($$arg_func)) {
$field[$arg_func] = $$arg_func;
}
}
if (is_null($values)) {
$values = array(
array(
'id' => $name.'_on',
'value' => 1,
'label' => $t->l('Enabled', __FILE__)
),
array(
'id' => $name.'_off',
'value' => 0,
'label' => $t->l('Disabled', __FILE__)
)
);
}
if (in_array($type, array('switch', 'radio', 'checkbox'))) {
$field['values'] = $values;
}
$field = array_merge($field, $additional_params);
if (array_key_exists('autoload_rte', $field) && $field['autoload_rte']) {
$this->form['tinymce'] = true;
}
$this->form['input'][] = $field;
#Fix standart Prestashop
unset($required);
unset($lang);
unset($desc);
unset($hint);
unset($suffix);
unset($options);
unset($values);
unset($is_bool);
unset($empty_message);
#End fix
return $this;
}
public function addSubmit($title)
{
$this->form['submit'] = array(
'title' => $title
);
return $this;
}
public function getForm()
{
return $this->form;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class FormatConfMEP
{
public static function prepareSetting($post_data, $input_array, $id_key, $properties)
{
$return_data = array();
if (is_array($input_array) && count($input_array)) {
foreach ($input_array as $item) {
if (!array_key_exists($item[$id_key], $return_data)) {
$return_data[$item[$id_key]] = array();
}
foreach ($properties as $property => $value) {
if (is_array($post_data) && array_key_exists($item[$id_key], $post_data)
&& array_key_exists($property, $post_data[$item[$id_key]])) {
$return_data[$item[$id_key]][$property] = ToolsModuleMEP::formatValue(
$post_data[$item[$id_key]][$property],
$value['validate']
);
} else {
$return_data[$item[$id_key]][$property] = $value['default_value'];
}
}
}
}
return $return_data;
}
public static function prepareSettingOrderStates($post_data)
{
$input_array = OrderState::getOrderStates(Context::getContext()->language->id);
$properties = array(
'add_bonus' => array('default_value' => 0, 'validate' => ObjectModel::TYPE_INT),
'cancel_bonus' => array('default_value' => 0, 'validate' => ObjectModel::TYPE_INT)
);
return self::prepareSetting($post_data, $input_array, 'id_order_state', $properties);
}
public static function prepareSettingGroup($post_data)
{
$input_array = Group::getGroups(Context::getContext()->language->id);
$properties = array(
'enabled' => array('default_value' => 0, 'validate' => ObjectModel::TYPE_INT),
'commission' => array('default_value' => 0, 'validate' => ObjectModel::TYPE_FLOAT),
'allow_count_product' => array('default_value' => 0, 'validate' => ObjectModel::TYPE_INT),
'allow_count_image' => array('default_value' => 0, 'validate' => ObjectModel::TYPE_INT)
);
return self::prepareSetting($post_data, $input_array, 'id_group', $properties);
}
public static function getSettingGroup()
{
return self::prepareSettingGroup(ConfMEP::getConf('SETTING_GROUPS', ConfMEP::TYPE_ARRAY));
}
public static function getSettingOrderStates()
{
return self::prepareSettingOrderStates(ConfMEP::getConf('SETTING_ORDER_STATES', ConfMEP::TYPE_ARRAY));
}
}

View File

@@ -0,0 +1,701 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperDbMEP
{
const _VERSION_ = '1.1.0';
private $class;
private $instance;
private $definition;
public function __construct($class_name)
{
$this->class = $class_name;
$this->instance = new $class_name();
$this->definition = $this->getDefinition($class_name);
if (isset($this->definition['multilang_shop']) && $this->definition['multilang_shop']
|| $this->existsLangShopField()) {
$this->definition['fields']['id_shop'] = array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedInt',
'lang' => true
);
}
return $this;
}
public function getDefinition($class_name)
{
$class = new ReflectionClass($class_name);
return $class->getStaticPropertyValue('definition');
}
public function installDb()
{
$sql = array();
$exists_fields_shop = false;
$exists_fields_lang = false;
$sql['default'] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.bqSQL($this->definition['table']).'`
(%fields%) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;';
$sql['lang'] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.bqSQL($this->definition['table']).'_lang`
(%fields%) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
$sql['shop'] = 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.bqSQL($this->definition['table']).'_shop`
(%fields%) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8;';
$fields = array(
'default' => array(
$this->definition['primary'] => '`'.bqSQL($this->definition['primary'])
.'` int(10) signed NOT NULL AUTO_INCREMENT'
),
'lang' => array(
$this->definition['primary'] => '`'.bqSQL($this->definition['primary'])
.'` int(10) signed NOT NULL',
'`id_lang` int(10) signed NOT NULL'
),
'shop' => array(
$this->definition['primary'] => '`'.bqSQL($this->definition['primary'])
.'` int(10) signed NOT NULL',
'`id_shop` int(11) signed NOT NULL'
)
);
foreach ($this->definition['fields'] as $key => $field) {
$field_sql = $this->definitionFieldToSQL($key, $field);
if (isset($field['lang']) && $field['lang']) {
$fields['lang'][] = $field_sql;
$exists_fields_lang = true;
}
if (isset($field['shop']) && $field['shop']) {
$fields['shop'][] = $field_sql;
$exists_fields_shop = true;
}
if (!isset($field['lang']) || (isset($field['lang']) && !$field['lang'])) {
$fields['default'][] = $field_sql;
}
}
$fields['default'][] = 'PRIMARY KEY (`'.bqSQL($this->definition['primary']).'`)';
$fields['lang'][] = 'PRIMARY KEY (`'.bqSQL($this->definition['primary']).'`, `id_lang`)';
$fields['shop'][] = 'PRIMARY KEY (`'.bqSQL($this->definition['primary']).'`, `id_shop`)';
foreach ($sql as $type => $s) {
if ($type == 'lang' && !$exists_fields_lang || $type == 'shop' && !$exists_fields_shop) {
continue;
}
$this->execute($s, $fields[$type]);
}
}
/**
* @param string $field_name
* @param string $definition
*
* @return string
*/
public function definitionFieldToSQL($field_name, $definition)
{
$sql_type = $this->getSQLType($definition['type'], (isset($definition['size']) ? $definition['size'] : null));
return '`'.bqSQL($field_name).'` '.$sql_type
.' '.($sql_type != 'text' ? $this->getSQLDefaultVal(
$field_name,
(isset($definition['validate']) ? $definition['validate'] : 'isAnything'),
(isset($definition['required']) && $definition['required'])
) : '');
}
/**
* @param $definition
*
* @return string
*/
public function getSQLTypeByDefinition($definition)
{
return $this->getSQLType($definition['type'], (isset($definition['size']) ? $definition['size'] : null));
}
public function uninstallDb()
{
$sql = array();
$exists_fields_shop = false;
$exists_fields_lang = false;
foreach ($this->definition['fields'] as $field) {
if (isset($field['lang']) && $field['lang']) {
$exists_fields_lang = true;
}
if (isset($field['shop']) && $field['shop']) {
$exists_fields_shop = true;
}
}
$sql['default'] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.bqSQL($this->definition['table']).'`';
if ($exists_fields_lang) {
$sql['lang'] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.bqSQL($this->definition['table']).'_lang`';
}
if ($exists_fields_shop) {
$sql['shop'] = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.bqSQL($this->definition['table']).'_shop`';
}
foreach ($sql as $s) {
Db::getInstance()->execute($s);
}
}
/**
* @param $field_type
* @param null|array|int $size
*
* @return string
*/
public function getSQLType($field_type, $size = null)
{
if ($field_type == ObjectModel::TYPE_STRING
|| $field_type == ObjectModel::TYPE_HTML
|| $field_type == ObjectModel::TYPE_NOTHING) {
if (is_null($size)) {
return 'text';
} else {
return 'varchar('.(int)$size.')';
}
} elseif ($field_type == ObjectModel::TYPE_FLOAT) {
if (is_string($size) && strpos($size, ',') !== false) {
$size = array_map('intval', explode(',', $size));
if (count($size) !== 2) {
$size = array(20, 6);
}
} elseif (is_array($size) && count($size) !== 2) {
$size = array(20, 6);
} elseif (is_int($size)) {
$size = array($size, 6);
} else {
$size = array(20, 6);
}
return 'decimal('.bqSQL($size[0]).','.bqSQL($size[1]).')';
} elseif ($field_type == ObjectModel::TYPE_INT) {
return 'int('.(is_null($size) ? 10 : (int)$size).') signed';
} elseif ($field_type == ObjectModel::TYPE_DATE) {
return 'datetime';
} elseif ($field_type == ObjectModel::TYPE_BOOL) {
return 'tinyint(1)';
}
return 'text';
}
public function getSQLDefaultVal($field, $validate, $required = false)
{
$default_val = ($required ? 'NOT NULL' : '');
switch ($validate) {
case 'isPrice':
return pSQL($default_val).' DEFAULT "0.000000"';
case 'isBool':
return pSQL($default_val).' DEFAULT "'.(isset($this->instance->{$field})
&& $this->instance->{$field} ? pSQL($this->instance->{$field}) : '0').'"';
case 'isDateFormat':
return pSQL($default_val).' DEFAULT "'
.(isset($this->instance->{$field}) && $this->instance->{$field}
? pSQL($this->instance->{$field}) : '0000-00-00 00:00:00').'"';
default:
return ($required ?
$default_val.(isset($this->instance->{$field}) && $this->instance->{$field}
? ' DEFAULT "'.pSQL($this->instance->{$field}).'"' : '')
: (isset($this->instance->{$field}) && $this->instance->{$field}
? ' DEFAULT "'.pSQL($this->instance->{$field}).'"' : 'DEFAULT NULL')
);
}
}
/**
* @param string $table_name
* @param bool $auto_increment
*
* @return string
*/
public function getTemplateTableSql($table_name, $auto_increment = false)
{
return 'CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.bqSQL($table_name).'`
(%fields%) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8 '.($auto_increment ? 'AUTO_INCREMENT=1;' : '');
}
public function execute($sql, $fields)
{
$sql = str_replace('%fields%', implode(',', $fields), $sql);
Db::getInstance()->execute($sql);
}
public function getAll()
{
if (!$this->existsLangField()) {
return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.bqSQL($this->definition['table']).'`');
} else {
return $this->getAllLang();
}
}
private function getAllLang()
{
return Db::getInstance()->executeS(
'SELECT * FROM `'._DB_PREFIX_.bqSQL($this->definition['table']).'` a
LEFT JOIN `'._DB_PREFIX_.bqSQL($this->definition['table']).'_lang` b
ON b.`'.bqSQL($this->definition['primary']).'` = a.`'.bqSQL($this->definition['primary']).'`
AND b.`id_lang` = '.(int)Context::getContext()->language->id
);
}
/**
* @return bool
*/
public function existsLangField()
{
$exists_fields_lang = false;
foreach ($this->definition['fields'] as $field) {
if (isset($field['lang']) && $field['lang']) {
$exists_fields_lang = true;
}
}
return $exists_fields_lang;
}
/**
* @return bool
*/
public function existsShopField()
{
$exists_fields_shop = false;
foreach ($this->definition['fields'] as $field) {
if (isset($field['shop']) && $field['shop']) {
$exists_fields_shop = true;
}
}
return $exists_fields_shop;
}
/**
* @return bool
*/
public function existsLangShopField()
{
$exists_fields_lang_shop = false;
foreach ($this->definition['fields'] as $field) {
if (isset($field['shop']) && $field['shop'] && isset($field['lang']) && $field['lang']) {
$exists_fields_lang_shop = true;
}
}
return $exists_fields_lang_shop;
}
/**
* @param $id
*
* @return mixed
*/
public function getById($id)
{
return Db::getInstance()->getRow(
'SELECT * FROM `'._DB_PREFIX_.bqSQL($this->definition['table']).'`
WHERE `'.bqSQL($this->definition['primary']).'` = '.(int)$id
);
}
/**
* @param $field
* @param $value
*
* @return mixed
*/
public function getByFieldAndValue($field, $value)
{
return Db::getInstance()->getRow(
'SELECT * FROM `'._DB_PREFIX_.bqSQL($this->definition['table']).'`
WHERE `'.pSQL($field).'` = "'.pSQL($value).'"'
);
}
/**
* @return $this
*/
public static function loadClass($class_name)
{
return new self($class_name);
}
/**
* @param string $field
* @param int $id
* @param string $value
*
* @return $this
*/
public function updateObjectField($field, $id, $value)
{
$class_name = $this->class;
$definition = ObjectModel::getDefinition($class_name);
$definition_field = ObjectModel::getDefinition($class_name, $field);
$ids_shop = Shop::getContextListShopID();
$multi_shop_active = (int)Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE');
$lang = (array_key_exists('lang', $definition_field) && $definition_field['lang'] ? true : false);
$shop = (array_key_exists('shop', $definition_field) && $definition_field['shop'] ? true : false);
$multi_lang_shop = (
array_key_exists('multilang_shop', $definition) && $definition['multilang_shop']
? true : false
);
if (!$multi_shop_active || ($lang && $multi_lang_shop) || Shop::getContext() == Shop::CONTEXT_ALL) {
$sql = 'UPDATE '._DB_PREFIX_.bqSQL($definition['table']).($lang ? '_lang' : '');
if ($lang && is_array($value)) {
$languages = Language::getLanguages(false);
$sql .= ' SET `'.pSQL($field).'` = CASE '.PHP_EOL;
foreach ($languages as $l) {
if (array_key_exists($l['id_lang'], $value)) {
$sql .= 'WHEN `id_lang` = '.(int)$l['id_lang']
.' THEN "'.ObjectModel::formatValue($value[$l['id_lang']], $definition_field['type'])
.'" '.PHP_EOL;
}
}
$sql .= 'END ';
} else {
$sql .= ' SET `'.pSQL($field).'` = "'.ObjectModel::formatValue($value, $definition_field['type']).'"';
}
$sql .= ' WHERE `'.bqSQL($definition['primary']).'` = '.(int)$id;
if ($multi_shop_active && $lang && $multi_lang_shop) {
$sql .= ' AND `id_shop` IN('.(count($ids_shop)
? implode(',', array_map('intval', $ids_shop)) : 'NULL').')';
}
Db::getInstance()->execute($sql);
}
if (!$lang && $shop) {
$sql_shop = 'UPDATE '._DB_PREFIX_.bqSQL($definition['table']).'_shop';
$sql_shop .= ' SET `'.pSQL($field).'` = "'.ObjectModel::formatValue($value, $definition_field['type']).'"';
$sql_shop .= ' WHERE `'.bqSQL($definition['primary']).'` = '.(int)$id;
if ($multi_shop_active) {
$sql_shop .= ' AND `id_shop` IN('.(count($ids_shop) ? implode(
',',
array_map('intval', $ids_shop)
) : 'NULL').')';
}
Db::getInstance()->execute($sql_shop);
}
return $this;
}
/**
* @param string|ObjectModel $entity
* @param array $definition_fields
*/
public function installManyToOne($entity, $definition_fields = array())
{
$fields = array();
$fields[$this->definition['primary']] = array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedInt'
);
if ($entity instanceof ObjectModel) {
$def = $this->getDefinition(get_class($entity));
$fields[$def['primary']] = array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedInt');
$table_name = bqSQL($this->definition['table']).'_'.bqSQL($def['table']);
} else {
if (class_exists($entity)) {
$def = $this->getDefinition($entity);
$fields[$def['primary']] = array('type' => ObjectModel::TYPE_INT, 'validate' => 'isUnsignedInt');
}
$table_name = bqSQL($this->definition['table']).'_'.bqSQL(Tools::strtolower($entity));
}
$fields = array_merge($fields, $definition_fields);
$sql = array();
foreach ($fields as $field_name => $field) {
$sql[] = $this->definitionFieldToSQL($field_name, $field);
}
$this->execute($this->getTemplateTableSql($table_name), $sql);
}
public function upgradeManyToOne($entity, $definition_fields = array())
{
$fields = array();
if ($entity instanceof ObjectModel) {
$def = $this->getDefinition(get_class($entity));
$fields[$def['primary']] = array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedInt'
);
$table_name = bqSQL($this->definition['table']).'_'.bqSQL($def['table']);
} else {
if (class_exists($entity)) {
$def = $this->getDefinition($entity);
$fields[$def['primary']] = array(
'type' => ObjectModel::TYPE_INT,
'validate' => 'isUnsignedInt'
);
}
$table_name = bqSQL($this->definition['table']).'_'.bqSQL(Tools::strtolower($entity));
}
$fields = array_merge($fields, $definition_fields);
$list_fields = $this->getFieldsFromDatabase($table_name);
$this->dropNotExistsColumns($table_name, $list_fields, $fields);
$this->upgradeColumnsTable($table_name, $fields, $list_fields);
}
public function deleteManyToOne($entity)
{
if ($entity instanceof ObjectModel) {
$def = $this->getDefinition(get_class($entity));
$table_name = bqSQL($this->definition['table']).'_'.bqSQL($def['table']);
} else {
$table_name = bqSQL($this->definition['table']).'_'.bqSQL(Tools::strtolower($entity));
}
return Db::getInstance()->execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.bqSQL($table_name).'`');
}
public function upgrade()
{
$tables = array(
$this->definition['table'] => array(
'fields' => $this->getFieldsFromDatabase($this->definition['table']),
'type' => 'default',
'excl_columns' => array($this->definition['primary'])
),
$this->definition['table'].'_lang' => array(
'fields' => $this->getLangFieldsFromDatabase($this->definition['table']),
'type' => 'lang',
'excl_columns' => array($this->definition['primary'], 'id_lang')
),
$this->definition['table'].'_shop' => array(
'fields' => $this->getShopFieldsFromDatabase($this->definition['table']),
'type' => 'shop',
'excl_columns' => array($this->definition['primary'], 'id_shop')
)
);
$trigger_install = false;
foreach ($tables as $table => $list_fields) {
if (!count($list_fields['fields']) && !$trigger_install) {
$this->installDb();
$trigger_install = true;
continue;
}
$this->dropNotExistsColumns(
$table,
$list_fields['fields'],
$this->definition['fields'],
$list_fields['excl_columns'],
$list_fields['type']
);
}
foreach ($tables as $table => $list_fields) {
if (!count($list_fields['fields'])) {
continue;
}
$this->upgradeColumnsTable(
$table,
$this->definition['fields'],
$list_fields['fields'],
$list_fields['type']
);
}
}
public function dropNotExistsColumns(
$table,
$list_fields,
$definition_fields,
$excl_columns = array(),
$type_table = null
) {
foreach ($list_fields as $list_field) {
if (in_array($list_field['Field'], $excl_columns)) {
continue;
}
if (!array_key_exists($list_field['Field'], $definition_fields)) {
$this->dropColumnTable($table, $list_field['Field']);
} elseif (!is_null($type_table)) {
$definition_field = $definition_fields[$list_field['Field']];
if (!$this->checkFieldByTypeTable($type_table, $definition_field)) {
$this->dropColumnTable($table, $list_field['Field']);
}
}
}
}
public function checkFieldByTypeTable($type_table, $definition_field)
{
if ($type_table == 'default') {
if (isset($definition_field['lang']) && $definition_field['lang']) {
return false;
}
}
if ($type_table == 'lang') {
if (!isset($definition_field['lang']) || !$definition_field['lang']) {
return false;
}
}
if ($type_table == 'shop') {
if (!isset($definition_field['shop']) || !$definition_field['shop']
|| (isset($definition_field['lang']) && $definition_field['lang'])) {
return false;
}
}
return true;
}
public function upgradeColumnsTable($table, $definition_fields, $list_fields, $type_table = null)
{
$database_fields = array();
foreach ($list_fields as $field) {
$database_fields[$field['Field']] = $field;
}
foreach ($definition_fields as $field_name => $definition) {
if (!is_null($type_table)) {
if (!$this->checkFieldByTypeTable($type_table, $definition)) {
continue;
}
}
if (!array_key_exists($field_name, $database_fields)) {
$this->createColumnTable($table, $field_name, $definition);
} else {
$database_field = $database_fields[$field_name];
$type = $this->getSQLTypeByDefinition($definition);
if ($type != $database_field['Type']) {
$this->changeColumnTable($table, $field_name, $definition);
}
}
}
}
/**
* @param string $table
* @param string $field_name
*
* @return mixed
*/
protected function dropColumnTable($table, $field_name)
{
return Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.bqSQL($table).'`
DROP `'.bqSQL($field_name).'`;');
}
protected function createColumnTable($table, $field_name, $definition)
{
return Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.bqSQL($table).'`
ADD '.$this->definitionFieldToSQL($field_name, $definition));
}
protected function changeColumnTable($table, $field_name, $definition)
{
return Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.bqSQL($table).'`
CHANGE `'.bqSQL($field_name).'` '.$this->definitionFieldToSQL($field_name, $definition));
}
public function checkExistsTable($table)
{
$result = Db::getInstance()->executeS(
'SELECT *
FROM information_schema.tables
WHERE table_schema = \''._DB_NAME_.'\'
AND table_name = \''._DB_PREFIX_.bqSQL($table).'\'
LIMIT 1;'
);
return (is_array($result) && count($result) ? true : false);
}
/**
* @return array
*/
public function getFieldsFromDatabase($table)
{
if (!$this->checkExistsTable($table)) {
return array();
}
$result = Db::getInstance()->executeS('SHOW FIELDS FROM `'._DB_PREFIX_.bqSQL($table).'`');
return (is_array($result) ? $result : array());
}
/**
* @return array
*/
public function getLangFieldsFromDatabase($table)
{
if (!$this->checkExistsTable($table.'_lang')) {
return array();
}
$result = Db::getInstance()->executeS('SHOW FIELDS FROM `'._DB_PREFIX_.bqSQL($table).'_lang`');
return (is_array($result) ? $result : array());
}
/**
* @return array
*/
public function getShopFieldsFromDatabase($table)
{
if (!$this->checkExistsTable($table.'_shop')) {
return array();
}
$result = Db::getInstance()->executeS('SHOW FIELDS FROM `'._DB_PREFIX_.bqSQL($table).'_shop`');
return (is_array($result) ? $result : array());
}
/**
* @param string $class_name
* @param string $field
* @param int $id
* @param string $value
*
* @return $this
*/
public static function updateObjectFieldByClass($class_name, $field, $id, $value)
{
return self::loadClass($class_name)->updateObjectField($field, $id, $value);
}
public function truncate()
{
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.$this->definition['table'].'`');
if ($this->existsLangField()) {
Db::getInstance()->execute('TRUNCATE TABLE `'._DB_PREFIX_.$this->definition['table'].'_lang`');
}
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperModuleMEP
{
public static function addCSS($css_uri, $css_media_type = 'all', $offset = null, $check_path = true)
{
Context::getContext()->controller->addCSS(
_MODULE_DIR_.ToolsModuleMEP::getModNameForPath(__FILE__)
.'/views/css/'.$css_uri,
$css_media_type,
$offset,
$check_path
);
}
public static function addJS($js_uri, $check_path = true)
{
Context::getContext()->controller->addJS(
_MODULE_DIR_.ToolsModuleMEP::getModNameForPath(__FILE__)
.'/views/js/'.$js_uri,
$check_path
);
}
/**
* @return string
*/
public static function getModuleTabAdminLink()
{
/**
* @var $module Module
*/
$module = Module::getInstanceByName(ToolsModuleMEP::getModNameForPath(__FILE__));
return Context::getContext()->link->getAdminLink(
'AdminModules',
true
).'&configure='.ToolsModuleMEP::getModNameForPath(__FILE__)
.'&tab_module='.$module->name.'&tab_module='.$module->tab.'&module_name='.$module->name;
}
public static function createAjaxApiCall($class)
{
$method = Tools::getValue('method');
$call_method = 'ajaxProcess'.ToolsModuleMEP::toCamelCase($method, 1);
if (method_exists($class, $call_method)) {
try {
$result = call_user_func(array($class, $call_method));
die(Tools::jsonEncode(array(
'hasError' => LoggerMEP::getInstance()->hasError(),
'result' => $result,
'log' => LoggerMEP::getInstance()->getMessages()
)));
} catch (Exception $e) {
LoggerMEP::getInstance()->exception($e);
die(Tools::jsonEncode(array(
'hasError' => LoggerMEP::getInstance()->hasError(),
'log' => LoggerMEP::getInstance()->getMessages()
)));
}
}
}
}

View File

@@ -0,0 +1,162 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperObjectMEP
{
public static function validateObject($object, $definition_fields = null)
{
$errors = array();
$definition = ObjectModel::getDefinition($object);
if (is_null($definition_fields)) {
$definition_fields = $definition['fields'];
}
$languages = ToolsModuleMEP::getLanguages(true);
$t = TransModMEP::getInstance();
$empty_field = $t->l('%s is empty', __FILE__);
$empty_lang_field = $t->l('%s for lang %s is empty', __FILE__);
$wrong_field = $t->l('%s wrong', __FILE__);
$wrong_lang_field = $t->l('%s for lang %s wrong', __FILE__);
$max_length_field = $t->l('%s size more %s', __FILE__);
$max_length_lang_field = $t->l('%s for lang %s size more %s', __FILE__);
$fields = array_keys($definition_fields);
foreach ($fields as $field) {
$l_field = $t->ld($field);
if (array_key_exists($field, $definition_fields)) {
$object_field = $object->{$field};
if (array_key_exists('lang', $definition_fields[$field]) && $definition_fields[$field]['lang']) {
foreach ($languages as $lang) {
if (isset($definition_fields[$field]['required']) && $definition_fields[$field]['required']
&& empty($object_field[$lang['id_lang']])) {
$errors[] = sprintf($empty_lang_field, $l_field, $lang['name']);
}
if (!empty($object_field[$lang['id_lang']])
&& !forward_static_call_array(
array('Validate', $definition_fields[$field]['validate']),
array(
$object_field[$lang['id_lang']]
)
)) {
$errors[] = sprintf($wrong_lang_field, $l_field, $lang['name']);
}
if (!empty($object_field[$lang['id_lang']])
&& forward_static_call_array(
array('Validate', $definition_fields[$field]['validate']),
array(
$object_field[$lang['id_lang']]
)
)
&& array_key_exists('size', $definition_fields[$field])
&& Tools::strlen($object_field[$lang['id_lang']]) > $definition_fields[$field]['size']) {
$errors[] = sprintf(
$max_length_lang_field,
$l_field,
$lang['name'],
$definition_fields[$field]['size']
);
}
}
} else {
if (isset($definition_fields[$field]['required'])
&& $definition_fields[$field]['required']
&& empty($object_field)
&& $definition_fields[$field]['type'] != ObjectModel::TYPE_BOOL) {
$errors[] = sprintf($empty_field, $l_field);
}
if (!empty($object_field)
&& array_key_exists('validate', $definition_fields[$field])
&& !forward_static_call_array(
array('Validate', $definition_fields[$field]['validate']),
array(
$object_field
)
)) {
$errors[] = sprintf($wrong_field, $l_field);
}
if (!empty($object_field)
&& array_key_exists('validate', $definition_fields[$field])
&& forward_static_call_array(
array('Validate', $definition_fields[$field]['validate']),
array(
$object_field
)
)
&& array_key_exists('size', $definition_fields[$field])
&& Tools::strlen($object_field) > $definition_fields[$field]['size']) {
$errors[] = sprintf($max_length_field, $l_field, $definition_fields[$field]['size']);
}
}
}
}
return $errors;
}
public static function copyFromPost(&$object, $post_array = null)
{
if (!is_null($post_array)) {
$post = $post_array;
} else {
$post = &${'_POST'};
}
$definition = ObjectModel::getDefinition($object);
$table = $definition['table'];
/* Classical fields */
foreach ($post as $key => $value) {
if (key_exists($key, $object) && $key != 'id_'.$table) {
/* Do not take care of password field if empty */
if ($key == 'passwd' && Tools::getValue('id_'.$table) && empty($value)) {
continue;
}
/* Automatically encrypt password in MD5 */
if ($key == 'passwd' && !empty($value)) {
$value = Tools::encrypt($value);
}
$object->{$key} = $value;
}
}
/* Multilingual fields */
$rules = call_user_func(array(get_class($object), 'getValidationRules'), get_class($object));
if (count($rules['validateLang'])) {
$languages = ToolsModuleMEP::getLanguages(false);
foreach ($languages as $language) {
foreach (array_keys($rules['validateLang']) as $field) {
if (isset($post[$field.'_'.(int)$language['id_lang']])) {
$object->{$field}[(int)$language['id_lang']] = $post[$field.'_'.(int)$language['id_lang']];
}
}
}
}
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,109 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2021 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class LoggerMEP
*/
class LoggerMEP
{
const LOG_ERROR = 'error';
const LOG_SUCCESS = 'success';
const LOG_MESSAGE = 'message';
protected $messages = array();
protected $has_error = false;
protected function __construct()
{
}
/**
* @var LoggerMEP
*/
protected static $instance = null;
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* @param $message
* @param $type
*/
public function log($message, $type)
{
$this->messages[] = array(
'message' => $message,
'type' => $type
);
}
/**
* @param $message
*/
public function error($message)
{
$this->has_error = true;
$this->log($message, self::LOG_ERROR);
}
/**
* @param $message
*/
public function success($message)
{
$this->log($message, self::LOG_SUCCESS);
}
/**
* @param $message
*/
public function message($message)
{
$this->log($message, self::LOG_MESSAGE);
}
public function getMessages()
{
return $this->messages;
}
public function exception(Exception $e)
{
$this->error($e->getMessage());
if (_PS_MODE_DEV_) {
$this->message($e->getTraceAsString());
}
}
public function hasError()
{
return $this->has_error;
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class MailModMEP
*/
class MailModMEP
{
public static function getMailTemplatePath()
{
return _PS_MODULE_DIR_ . ToolsModuleMEP::getModNameForPath(__FILE__) . '/mails/';
}
public static function sendMail($template, $email_to, $theme, $template_vars = array())
{
$context = Context::getContext();
self::checkAndFixEmailTemplateForLang($context->language, $template);
Mail::Send(
$context->language->id,
$template,
$theme,
$template_vars,
$email_to,
null,
Configuration::get('PS_SHOP_EMAIL'),
Configuration::get('PS_SHOP_NAME'),
null,
null,
self::getMailTemplatePath()
);
}
public static function fixEmailTemplateForLang($lang, $template_filename)
{
if (!file_exists($template_path = self::getMailTemplatePath() . $lang->iso_code)) {
mkdir($template_path = self::getMailTemplatePath() . $lang->iso_code);
}
$default_template_path = self::getMailTemplatePath() . 'en/';
$template_path = self::getMailTemplatePath() . $lang->iso_code . '/' . $template_filename;
if (file_exists($default_template_path . $template_filename)) {
call_user_func_array(
'copy',
array(
$default_template_path . $template_filename,
$template_path
)
);
}
}
public static function checkAndFixEmailTemplateForLang($lang, $template)
{
$template_path = self::getMailTemplatePath() . $lang->iso_code . '/' . $template;
if (!file_exists($template_path . '.txt')) {
self::fixEmailTemplateForLang($lang, $template . '.txt');
}
if (!file_exists($template_path . '.html')) {
self::fixEmailTemplateForLang($lang, $template . '.html');
}
}
}

View File

@@ -0,0 +1,280 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ModuleAdminControllerMEP extends ModuleAdminController
{
/**
protected $position_identifier = 'id_object';
*/
/**
* @var bool
*/
public $redirect_to_controller = false;
/**
* @var int
*/
public $thumbnail_list_size = 50;
public function __construct()
{
if ($this->redirect_to_controller) {
$this->context = Context::getContext();
$this->table = 'configuration';
$this->identifier = 'id_configuration';
$this->className = 'Configuration';
$this->lang = false;
$this->bootstrap = true;
$this->display = 'list';
}
/**
$this->list_id = 'table';
$this->_defaultOrderBy = 'position';
$this->_defaultOrderWay = 'ASC';
*/
parent::__construct();
if ($this->redirect_to_controller) {
Tools::redirectAdmin(
$this->context->link->getAdminLink($this->redirect_to_controller, true)
);
}
SmartyMEP::registerSmartyFunctions();
ToolsModuleMEP::globalAssignVar();
ToolsModuleMEP::convertJSONRequestToPost();
}
public function assignModuleTabAdminLink()
{
$this->context->smarty->assign(
'link_to_documentation',
HelperModuleMEP::getModuleTabAdminLink()
);
}
public function setMedia()
{
parent::setMedia();
if (property_exists($this, 'position_identifier')) {
$this->context->controller->addJqueryUI('ui.sortable');
}
}
public function renderList()
{
if ($this->module->documentation) {
$this->assignModuleTabAdminLink();
return ToolsModuleMEP::fetchTemplate(
'admin/documentation_row.tpl'
).parent::renderList();
} else {
return parent::renderList();
}
}
public function renderView()
{
if ($this->module->documentation) {
$this->assignModuleTabAdminLink();
return ToolsModuleMEP::fetchTemplate(
'admin/documentation_row.tpl'
).parent::renderView();
} else {
return parent::renderView();
}
}
public function renderForm()
{
if ($this->module->documentation) {
$this->assignModuleTabAdminLink();
return ToolsModuleMEP::fetchTemplate(
'admin/documentation_row.tpl'
).parent::renderForm();
} else {
return parent::renderForm();
}
}
public function initAngular()
{
ToolsModuleMEP::autoloadCSS($this->module->getPathUri().'views/css/autoload/');
$this->context->controller->addJS(array(
$this->module->getPathUri().'views/js/lib/angular/vendor/jquery.fileStyle.js',
$this->module->getPathUri().'views/js/lib/angular/vendor/jquery.binarytransport.js',
$this->module->getPathUri().'views/js/lib/angular/vendor/jquery.binarytransport.js',
$this->module->getPathUri().'views/js/lib/angular/vendor/angular.js'
));
AngularAppMEP::getInstance(
$this->module->getPathUri().'views/js/lib/angular/vendor/packages/lazy-load/'
)->autoloadApp();
AngularAppMEP::getInstance(
$this->module->getPathUri().'views/js/lib/angular/'
)->autoloadApp();
}
public $return = array();
public function ajaxProcessApi()
{
ErrorHandlerMEP::setErrorHandler();
HelperModuleMEP::createAjaxApiCall($this);
}
protected function assignAngularFiles()
{
$angular_templates_folder = $this->module->getLocalPath().'views/templates/admin/angular-templates';
$angular_templates = ToolsModuleMEP::globRecursive($angular_templates_folder.'/**.tpl');
foreach ($angular_templates as &$path) {
$path = str_replace($angular_templates_folder.'/', '', $path);
}
unset($path);
$this->context->smarty->assign('angular_templates', $angular_templates);
$this->context->smarty->assign(
'path_angular',
_PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/'
);
}
public function processSave()
{
/**
* @var ObjectModelMEP $object
*/
$object = parent::processSave();
$object_name = $this->className;
$property = 'has_image';
if (Validate::isLoadedObject($object)
&& property_exists($object_name, $property) && $object_name::$$property) {
$property = 'lang_image';
if (property_exists($object_name, $property) && $object_name::$$property) {
foreach (ToolsModuleMEP::getLanguages(false) as $l) {
$image = Tools::fileAttachment('image_'.$l['id_lang']);
if ($image['tmp_name'] && ToolsModuleMEP::checkImage($image['tmp_name'])) {
$object->uploadImage($image['tmp_name'], $l['id_lang']);
}
}
} else {
$image = Tools::fileAttachment('image');
if ($image['tmp_name'] && ToolsModuleMEP::checkImage($image['tmp_name'])) {
$object->uploadImage($image['tmp_name']);
}
}
}
return $object;
}
public function getFieldsValue($obj)
{
$fields_value = parent::getFieldsValue($obj);
$object_name = $this->className;
$property = 'has_image';
if (property_exists($object_name, $property) && $object_name::$$property) {
$fields_value['image'] = $obj->getImage();
}
return $fields_value;
}
public function getList(
$id_lang,
$order_by = null,
$order_way = null,
$start = 0,
$limit = null,
$id_lang_shop = false
) {
parent::getList($id_lang, $order_by, $order_way, $start, $limit, $id_lang_shop);
if (array_key_exists('image', $this->fields_list)) {
$object_name = $this->className;
$property = 'lang_image';
$id_lang = null;
if (property_exists($object_name, $property) && $object_name::$$property) {
$id_lang = $this->context->language->id;
}
foreach ($this->_list as &$row) {
$row['image'] = forward_static_call(
array($this->className, 'getObjectThumbnail'),
$row[$this->identifier],
$this->thumbnail_list_size,
$id_lang
);
}
}
}
public function ajaxProcessDeleteImage()
{
$id_lang = Tools::getValue('id_lang', null);
/**
* @var ObjectModelMEP $object
*/
$object = $this->loadObject(true);
$object->deleteImg($id_lang);
die(Tools::jsonEncode(array(
'hasError' => false
)));
}
public function ajaxProcessUpdatePositions()
{
if ($this->tabAccess['edit'] === '1') {
$way = (int)Tools::getValue('way');
$id_object = (int)Tools::getValue('id');
$positions = Tools::getValue($this->table);
$new_positions = array();
foreach ($positions as $v) {
if (!empty($v)) {
$new_positions[] = $v;
}
}
foreach ($new_positions as $position => $value) {
$pos = explode('_', $value);
if (isset($pos[2]) && (int)$pos[2] === $id_object) {
$object_name = $this->className;
if ($object = new $object_name((int)$pos[2])) {
if (isset($position) && $object->updatePosition($way, $position, $id_object)) {
echo 'ok position '.(int)$position.' for item '.(int)$pos[1].'\r\n';
} else {
echo '{"hasError" : true, "errors" : "Can not update item '
.(int)$id_object.' to position '.(int)$position.' "}';
}
} else {
echo '{"hasError" : true, "errors" : "This item ('.(int)$id_object.') can t be loaded"}';
}
break;
}
}
}
die();
}
}

View File

@@ -0,0 +1,367 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ModuleContainerMEP
{
/**
* @var Module
*/
public $module;
/**
* @var Context
*/
public $context;
/**
* @var array
*/
public $hooks = array();
/**
* @var array
*/
public $classes = array();
/**
* @var array
*/
public $config = array();
/**
* @var array
*/
public $tabs = array();
public $documentation = false;
public $documentation_type = null;
public $install_fixtures = false;
const DOCUMENTATION_TYPE_TAB = 'tab';
const DOCUMENTATION_TYPE_SIMPLE = 'simple';
/**
* ModuleContainerMEP constructor.
* @param $module Module
*/
protected function __construct($module)
{
$this->module = $module;
$this->context = Context::getContext();
$this->documentation_type = self::DOCUMENTATION_TYPE_SIMPLE;
}
/**
* @var LoggerMEP
*/
protected static $instance = null;
public static function getInstance($module)
{
if (is_null(self::$instance)) {
self::$instance = new self($module);
}
return self::$instance;
}
/**
* @param array $hooks
* @return $this
*/
public function setHooks($hooks)
{
$this->hooks = $hooks;
return $this;
}
/**
* @param array $classes
* @return $this
*/
public function setClasses($classes)
{
$this->classes = $classes;
return $this;
}
/**
* @param array $configs
* @return $this
*/
public function setConfig($configs)
{
$this->config = $configs;
return $this;
}
/**
* @param array $tabs
* @return $this
*/
public function setTabs($tabs)
{
$this->tabs = $tabs;
return $this;
}
public function getTabs()
{
return $this->formatTabs($this->tabs);
}
/**
* @param int $value
* @return $this
*/
public function setInstallFixtures($value)
{
$this->install_fixtures = $value;
return $this;
}
/**
* @param $type
* @return $this
*/
public function setDocumentationType($type)
{
$this->documentation_type = $type;
return $this;
}
/**
* @param $value
* @return $this
*/
public function setDocumentation($value)
{
$this->documentation = $value;
return $this;
}
/**
* @return bool
*/
public function registerHooks()
{
foreach ($this->hooks as $hook) {
$this->module->registerHook($hook);
}
return true;
}
/**
* @return bool
*/
public function installClasses()
{
foreach ($this->classes as $class) {
HelperDbMEP::loadClass($class)->installDb();
}
return true;
}
/**
* @return bool
*/
public function uninstallClasses()
{
foreach ($this->classes as $class) {
HelperDbMEP::loadClass($class)->uninstallDb();
}
return true;
}
/**
* @return bool
*/
public function installConfig()
{
foreach ($this->config as $name => $value) {
$type = (is_array($this->config[$name]) ? ConfMEP::TYPE_ARRAY : ConfMEP::TYPE_STRING);
ConfMEP::setConf($name, $value, $type);
}
return true;
}
/**
* @return bool
*/
public function uninstallConfig()
{
foreach (array_keys($this->config) as $name) {
ConfMEP::deleteConf($name);
}
return true;
}
/**
* @param array $tabs
* @return array
*/
public function formatTabs($tabs)
{
if (version_compare(_PS_VERSION_, '1.7.1.0', '>=')) {
foreach ($tabs as &$tab) {
if (!is_array($tab['name'])) {
$tab['name'] = array('en' => $tab['name']);
}
$languages = ToolsModuleMEP::getLanguages(false);
$name = array();
foreach ($languages as $language) {
$name[$language['locale']] = (isset($tab['name'][$language['iso_code']])
? $tab['name'][$language['iso_code']] :
$tab['name']['en']);
}
$tab = array(
'class_name' => $tab['tab'],
'ParentClassName' => $tab['parent'],
'name' => $name,
'visible' => (!isset($tab['visible']) ? true : $tab['visible']),
'icon' => (!isset($tab['icon']) ? '' : $tab['icon']),
);
}
}
return $tabs;
}
/**
* @return bool
*/
public function installTabs()
{
if (version_compare(_PS_VERSION_, '1.7.1.0', '<')) {
foreach ($this->tabs as $tab) {
ToolsModuleMEP::createTab(
$this->module->name,
$tab['tab'],
$tab['parent'],
$tab['name'],
(isset($tab['visible']) ? !$tab['visible'] : false)
);
}
}
return true;
}
/**
* @return bool
*/
public function uninstallTabs()
{
foreach ($this->tabs as $tab) {
ToolsModuleMEP::deleteTab(
isset($tab['tab']) ? $tab['tab'] : $tab['class_name']
);
}
return true;
}
/**
* @return bool
*/
public function install()
{
return $this->registerHooks()
&& $this->installClasses()
&& $this->importFixtures()
&& $this->installConfig()
&& $this->installTabs();
}
/**
* @return bool
*/
public function uninstall()
{
return $this->uninstallClasses()
&& $this->uninstallConfig()
&& $this->uninstallTabs();
}
public function getDocumentation()
{
DocumentationMEP::assignDocumentation();
$return_back_link = '#';
if (count($this->tabs)) {
$return_back_link = $this->context->link->getAdminLink(
isset($this->tabs[0]['class_name'])
? $this->tabs[0]['class_name']
: $this->tabs[0]['tab']
);
}
$this->context->smarty->assign('return_back_link', $return_back_link);
return ToolsModuleMEP::fetchTemplate('admin/documentation.tpl');
}
public function getContent($content)
{
if (!$this->documentation) {
return $content;
} else {
if ($this->documentation_type == self::DOCUMENTATION_TYPE_SIMPLE) {
return $this->getDocumentation();
}
SmartyMEP::registerSmartyFunctions();
$this->context->smarty->assign(array(
'content_tab' => $content,
'documentation' => $this->getDocumentation()
));
return ToolsModuleMEP::fetchTemplate('admin/content.tpl');
}
}
public function importFixtures()
{
if (!$this->install_fixtures) {
return true;
}
$fixture_class = FixtureMEP::getInstance($this->module->name);
foreach ($this->classes as $class_name) {
$fixture_class->importEntity($class_name);
}
return true;
}
public function addColumn()
{
$res = true;
$list_fields = Db::getInstance()->executeS('SHOW FIELDS FROM `'._DB_PREFIX_.'product_shop`');
if (is_array($list_fields)) {
foreach ($list_fields as $k => &$field) {
$field = $field['Field'];
}
if (!in_array('final_price', $list_fields) && $res) {
$res = Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'product_shop`
ADD `final_price` DECIMAL(20,6) NOT NULL');
}
}
return $res;
}
}

View File

@@ -0,0 +1,47 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ModuleFrontControllerMEP extends ModuleFrontController
{
public function setTemplate($template, $params = array(), $locale = null)
{
if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
SmartyMEP::registerSmartyFunctions();
$this->context->smarty->assign(array(
'template_path' => $this->getTemplatePath('front/'.$template),
'navigationPipe' => '>',
'use_taxes' => (int)Configuration::get('PS_TAX')
));
$template = 'module:'.$this->module->name.'/views/templates/front/base_17.tpl';
}
$this->context->smarty->assign(
array(
'is_17' => version_compare(_PS_VERSION_, '1.7.0.0', '>=')
)
);
parent::setTemplate($template, $params, $locale);
}
}

View File

@@ -0,0 +1,258 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ModuleMEP extends Module
{
/**
* @var array
*/
public $hooks = array();
/**
* @var array
*/
public $classes = array();
/**
* @var array
*/
public $config = array();
/**
* @var array
*/
public $tabs = array();
public $documentation = true;
public $documentation_type = null;
public $install_fixtures = false;
const DOCUMENTATION_TYPE_TAB = 'tab';
const DOCUMENTATION_TYPE_SIMPLE = 'simple';
public function __construct()
{
$this->name = ToolsModuleMEP::getModNameForPath(__FILE__);
$this->documentation_type = self::DOCUMENTATION_TYPE_SIMPLE;
$this->bootstrap = true;
if (count($this->tabs)) {
$this->tabs = $this->formatTabs($this->tabs);
}
parent::__construct();
}
/**
* @return bool
*/
public function registerHooks()
{
foreach ($this->hooks as $hook) {
$this->registerHook($hook);
}
return true;
}
/**
* @return bool
*/
public function installClasses()
{
foreach ($this->classes as $class) {
HelperDbMEP::loadClass($class)->installDb();
}
return true;
}
/**
* @return bool
*/
public function uninstallClasses()
{
foreach ($this->classes as $class) {
HelperDbMEP::loadClass($class)->uninstallDb();
}
return true;
}
/**
* @return bool
*/
public function installConfig()
{
foreach ($this->config as $name => $value) {
$type = (is_array($this->module->config[$name]) ? ConfMEP::TYPE_ARRAY : ConfMEP::TYPE_STRING);
ConfMEP::setConf($name, $value, $type);
}
return true;
}
/**
* @return bool
*/
public function uninstallConfig()
{
foreach (array_keys($this->config) as $name) {
ConfMEP::deleteConf($name);
}
return true;
}
/**
* @param array $tabs
* @return array
*/
public function formatTabs($tabs)
{
if (version_compare(_PS_VERSION_, '1.7.1.0', '>=')) {
foreach ($tabs as &$tab) {
if (!is_array($tab['name'])) {
$tab['name'] = array('en' => $tab['name']);
}
$languages = ToolsModuleMEP::getLanguages(false);
$name = array();
foreach ($languages as $language) {
$name[$language['locale']] = (isset($tab['name'][$language['iso_code']])
? $tab['name'][$language['iso_code']] :
$tab['name']['en']);
}
$tab = array(
'class_name' => $tab['tab'],
'ParentClassName' => $tab['parent'],
'name' => $name,
'visible' => (!isset($tab['visible']) ? true : $tab['visible']),
'icon' => (!isset($tab['icon']) ? '' : $tab['icon']),
);
}
}
return $tabs;
}
/**
* @return bool
*/
public function installTabs()
{
if (version_compare(_PS_VERSION_, '1.7.1.0', '<')) {
foreach ($this->tabs as $tab) {
ToolsModuleMEP::createTab(
$this->name,
$tab['tab'],
$tab['parent'],
$tab['name'],
(isset($tab['visible']) ? !$tab['visible'] : false)
);
}
}
return true;
}
/**
* @return bool
*/
public function uninstallTabs()
{
foreach ($this->tabs as $tab) {
ToolsModuleMEP::deleteTab(
isset($tab['tab']) ? $tab['tab'] : $tab['class_name']
);
}
return true;
}
/**
* @return bool
*/
public function install()
{
return parent::install()
&& $this->registerHooks()
&& $this->installClasses()
&& $this->importFixtures()
&& $this->installConfig()
&& $this->installTabs();
}
/**
* @return bool
*/
public function uninstall()
{
return parent::uninstall()
&& $this->uninstallClasses()
&& $this->uninstallConfig()
&& $this->uninstallTabs();
}
public function getDocumentation()
{
DocumentationMEP::assignDocumentation();
$return_back_link = '#';
if (count($this->tabs)) {
$return_back_link = $this->context->link->getAdminLink($this->tabs[0]['class_name']);
}
$this->context->smarty->assign('return_back_link', $return_back_link);
return ToolsModuleMEP::fetchTemplate('admin/documentation.tpl');
}
public function getContent()
{
if (!$this->documentation) {
return $this->getContentTab();
} else {
if ($this->documentation_type == self::DOCUMENTATION_TYPE_SIMPLE) {
return $this->getDocumentation();
}
SmartyMEP::registerSmartyFunctions();
$this->context->smarty->assign(array(
'content_tab' => $this->getContentTab(),
'documentation' => $this->getDocumentation()
));
return ToolsModuleMEP::fetchTemplate('admin/content.tpl');
}
}
public function getContentTab()
{
}
public function importFixtures()
{
if (!$this->install_fixtures) {
return true;
}
$fixture_class = FixtureMEP::getInstance($this->name);
foreach ($this->classes as $class_name) {
$fixture_class->importEntity($class_name);
}
return true;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,310 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ObjectModelMEP extends ObjectModel
{
/**
* @var int
*/
public $position;
/**
* @var bool
*/
public static $has_image = false;
/**
* @var bool
*/
public static $lang_image = false;
public function __construct($id = null, $id_lang = null, $id_shop = null)
{
if (isset(static::$definition['multishop']) && !Shop::isTableAssociated(static::$definition['table'])) {
Shop::addTableAssociation(static::$definition['table'], static::$definition['multishop']);
}
parent::__construct($id, $id_lang, $id_shop);
}
public function getImage()
{
if (static::$lang_image) {
if (!is_null($this->id_lang)) {
if ($this->checkImage($this->id_lang)) {
return $this->getPathImage($this->id_lang);
}
} else {
$images = array();
foreach (ToolsModuleMEP::getLanguages(!defined('_PS_ADMIN_DIR_')) as $l) {
$images[$l['id_lang']] = false;
if ($this->checkImage($l['id_lang'])) {
$images[$l['id_lang']] = $this->getPathImage($l['id_lang']);
}
}
return $images;
}
} else {
if ($this->checkImage()) {
return $this->getPathImage();
}
}
return false;
}
public function uploadImage($tmp_name, $id_lang = null)
{
if (!$this->id) {
return false;
}
if ($tmp_name) {
if ($this->checkImage($id_lang)) {
$this->deleteImg($id_lang);
}
if (ToolsModuleMEP::checkImage($tmp_name)) {
$width = null;
$height = null;
if (property_exists($this, 'image_size')) {
$width = $this->{'image_size'}[0];
$height = $this->{'image_size'}[1];
}
ImageManager::resize($tmp_name, $this->getFullPathImage($id_lang), $width, $height);
}
return true;
}
return false;
}
public function getFullPathImage($id_lang = null)
{
return _PS_MODULE_DIR_ . ToolsModuleMEP::getModNameForPath(__FILE__) . '/views/img/'
. Tools::strtolower($this->getClassName()) . '/'
. (int)$this->id . (!is_null($id_lang) ? '_' . $id_lang : '') . '.jpg';
}
public function getPathImage($id_lang = null)
{
return _MODULE_DIR_ . ToolsModuleMEP::getModNameForPath(__FILE__) . '/views/img/'
. Tools::strtolower($this->getClassName()) . '/'
. (int)$this->id . (!is_null($id_lang) ? '_' . $id_lang : '') . '.jpg';
}
public function checkImage($id_lang = null)
{
return file_exists($this->getFullPathImage($id_lang));
}
public function deleteImg($id_lang = null)
{
if ($this->checkImage($id_lang)) {
unlink($this->getFullPathImage($id_lang));
if (file_exists(_PS_TMP_IMG_DIR_ . $this->getThumbnailName($id_lang))) {
unlink(_PS_TMP_IMG_DIR_ . $this->getThumbnailName($id_lang));
}
}
}
public function getClassName()
{
return 'object_model';
}
public function toArray()
{
$array = array(
'id' => $this->id
);
if (static::$has_image) {
$array['image'] = $this->getImage();
}
foreach (static::$definition['fields'] as $field_name => $field) {
unset($field);
if (Tools::substr($field_name, 0, 4) == 'ids_') {
$field_name = Tools::substr($field_name, 4);
}
$method = 'toArray' . ToolsModuleMEP::toCamelCase($field_name, true);
if (method_exists($this, $method)) {
$array[$field_name] = $this->{$method}();
} else {
$array[$field_name] = $this->{$field_name};
}
}
return $array;
}
public function getThumbnailName($id_lang = null)
{
return 'tmp_' . $this->getClassName() . '_' . $this->id . (!is_null($id_lang) ? '_' . $id_lang : '') . '.jpg';
}
/**
* @return DbQuery
*/
public static function getAllQuery()
{
$query = new DbQuery();
$query->select('a.`' . static::$definition['primary'] . '`, a.`name`');
$query->from(static::$definition['table'], 'a');
return $query;
}
public static function getAll($as_array = false, $id_lang = null, DbQuery $query = null)
{
$result = Db::getInstance()->executeS((!is_null($query) ? $query->build() : static::getAllQuery()->build()));
$result = is_array($result) && count($result) ? $result : array();
$items = array();
foreach ($result as $item) {
$object = new static($item[static::$definition['primary']], $id_lang);
$items[] = ($as_array ? $object->toArray() : $object);
}
return $items;
}
public static function getObjectThumbnail($id_object, $size, $id_lang = null)
{
$object = new static();
$object->id = $id_object;
return ImageManager::thumbnail(
$object->getFullPathImage($id_lang),
$object->getThumbnailName($id_lang),
$size
);
}
public static function getObjectImageLink($id_object, $id_lang = null)
{
/**
* @var $object ObjectModel
*/
$object = new static();
$object->id = $id_object;
$object->id_lang = $id_lang;
return $object->getImage();
}
/**
* Move a feature
* @param bool $way Up (1) or Down (0)
* @param int $position
* @return bool Update result
*/
public function updatePosition($way, $position, $id_object = null)
{
if (!$res = Db::getInstance()->executeS(
'SELECT `position`, `' . pSQL(static::$definition['primary']) . '`
FROM `' . _DB_PREFIX_ . pSQL(static::$definition['table']) . '`
WHERE `' . pSQL(static::$definition['primary']) . '` = ' . (int)($id_object ? $id_object : $this->id) . '
ORDER BY `position` ASC'
)) {
return false;
}
foreach ($res as $item) {
if ((int)$item[static::$definition['primary']] == (int)$this->id) {
$moved_item = $item;
}
}
if (!isset($moved_item) || !isset($position)) {
return false;
}
// < and > statements rather than BETWEEN operator
// since BETWEEN is treated differently according to databases
return (Db::getInstance()->execute(
'UPDATE `' . _DB_PREFIX_ . pSQL(static::$definition['table']) . '`
SET `position`= `position` ' . ($way ? '- 1' : '+ 1') . '
WHERE `position`
' . (
$way
? '> ' . (int)$moved_item['position'] . ' AND `position` <= ' . (int)$position
: '< ' . (int)$moved_item['position'] . ' AND `position` >= ' . (int)$position
)
)
&& Db::getInstance()->execute(
'UPDATE `' . _DB_PREFIX_ . pSQL(static::$definition['table']) . '`
SET `position` = ' . (int)$position . '
WHERE `' . pSQL(static::$definition['primary']).'`=' . (int)$moved_item[static::$definition['primary']]
));
}
/**
* Reorder object position
* Call it after deleting a feature.
*
* @return bool $return
*/
public static function cleanPositions()
{
Db::getInstance()->execute('SET @i = -1', false);
$sql = 'UPDATE `' . _DB_PREFIX_ . pSQL(static::$definition['table']) . '`
SET `position` = @i:=@i+1 ORDER BY `position` ASC';
return (bool)Db::getInstance()->execute($sql);
}
/**
* getHigherPosition
*
* Get the higher object position
*
* @return int $position
*/
public static function getHigherPosition()
{
$sql = 'SELECT MAX(`position`)
FROM `' . _DB_PREFIX_ . pSQL(static::$definition['table']) . '`';
$position = DB::getInstance()->getValue($sql);
return (is_numeric($position)) ? $position : -1;
}
public function add($auto_date = true, $null_values = false)
{
if (array_key_exists('position', static::$definition['fields'])) {
if ($this->position <= 0) {
$this->position = self::getHigherPosition() + 1;
}
}
return parent::add($auto_date, $null_values);
}
public function delete()
{
if (static::$lang_image) {
foreach (ToolsModuleMEP::getLanguages(false) as $l) {
$this->deleteImg($l['id_lang']);
}
} else {
$this->deleteImg();
}
if (array_key_exists('position', static::$definition['fields'])) {
$this->cleanPositions();
}
return parent::delete();
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class SortMEP
{
public function reindexPositionsByPrice()
{
$categories = Category::getSimpleCategories($this->context->language->id);
foreach ($categories as $category) {
$id_category = $category['id_category'];
$products = $this->getProductsCategory($id_category);
usort($products, array($this, 'sortProductByPrice'));
foreach ($products as $key => $product) {
Db::getInstance()->update(
'category_product',
array(
'position' => $key
),
' id_product = '.(int)$product['id_product'].' AND id_category = '.(int)$id_category
);
}
}
}
public function getProductsCategory($id_category)
{
return Db::getInstance()->executeS(
'SELECT id_product FROM '._DB_PREFIX_.'category_product
WHERE id_category = '.(int)$id_category
);
}
public function sortProductByPrice($a, $b)
{
$price_a = Product::getPriceStatic($a['id_product']);
$price_b = Product::getPriceStatic($b['id_product']);
if ($price_a == $price_b) {
return 0;
}
return ($price_a < $price_b ? -1 : 1);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,50 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ReflectionUtilMEP
{
public static function getClassSource(ReflectionClass $class)
{
$path = $class->getFileName();
$lines = @file($path);
$from = $class->getStartLine();
$to = $class->getEndLine();
$len = $to - $from + 1;
return implode(array_slice($lines, $from-1, $len));
}
public static function getClassSourceByClassName($class_name)
{
self::getClassSource(new ReflectionClass($class_name));
}
public static function getDirNameClass($class_name)
{
$reflector = new ReflectionClass($class_name);
$fn = $reflector->getFileName();
return dirname($fn);
}
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class SmartyMEP
{
protected static $cache_smarty_plugins = array();
/**
* @param $type
* @param $function
* @param $params
* @return bool
*/
protected static function registerFunction($type, $function, $params)
{
$cache_key = $type . '-' . $function;
if (in_array($cache_key, self::$cache_smarty_plugins)) {
return false;
}
$smarty = Context::getContext()->smarty;
if (array_key_exists($function, $smarty->registered_plugins[$type])) {
$smarty->unregisterPlugin($type, $function);
}
$smarty->registerPlugin($type, $function, $params);
self::$cache_smarty_plugins[] = $cache_key;
return true;
}
/**
* @void
*/
public static function registerSmartyFunctions()
{
$smarty = Context::getContext()->smarty;
self::registerFunction(
'modifier',
'no_escape',
array(__CLASS__, 'noEscape')
);
self::registerFunction(
'function',
'get_image_lang',
array(__CLASS__, 'getImageLang')
);
self::registerFunction(
'function',
'renderTemplate',
array(__CLASS__, 'renderTemplate')
);
self::registerFunction(
'function',
'categoryImage',
array(__CLASS__, 'categoryImage')
);
self::registerFunction(
'function',
'versionCompare',
array(__CLASS__, 'versionCompare')
);
self::registerFunction(
'modifier',
'versionCompare',
array(__CLASS__, 'versionCompareModifier')
);
self::registerFunction(
'modifier',
'pluralForm',
array(__CLASS__, 'pluralForm')
);
if (class_exists('TransModMEP')) {
self::registerFunction(
'modifier',
'ld',
array(TransModMEP::getInstance(), 'ld')
);
}
self::registerFunction(
'modifier',
'dt',
array(__CLASS__, 'smartyDateFormatTranslate')
);
if (!array_key_exists('displayPrice', $smarty->registered_plugins['function'])) {
smartyRegisterFunction(
$smarty,
'function',
'displayPrice',
array('Tools', 'displayPriceSmarty')
);
}
}
public static function noEscape($value)
{
return $value;
}
public static function pluralForm($params, &$smarty)
{
$n = $params['n'];
$form1 = $params['form1'];
$form2 = $params['form2'];
$form5 = $params['form5'];
$n = abs($n) % 100;
$n1 = $n % 10;
if ($n > 10 && $n < 20) {
return $form5;
}
if ($n1 > 1 && $n1 < 5) {
return $form2;
}
if ($n1 == 1) {
return $form1;
}
unset($smarty);
return $form5;
}
public static function getImageLang($smarty)
{
$path = $smarty['path'];
$module_path = ToolsModuleMEP::getModNameForPath(__FILE__) . '/views/img/';
$module_lang_path = $module_path . Context::getContext()->language->iso_code . '/';
$module_lang_default_path = $module_path . 'en/';
$path_image = false;
if (file_exists(_PS_MODULE_DIR_ . $module_lang_path . $path)) {
$path_image = _MODULE_DIR_ . $module_lang_path . $path;
} elseif (file_exists(_PS_MODULE_DIR_ . $module_lang_default_path . $path)) {
$path_image = _MODULE_DIR_ . $module_lang_default_path . $path;
}
$attrs = '';
if (isset($smarty['attrs'])) {
foreach ($smarty['attrs'] as $name => $attr) {
$attrs .= ' ' . $name . '="' . $attr . '"';
}
}
if ($path_image) {
return '<img src="' . $path_image . '" ' . $attrs . '>';
} else {
return '[can not load image "' . $path . '"]';
}
}
public static function renderTemplate($smarty)
{
$file = $smarty['file'];
$v = isset($smarty['v']) ? $smarty['v'] : array();
return ToolsModuleMEP::fetchTemplate($file, $v);
}
public static function categoryImage($smarty)
{
$id_category = $smarty['id'];
return (Tools::file_exists_cache(_PS_CAT_IMG_DIR_ . (int)$id_category . '.jpg')
|| Tools::file_exists_cache(_PS_CAT_IMG_DIR_ . (int)$id_category . '_thumb.jpg'))
? (int)$id_category : Language::getIsoById(Context::getContext()->language->id) . '-default';
}
public static function versionCompare($smarty)
{
$version = $smarty['v'];
$operand = $smarty['op'];
return version_compare(_PS_VERSION_, $version, $operand);
}
public static function versionCompareModifier($value, $version, $operand)
{
return (version_compare(_PS_VERSION_, $version, $operand) ? $value : '');
}
public static function smartyDateFormatTranslate($date, $format = null)
{
return ToolsModuleMEP::dateFormatTranslate($date, $format);
}
}

View File

@@ -0,0 +1,636 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ToolsModuleMEP
*/
class ToolsModuleMEP
{
public static $languages = array();
public static function toCamelCase($str, $capitaliseFirstChar = false)
{
$str = Tools::strtolower($str);
$str = str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $str)));
if (!$capitaliseFirstChar) {
$str = lcfirst($str);
}
return $str;
}
public static function getLanguages($active = true)
{
$cache_id = md5($active);
if (array_key_exists($cache_id, self::$languages)) {
return self::$languages[$cache_id];
}
$languages = Language::getLanguages($active);
foreach ($languages as &$l) {
$l['is_default'] = (Configuration::get('PS_LANG_DEFAULT') == $l['id_lang']);
}
self::$languages[$cache_id] = $languages;
return $languages;
}
/**
* @param $module_name string
* @param $class_name string
* @param $parent string
* @param $name mixed
* @return void
*/
public static function createTab($module_name, $class_name, $parent = null, $name = 'Tab', $hide = false)
{
if (!is_array($name)) {
$name = array('en' => $name);
} elseif (is_array($name) && !count($name)) {
$name = array('en' => $class_name);
} elseif (is_array($name) && count($name) && !isset($name['en'])) {
$name['en'] = current($name);
}
$tab = new Tab();
$tab->class_name = $class_name;
$tab->module = $module_name;
$tab->id_parent = (!is_null($parent) ? Tab::getIdFromClassName($parent) : 0);
if ($hide) {
$tab->hide_host_mode = true;
$tab->active = 0;
} else {
$tab->active = 1;
}
if (is_null($parent)) {
self::copyTabIconInRoot($class_name);
}
foreach (self::getLanguages() as $l) {
$tab->name[$l['id_lang']] = (isset($name[$l['iso_code']]) ? $name[$l['iso_code']] : $name['en']);
}
$tab->add();
}
public static function copyTabIconInRoot($icon)
{
$icon = $icon . '.gif';
$path = _PS_MODULE_DIR_ . basename(dirname(__FILE__)) . '/';
if (!file_exists($path . $icon) && file_exists($path . 'views/img/' . $icon)
&& _PS_VERSION_ < 1.6) {
copy($path . 'views/img/' . $icon, $path . $icon);
}
}
/**
* @param $class_name string
* @return void
*/
public static function deleteTab($class_name)
{
$tab = Tab::getInstanceFromClassName($class_name);
if (!Validate::isLoadedObject($tab)) {
return null;
}
$tab->delete();
self::deleteTab($class_name);
}
public static $module_name = null;
public static function getModNameForPath($path)
{
if (!is_null(self::$module_name)) {
return self::$module_name;
}
$path = str_replace(_PS_ROOT_DIR_, '', $path);
$map_dir = explode(DIRECTORY_SEPARATOR, $path);
$key_module = array_search('modules', $map_dir);
self::$module_name = $map_dir[$key_module + 1];
return self::$module_name;
}
public static function getTemplateDir($path)
{
if (Tools::file_exists_cache(
_PS_THEME_DIR_ . 'modules/'
. self::getModNameForPath(__FILE__) . '/views/templates/' . $path
)) {
return _PS_THEME_DIR_ . 'modules/' . self::getModNameForPath(__FILE__) . '/views/templates/' . $path;
} else {
return _PS_MODULE_DIR_ . self::getModNameForPath(__FILE__) . '/views/templates/' . $path;
}
}
/**
* @param $path
* @param $variables
*
* @return string
*/
public static function fetchTemplate($path, $variables = array())
{
Context::getContext()->smarty->assign($variables);
return Context::getContext()->smarty->fetch(self::getTemplateDir($path));
}
public static function globalAssignVar()
{
Context::getContext()->smarty->assign(array(
'is_15_ps' => self::is15ps()
));
}
/**
* @param string $pattern
* @param int $flags
* @return array
*/
public static function globRecursive($pattern, $flags = 0)
{
$files = glob($pattern, $flags);
if (!$files) {
$files = array();
}
foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
/** @noinspection SlowArrayOperationsInLoopInspection */
$files = array_merge($files, self::globRecursive($dir . '/' . basename($pattern), $flags));
}
return $files;
}
public static function is15ps()
{
return self::isLower('1.6') && !self::isLower('1.5');
}
/**
* @param string $version
* @return bool
*/
public static function isGreater($version)
{
return version_compare(_PS_VERSION_, $version, '>');
}
/**
* @param string $version
* @return bool
*/
public static function isLower($version)
{
return version_compare(_PS_VERSION_, $version, '<');
}
public static function autoloadCSS($uri_path)
{
$full_path = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR
. self::strReplaceFirst(__PS_BASE_URI__, '', $uri_path);
$context = Context::getContext();
$files = self::globRecursive($full_path . '*.css');
if (is_array($files) && count($files)) {
foreach ($files as $file) {
$file_path = str_replace($full_path, '', $file);
$context->controller->addCSS($uri_path . $file_path);
}
}
}
public static function autoloadJS($uri_path)
{
$full_path = _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR
. self::strReplaceFirst(__PS_BASE_URI__, '', $uri_path);
$context = Context::getContext();
$files = self::globRecursive($full_path . '*.js');
if (is_array($files) && count($files)) {
foreach ($files as $file) {
$file_path = str_replace($full_path, '', $file);
$context->controller->addJS($uri_path . $file_path);
}
}
}
public static function convertJSONRequestToPost()
{
$post = &$_POST;
$params = Tools::jsonDecode(Tools::file_get_contents('php://input'), true);
if (is_array($params) && count($params)) {
foreach ($params as $key => $value) {
$post[$key] = $value;
}
}
}
public static function strReplaceFirst($search, $replace, $subject)
{
$pos = call_user_func('strpos', $subject, $search);
if ($pos !== false) {
$subject = substr_replace($subject, $replace, $pos, Tools::strlen($search));
}
return $subject;
}
public static function buildSQLSearchWhereFromQuery($query, $detailed_search, $field)
{
if (!$query || !$field) {
return '1';
}
if ((int)$detailed_search) {
return $field . ' LIKE "%' . pSQL($query) . '%"';
} else {
$sql_where = array();
$words = explode(' ', $query);
foreach ($words as $word) {
$sql_where[] = $field . ' LIKE "%' . pSQL($word) . '%"';
}
return implode(' AND ', $sql_where);
}
}
public static function getIP()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
public static function checkImage($tmp_name, $type = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG))
{
return in_array(exif_imagetype($tmp_name), $type);
}
public static function arrayMergeRecursiveDistinct(array &$array1, array &$array2)
{
$merged = $array1;
foreach ($array2 as $key => &$value) {
if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) {
$merged[$key] = self::arrayMergeRecursiveDistinct($merged[$key], $value);
} else {
$merged[$key] = $value;
}
}
return $merged;
}
public static function fileForceContents($dir, $contents)
{
if (!file_exists(dirname($dir))) {
mkdir(dirname($dir), 0777, true);
}
if (file_exists($dir)) {
unlink($dir);
}
file_put_contents($dir, $contents);
}
public static function checkItemArray($item_name, $array)
{
return (is_array($array) && count($array) && array_key_exists($item_name, $array));
}
public static function getCookieKey($name, $default_value = '')
{
if (isset(Context::getContext()->cookie->{$name})) {
return Context::getContext()->cookie->{$name};
}
return $default_value;
}
public static function setCookieKey($name, $value)
{
Context::getContext()->cookie->{$name} = $value;
}
/**
* @param $string
* @return array
*/
public static function stringToCss($string)
{
$css_features = array();
if (!$string) {
return $css_features;
}
$features = explode(';', $string);
if (is_array($features) && count($features)) {
foreach ($features as $feature) {
list($property, $value) = explode(':', $feature);
$css_features[trim($property)] = trim($value);
}
}
return $css_features;
}
public static function simpleArrayToInt(&$var)
{
if (!is_array($var)) {
return false;
}
foreach ($var as &$item) {
$item = (int)$item;
}
}
public static function isSerialized($value, &$result = null)
{
if (!is_string($value)) {
return false;
}
if ($value === 'b:0;') {
$result = false;
return true;
}
$length = Tools::strlen($value);
$end = '';
switch ($value[0]) {
case 's':
if ($value[$length - 2] !== '"') {
return false;
}
//no break
case 'b':
case 'i':
case 'd':
$end .= ';';
//no break
case 'a':
case 'O':
$end .= '}';
if ($value[1] !== ':') {
return false;
}
switch ($value[2]) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
break;
default:
return false;
}
//no break
case 'N':
$end .= ';';
if ($value[$length - 1] !== $end[0]) {
return false;
}
break;
default:
return false;
}
if (($result = @unserialize($value)) === false) {
$result = null;
return false;
}
return true;
}
public static function formatValue($value, $type)
{
switch ($type) {
case ObjectModel::TYPE_INT:
$value = (int)$value;
break;
case ObjectModel::TYPE_STRING:
$value = (string)$value;
break;
case ObjectModel::TYPE_FLOAT:
$value = (float)$value;
break;
}
return $value;
}
public static function dateFormatTranslate($date, $format = null)
{
if (is_null($format)) {
$format = 'H:i:s d-m-Y';
}
$l = TransModMEP::getInstance();
$months = explode(
'|',
'January|February|March|April|May|June|July|August|September|October|November|December'
);
$mons = explode('|', 'Jan|Feb|Mar|Apr|May|June|July|Aug|Sept|Oct|Nov|Dec');
$weekdays = explode('|', 'Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday');
$weeks = explode('|', 'Mon|Tue|Wed|Thu|Fri|Sat|Sun');
$date_data = array_merge($months, $mons, $weekdays, $weeks);
$date = date($format, strtotime($date));
$date = str_replace($date_data, array_map(array($l, 'ld'), $date_data), $date);
return $date;
}
public static function arrayInsert(&$array, $position, $insert)
{
if (is_int($position)) {
array_splice($array, $position, 0, $insert);
} else {
$pos = array_search($position, array_keys($array));
$array = array_merge(
array_slice($array, 0, $pos),
$insert,
array_slice($array, $pos)
);
}
}
public function properParseStr($query_string, $arg_separator = '&', $dec_type = PHP_QUERY_RFC1738)
{
$result = array();
$parts = explode($arg_separator, $query_string);
foreach ($parts as $part) {
list($param_name, $param_value) = explode('=', $part, 2);
switch ($dec_type) {
case PHP_QUERY_RFC3986:
$param_name = rawurldecode($param_name);
$param_value = rawurldecode($param_value);
break;
case PHP_QUERY_RFC1738:
default:
$param_name = urldecode($param_name);
$param_value = urldecode($param_value);
break;
}
if (preg_match_all('/\[([^\]]*)\]/m', $param_name, $matches)) {
$param_name = Tools::substr($param_name, 0, strpos($param_name, '['));
$keys = array_merge(array($param_name), $matches[1]);
} else {
$keys = array($param_name);
}
$target = &$result;
foreach ($keys as $index) {
if ($index === '') {
if (isset($target)) {
if (is_array($target)) {
$int_keys = array_filter(array_keys($target), 'is_int');
$index = count($int_keys) ? max($int_keys) + 1 : 0;
} else {
$target = array($target);
$index = 1;
}
} else {
$target = array();
$index = 0;
}
} elseif (isset($target[$index]) && !is_array($target[$index])) {
$target[$index] = array($target[$index]);
}
$target = &$target[$index];
}
if (is_array($target)) {
$target[] = $param_value;
} else {
$target = $param_value;
}
}
return $result;
}
protected static function clearCacheCart()
{
Cache::clean('getPackageShippingCost_*');
Cache::clean('Cart::getDiscountsCustomer_*');
Cache::clean('getContextualValue_*');
Cache::clean('Cart::getCartRules_*');
Cache::clean('Carrier::getMaxDeliveryPriceByPrice_*');
}
public static function getTotalOrderInRub($cart_option = null)
{
$context = Context::getContext();
$cart = $context->cart;
if (!is_null($cart_option)) {
$cart = $cart_option;
}
self::clearCacheCart();
$id_currency = Currency::getIdByIsoCode('RUB');
if ($context->currency->iso_code != 'RUB'
&& $id_currency == Configuration::get('PS_CURRENCY_DEFAULT')) {
$old_currency = $context->currency;
$context->currency = new Currency($id_currency);
$context->cookie->id_currency = $id_currency;
$context->cookie->write();
$cart->id_currency = $id_currency;
$cart->getDeliveryOptionList(null, true);
$total_order = $cart->getOrderTotal(
Configuration::get('PS_TAX'),
Cart::BOTH,
null,
$cart->id_carrier,
false
);
$context->currency = $old_currency;
$context->cookie->id_currency = $old_currency->id;
$context->cookie->write();
$cart->id_currency = $old_currency->id;
self::clearCacheCart();
$cart->getDeliveryOptionList(null, true);
} elseif ($context->currency->iso_code != 'RUB'
&& $id_currency != Configuration::get('PS_CURRENCY_DEFAULT')) {
$total_order = Tools::convertPrice(
$cart->getOrderTotal(
Configuration::get('PS_TAX'),
Cart::BOTH,
null,
$cart->id_carrier,
false
),
$id_currency
);
} else {
$total_order = $cart->getOrderTotal(
Configuration::get('PS_TAX'),
Cart::BOTH,
null,
$cart->id_carrier,
false
);
}
return $total_order;
}
public function decodeCode($code)
{
return preg_replace_callback(
'@\\\(x)?([0-9a-f]{2,3})@',
function ($m) {
if ($m[1]) {
$hex = Tools::substr($m[2], 0, 2);
$unhex = chr(hexdec($hex));
if (Tools::strlen($m[2]) > 2) {
$unhex .= Tools::substr($m[2], 2);
}
return $unhex;
} else {
return chr(octdec($m[2]));
}
},
$code
);
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class TransModMEP
*/
class TransModMEP
{
/**
* @var TransModMEP
*/
protected static $instance = null;
public static function getInstance()
{
if (is_null(self::$instance)) {
self::$instance = new self();
self::$instance->setModuleNameForString(__FILE__);
}
return self::$instance;
}
public function l($string, $file)
{
$source = $this->getSourceByPath($file);
$string = $this->translate($string, $source);
return $string;
}
protected $dynamic = null;
public function ld($string)
{
if (!file_exists(_PS_MODULE_DIR_ . $this->module_name . '/translations')) {
mkdir(_PS_MODULE_DIR_ . $this->module_name . '/translations');
}
$string = pSQL($string);
$file = _PS_MODULE_DIR_ . $this->module_name . '/translations/translate_dynamic.php';
${'_DYNAMIC'} = array();
if (is_null($this->dynamic)) {
if (file_exists($file)) {
$this->dynamic = array();
include($file);
if (count(${'_DYNAMIC'})) {
foreach (${'_DYNAMIC'} as $key => $dynamic) {
$this->dynamic[str_replace('"', '\"', $key)] = $dynamic;
}
}
} else {
$this->dynamic = array();
}
}
$t_key = '->l(\'' . $string . '\')';
if (!array_key_exists($t_key, $this->dynamic)) {
$this->dynamic[$t_key] = $string;
$translate_dynamic = fopen($file, 'w+');
fwrite($translate_dynamic, '<?php' . PHP_EOL);
fwrite($translate_dynamic, '$_DYNAMIC = array();' . PHP_EOL);
foreach ($this->dynamic as $key => $row) {
fwrite($translate_dynamic, '$_DYNAMIC["' . $key . '"] = \'' . $row . '\';' . PHP_EOL);
}
}
return $this->translate($string, 'translate_dynamic');
}
protected $module_name = null;
public function setModuleNameForString($path)
{
if (!is_null($this->module_name)) {
return $this->module_name;
}
$path = str_replace(_PS_ROOT_DIR_, '', $path);
$map_dir = explode(DIRECTORY_SEPARATOR, $path);
$this->module_name = $map_dir[2];
return $this->module_name;
}
public function getSourceByPath($file)
{
$filename = str_replace('.php', '', basename($file));
return Tools::strtolower($filename);
}
public function translate($string, $source)
{
return Translate::getModuleTranslation($this->module_name, $string, $source);
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TabTypeMEP
{
const TAB_FAVORITE = 'favorite';
const TAB_ALL = 'all';
const TAB_SEO = 'seo';
const TAB_ADMINISTRATION = 'administration';
const TAB_QUICK_BULK_UPDATE = 'quick_bulk_update';
const TAB_SHIPPING_LOGISTICS = 'shipping_logistics';
const TAB_MIGRATION_TOOLS = 'migration_tools';
const TAB_ADVERTISING_MARKETING = 'advertising_marketing';
const TAB_MERCHANDIZING = 'merchandizing';
const TAB_FRONT_OFFICE_FEATURES = 'front_office_features';
const TAB_BILLING_INVOICING = 'billing_invoicing';
const TAB_CHECKOUT = 'checkout';
const TAB_DASHBOARD = 'dashboard';
const TAB_EMAILING = 'emailing';
const TAB_PAYMENTS_GATEWAYS = 'payments_gateways';
const TAB_SMART_SHOPPING = 'smart_shopping';
const TAB_PRICING_PROMOTION = 'pricing_promotion';
const TAB_OTHERS = 'others';
const TAB_SLIDESHOWS = 'slideshows';
const TAB_ANALYTICS_STATS = 'analytics_stats';
const TAB_MARKET_PLACE = 'market_place';
const TAB_CONTENT_MANAGEMENT = 'content_management';
const TAB_EXPORT = 'export';
}

View File

@@ -0,0 +1,127 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2021 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class ValidateTypeMEP
{
const IS_IP2_LONG = 'isIp2Long';
const IS_ANYTHING = 'isAnything';
const IS_EMAIL = 'isEmail';
const IS_MODULE_URL = 'isModuleUrl';
const IS_MD5 = 'isMd5';
const IS_SHA1 = 'isSha1';
const IS_FLOAT = 'isFloat';
const IS_UNSIGNED_FLOAT = 'isUnsignedFloat';
const IS_OPT_FLOAT = 'isOptFloat';
const IS_CARRIER_NAME = 'isCarrierName';
const IS_IMAGE_SIZE = 'isImageSize';
const IS_NAME = 'isName';
const IS_HOOK_NAME = 'isHookName';
const IS_MAIL_NAME = 'isMailName';
const IS_MAIL_SUBJECT = 'isMailSubject';
const IS_MODULE_NAME = 'isModuleName';
const IS_TPL_NAME = 'isTplName';
const IS_IMAGE_TYPE_NAME = 'isImageTypeName';
const IS_PRICE = 'isPrice';
const IS_NEGATIVE_PRICE = 'isNegativePrice';
const IS_LANGUAGE_ISO_CODE = 'isLanguageIsoCode';
const IS_LANGUAGE_CODE = 'isLanguageCode';
const IS_STATE_ISO_CODE = 'isStateIsoCode';
const IS_NUMERIC_ISO_CODE = 'isNumericIsoCode';
const IS_DISCOUNT_NAME = 'isDiscountName';
const IS_CATALOG_NAME = 'isCatalogName';
const IS_MESSAGE = 'isMessage';
const IS_COUNTRY_NAME = 'isCountryName';
const IS_LINK_REWRITE = 'isLinkRewrite';
const IS_ROUTE_PATTERN = 'isRoutePattern';
const IS_ADDRESS = 'isAddress';
const IS_CITY_NAME = 'isCityName';
const IS_VALID_SEARCH = 'isValidSearch';
const IS_GENERIC_NAME = 'isGenericName';
const IS_CLEAN_HTML = 'isCleanHtml';
const IS_REFERENCE = 'isReference';
const IS_PASSWD = 'isPasswd';
const IS_PASSWD_ADMIN = 'isPasswdAdmin';
const IS_CONFIG_NAME = 'isConfigName';
const IS_PHP_DATE_FORMAT = 'isPhpDateFormat';
const IS_DATE_FORMAT = 'isDateFormat';
const IS_DATE = 'isDate';
const IS_BIRTH_DATE = 'isBirthDate';
const IS_BOOL = 'isBool';
const IS_PHONE_NUMBER = 'isPhoneNumber';
const IS_EAN13 = 'isEan13';
const IS_UPC = 'isUpc';
const IS_POST_CODE = 'isPostCode';
const IS_ZIP_CODE_FORMAT = 'isZipCodeFormat';
const IS_ORDER_WAY = 'isOrderWay';
const IS_ORDER_BY = 'isOrderBy';
const IS_TABLE_OR_IDENTIFIER = 'isTableOrIdentifier';
const IS_VALUES_LIST = 'isValuesList';
const IS_TAGS_LIST = 'isTagsList';
const IS_PRODUCT_VISIBILITY = 'isProductVisibility';
const IS_INT = 'isInt';
const IS_UNSIGNED_INT = 'isUnsignedInt';
const IS_PERCENTAGE = 'isPercentage';
const IS_UNSIGNED_ID = 'isUnsignedId';
const IS_NULL_OR_UNSIGNED_ID = 'isNullOrUnsignedId';
const IS_LOADED_OBJECT = 'isLoadedObject';
const IS_COLOR = 'isColor';
const IS_URL = 'isUrl';
const IS_TRACKING_NUMBER = 'isTrackingNumber';
const IS_URL_OR_EMPTY = 'isUrlOrEmpty';
const IS_ABSOLUTE_URL = 'isAbsoluteUrl';
const IS_MYSQL_ENGINE = 'isMySQLEngine';
const IS_UNIX_NAME = 'isUnixName';
const IS_TABLE_PREFIX = 'isTablePrefix';
const IS_FILE_NAME = 'isFileName';
const IS_DIR_NAME = 'isDirName';
const IS_TAB_NAME = 'isTabName';
const IS_WEIGHT_UNIT = 'isWeightUnit';
const IS_DISTANCE_UNIT = 'isDistanceUnit';
const IS_SUB_DOMAIN_NAME = 'isSubDomainName';
const IS_VOUCHER_DESCRIPTION = 'isVoucherDescription';
const IS_SORT_DIRECTION = 'isSortDirection';
const IS_LABEL = 'isLabel';
const IS_PRICE_DISPLAY_METHOD = 'isPriceDisplayMethod';
const IS_DNI_LITE = 'isDniLite';
const IS_COOKIE = 'isCookie';
const IS_STRING = 'isString';
const IS_REDUCTION_TYPE = 'isReductionType';
const IS_BOOL_ID = 'isBoolId';
const IS_BOOL__ID = 'isBool_Id';
const IS_LOCALIZATION_PACK_SELECTION = 'isLocalizationPackSelection';
const IS_SERIALIZED_ARRAY = 'isSerializedArray';
const IS_COORDINATE = 'isCoordinate';
const IS_LANG_ISO_CODE = 'isLangIsoCode';
const IS_LANGUAGE_FILE_NAME = 'isLanguageFileName';
const IS_ARRAY_WITH_IDS = 'isArrayWithIds';
const IS_SCENE_ZONES = 'isSceneZones';
const IS_STOCK_MANAGEMENT = 'isStockManagement';
const IS_SIRET = 'isSiret';
const IS_APE = 'isApe';
const IS_CONTROLLER_NAME = 'isControllerName';
const IS_PRESTA_SHOP_VERSION = 'isPrestaShopVersion';
const IS_ORDER_INVOICE_NUMBER = 'isOrderInvoiceNumber';
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,30 @@
<?php
/**
* 2007-2021 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2021 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
if (!class_exists('AutoloaderMEP')) {
require_once(dirname(__FILE__) . '/AutoloaderMEP.php');
AutoloaderMEP::create(dirname(__FILE__) . '/../');
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2012-2021 SeoSA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;