PImcore hook into pre-update event on dataobject

316
07 марта 2018, 08:31

Доброго времени суток! Действовал по мануалу:

https://pimcore.com/docs/5.0.x/Development_Documentation/Extending_Pimcore/Event_API_and_Event_Manager.html

Добавил в : app/config/services.yml:

services: 
    # default configuration for services in *this* file 
    _defaults: 
        # automatically injects dependencies in your services 
        autowire: true 
        # automatically registers your services as commands, event subscribers, etc. 
        autoconfigure: true 
        # this means you cannot fetch services directly from the container via $container->get() 
        # if you need to do this, you can override this setting on individual services 
        public: true 
 
    # Example custom templating helper 
    # AppBundle\Templating\Helper\Example: 
    #     # templating helpers need to be public as they 
    #     # are fetched from the container on demand 
    #     public: true 
    #     tags: 
    #         - { name: templating.helper, alias: fooBar } 
 
    # Example event listener for objects 
    AppBundle\EventListener\NavCategoryListener: 
         tags: 
             - { name: kernel.event_listener, event: pimcore.dataobject.preUpdate, method: onObjectPreUpdate }

Создал класс с положил как указано:

<?php 
/** 
 * Created by PhpStorm. 
 * User: rtm00 
 * Date: 01.03.2018 
 * Time: 11:46 
 */ 
 
namespace AppBundle\EventListener; 
 
use Pimcore\Event\DataObjectEvents; 
use Pimcore\Event\Model\DataObjectEvent; 
use Symfony\Component\EventDispatcher\EventSubscriberInterface; 
use Pimcore\Model\DataObject; 
use Pimcore\Config; 
use Pimcore\Event\Model\ElementEventInterface; 
use Pimcore\Event\Model\AssetEvent; 
use Pimcore\Event\Model\DocumentEvent; 
 
class NavCategoryListener 
{ 
 
    public function searchInArray(&$navCategorys, int $val) 
    { 
        foreach ($navCategorys as $r){ 
            if($r == $val){ 
                return true; 
            } 
        } 
        return false; 
    } 
 
    public function onObjectPreUpdate (ElementEventInterface  $event) { 
            // do with the object whatever you want ;-) 
        if($event instanceof DataObjectEvent) { 
            $object = $event->getObject(); 
 
            //Load config --> 
            $values = Config::getSystemConfig(); 
            $valueArray = $values->toArray(); 
            $navCategoryClass = $valueArray['cit_ecommerce']['cit_basicCategoryClass']; 
            $productClass = $valueArray['cit_ecommerce']['cit_basicProductClass']; 
 
            //Debug --> 
            $productClass = "Product"; 
            $navCategoryClass = "NavCategory"; 
            //Debug <-- 
 
            $catgoryClass = DataObject\ClassDefinition::getByName($navCategoryClass); 
            //Load config <-- 
 
            $class = $object->getClass(); 
            if($class == $catgoryClass ){ 
                $isProductForIm = $object->getPublished() == true? 1: 0; 
                $navCategorys[] = $object->getId(); 
                //Publish or Unpublish for all Children 
                if($object->hasChildren()){ 
                    $childrenArr = $object->getChildren(); 
                    foreach ($childrenArr as $child){ 
                        if($child->getClass() == $catgoryClass){ 
                            $child->setPublished($object->getPublished()); 
                            $child->save(); 
                            $navCategorys[] = $child->getId(); 
                        } 
                    } 
                } 
 
                //Load Products 
                $attrType = "Pimcore\\Model\\DataObject\\".$productClass; 
                $entries = $attrType::getList(["unpublished" => false]); 
                $entriesList = $entries->load(); 
                foreach ($entriesList as $entity){ 
                    $navCats = $entity->getNavCat(); 
                    if(count($navCats) == 1){ 
                        $navCat = $navCats[0]->getId(); 
                        if($this->searchInArray($navCategorys,$navCat)){ 
                            $entity->setInAssortment($isProductForIm); 
                            $entity->save(); 
                        } 
                    } 
                } 
            } 
        } 
        return; 
    } 
}

Однако при установки точки останова не попадаю в этот класс... в чем может быть проблема??

READ ALSO
Разделить оформление заказа в WooCommerce

Разделить оформление заказа в WooCommerce

После выбора товара человек нажимает "оформить заказ" и попадает на страницу с формой проверки данных, куда доставить и выбора способа оплатыЭто...

258
Как лучше всего подгрузить поля из БД?

Как лучше всего подгрузить поля из БД?

Всем дорого времени сутокНа сайте есть поля с выпадающим списком, поле используется для того чтобы пользователь мог выбрать нужный ему город...

226
Curl php относительные ссылки

Curl php относительные ссылки

Запрашиваю сайт через curl (php), и получаю ее html кодНо проблема в том, что в полученном html документе указаны ОТНОСИТЕЛЬНЫЕ ссылки на подключаемые...

202
Сортировка по убыванию/возрастанию eFilter

Сортировка по убыванию/возрастанию eFilter

На сайте использую фильтр eFilter для показа товаров по параметрам

242