Jump to content

Override через модуль Prestashop 1.5


Recommended Posts

Доброго времени суток. Делаю чеорез оверрайд расширение функции в классе Product.php, заменив дефолтную функцию класса расширеной.

Prestashop 1.5.4.1

<?php
class Product extends ProductCore {
 public static function searchByName($id_lang, $query, Context $context = null)
{
 if (!$context)
  $context = Context::getContext();
 $sql = new DbQuery();
 $sql->select('p.`id_product`, pl.`name`, p.`active`, p.`reference`, m.`name` AS manufacturer_name, stock.`quantity`, product_shop.advanced_stock_management, p.`customizable`');
 $sql->from('category_product', 'cp');
 $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`');
 $sql->join(Shop::addSqlAssociation('product', 'p'));
 $sql->leftJoin('product_lang', 'pl', '
  p.`id_product` = pl.`id_product`
  AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl')
 );
 $sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`');
 $where = 'pl.`name` LIKE \'%'.pSQL($query).'%\'
 OR p.`xml` LIKE \'%'.pSQL($query).'%\'
 OR p.`reference` LIKE \'%'.pSQL($query).'%\'
 OR p.`supplier_reference` LIKE \'%'.pSQL($query).'%\'
 OR  p.`id_product` IN (SELECT id_product FROM '._DB_PREFIX_.'product_supplier sp WHERE `product_supplier_reference` LIKE \'%'.pSQL($query).'%\')';
 $sql->groupBy('`id_product`');
 $sql->orderBy('pl.`name` ASC');
 if (Combination::isFeatureActive())
 {
  $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product` = p.`id_product`');
  $sql->join(Shop::addSqlAssociation('product_attribute', 'pa', false));
  $where .= ' OR pa.`reference` LIKE \'%'.pSQL($query).'%\'';
 }
 $sql->where($where);
 $sql->join(Product::sqlStock('p', 'pa', false, $context->shop));
 $result = Db::getInstance()->executeS($sql);
 if (!$result)
  return false;
 $results_array = array();
 foreach ($result as $row)
 {
  $row['price_tax_incl'] = Product::getPriceStatic($row['id_product'], true, null, 2);
  $row['price_tax_excl'] = Product::getPriceStatic($row['id_product'], false, null, 2);
  $results_array[] = $row;
 }
 return $results_array;
}
}

 

Выше содержание оверрайда. Лежит как и положено в modules/модуль/override/classes/Product.php

При инсталяции все кошерно работает. Собственно вопрос: при деинсталяции или попытке сбросить настройки модуля получаю такой выхлоп:

Parse error: syntax error, unexpected '?' in /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php(1979) : eval()'d code on line 1
Fatal error: Uncaught exception 'ReflectionException' with message 'Class ProductOverrideOriginal_remove does not exist' in /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php:1980 Stack trace: #0 /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php(1980): ReflectionClass->__construct('ProductOverride...') #1 /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php(1898): ModuleCore->removeOverride('Product') #2 /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php(498): ModuleCore->uninstallOverrides() #3 /home/funnykid/elcommerce.com.ua/host/modules/Csync/Csync.php(104): ModuleCore->uninstall() #4 /home/funnykid/elcommerce.com.ua/host/controllers/admin/AdminModulesController.php(487): Csync->uninstall() #5 /home/funnykid/elcommerce.com.ua/host/controllers/admin/AdminModulesController.php(790): AdminModulesControllerCore->postProcessReset() #6 /home/funnykid/elcommerce.com.ua/host/classes/controller/Controller.php(158): AdminModulesControllerCore->postProcess() #7 /home/funnykid/el in /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php on line 1980
[PrestaShop] Fatal error in module Module:
Uncaught exception 'ReflectionException' with message 'Class ProductOverrideOriginal_remove does not exist' in /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php:1980 Stack trace: #0 /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php(1980): ReflectionClass->__construct('ProductOverride...') #1 /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php(1898): ModuleCore->removeOverride('Product') #2 /home/funnykid/elcommerce.com.ua/host/classes/module/Module.php(498): ModuleCore->uninstallOverrides() #3 /home/funnykid/elcommerce.com.ua/host/modules/Csync/Csync.php(104): ModuleCore->uninstall() #4 /home/funnykid/elcommerce.com.ua/host/controllers/admin/AdminModulesController.php(487): Csync->uninstall() #5 /home/funnykid/elcommerce.com.ua/host/controllers/admin/AdminModulesController.php(790): AdminModulesControllerCore->postProcessReset() #6 /home/funnykid/elcommerce.com.ua/host/classes/controller/Controller.php(158): AdminModulesControllerCore->postProcess() #7 /home/funnykid/el

 

Я так понимаю не срабатывае деинсталл оверрайда?

 

Содержимое функции анинсталл модуля:

 

function uninstall()
{
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'category`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product_shop`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'image`  DROP `xml`');
 //Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'stock_available`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'feature`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'feature_value`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'feature_value_lang`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'manufacturer`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'manufacturer` DROP INDEX `UNIQUE`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product_attribute`  DROP `xml`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'product_attribute_shop`  DROP `xml`');
 Db::getInstance()->Execute('DROP TABLE `'._DB_PREFIX_.'cuser`');
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'feature_lang`');
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'group`');
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'group_lang`');
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'group_shop`');
 Db::getInstance()->Execute('TRUNCATE TABLE `'._DB_PREFIX_.'specific_price`');
 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'specific_price`  DROP `xml`');
 if(!Configuration::deleteByName('_PRICE_ID_') OR !parent::uninstall())   return false;
 return true;
}

Link to comment
Share on other sites

×
×
  • Create New...