Created
December 31, 2015 23:20
-
-
Save maximzasorin/6507cf2aa1b6c089f510 to your computer and use it in GitHub Desktop.
Поиск по артикулу и производителю при импорте CSV-файла (HostCMS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// В импортируемом CSV-файле первым должен быть столбец с производителем, а вторым столбец с артикулом | |
/* | |
* В bootstrap.php: | |
* | |
// Поиск по артикулу и производителю при импорте CSV-файла | |
Core_Event::attach('ImportShopItems.onBeforeFindByMarking', array('Shop_Item_Import_Observer_SearchByProdAndVendor', 'onBeforeFindByMarking')); | |
Core_Event::attach('ImportShopItems.onAfterFindByMarking', array('Shop_Item_Import_Observer_SearchByProdAndVendor', 'onAfterFindByMarking')); | |
* | |
*/ | |
defined('HOSTCMS') || exit('HostCMS: access denied.'); | |
class Shop_Item_Import_Observer_SearchByProdAndVendor | |
{ | |
static public function onBeforeFindByMarking($object, $args) | |
{ | |
// Запоминаем товар с производителем | |
Core_Registry::instance()->set('shop_item_with_prod', clone $args[1]); | |
} | |
static public function onAfterFindByMarking($object, $args) | |
{ | |
// Новый товар | |
$oItemWithProd = Core_Registry::instance()->get('shop_item_with_prod'); | |
// Результат поиска по артикулу | |
$oItemWithMarking = $args[1]; | |
$oShop_Item = Core_Entity::factory('shop_item'); | |
$oShop_Item->queryBuilder() | |
->where('marking', '=', $oItemWithMarking->marking) | |
->where('shop_producer_id', '=', $oItemWithProd->shop_producer_id) | |
->limit(1) | |
; | |
$aoShop_Item = $oShop_Item->findAll(); | |
if (count($aoShop_Item) > 0) | |
{ | |
$object->setCurrentItem($aoShop_Item[0]); | |
} | |
else | |
{ | |
$oItemWithProd->marking = $oItemWithMarking->marking; | |
$object->setCurrentItem($oItemWithProd); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment