Возможно уже кто-нибудь сталкивался. Прошу откликнуться. Требуется подключить шаблон от яндекса на БУС.
Нам далиШаблон там находятся классы и обработчик события. Привожу отрывки кода и некоторые файлы.
файлenvironment.php
файл delivery.php
и файлindex.php
Я подключил это согласно п.1 статьи Автозагрузка классов
1. Создал папку /local/php_interface/lib/yandex_market в нее поместил файлы environment.php и delivery.php
2. в Папке /local/php_interface создал файл autoload.php
3. В файле /local/php_interface/init.php внес такие строки
Обработчик зарегистрировался. Сайт работает, init.php отработал.
код в консоли возвращает:
array (size=1) 0 =>
array (size=7)
'FROM_MODULE_ID' => string 'yandex.market' (length=13)
'MESSAGE_ID' => string 'onTradingEntityEnvironmentBuildList' (length=35)
'CALLBACK' =>
object(Closure)[72]
'SORT' => int 100
'FULL_PATH' => boolean false
'VERSION' => int 2
'TO_NAME' => string 'callable' (length=8)
Но теперь при работе модуле яндекса возникает ошибка
PhpInterface\YandexMarket\Trading\Environment must extends Yandex\Market\Trading\Entity\Reference\Environment for user (100)
Правильно ли я подключил классы и обработчик событий из исходников?
Нам дали
файл
Код |
---|
<?php namespace PhpInterface\YandexMarket\Trading; use Yandex\Market; use Bitrix\Main; if (!Main\Loader::includeModule('yandex.market')) { return; } class Environment extends Market\Trading\Entity\Sale\Environment { protected function createDelivery() { return new Delivery($this); } protected function createStore() { return new Store($this); } protected function createOrderRegistry() { return new OrderRegistry($this); } } |
Код |
---|
<?php namespace PhpInterface\YandexMarket\Trading; use Yandex\Market; use Bitrix\Main; use Yandex\Market\Trading\Entity as TradingEntity; if (!Main\Loader::includeModule('yandex.market')) { return; } class Delivery extends Market\Trading\Entity\Sale\Delivery { public function calculate($deliveryId, TradingEntity\Reference\Order $order) { /** @var TradingEntity\Reference\Delivery\CalculationResult */ $calculateResult = parent::calculate($deliveryId, $order); if (DeliveryRules::isPickup($deliveryId)) { $saleOrder = $this->getOrderCalculatable($order); $location = $saleOrder->getPropertyCollection()->getDeliveryLocation(); $locationCode = $location !== null ? $location->getValue() : null; $calculateResult->setDeliveryType('PICKUP'); $calculateResult->setOutlets(DeliveryRules::getOutletCodes($deliveryId, $locationCode)); } return $calculateResult; } } |
и файл
Код |
---|
<?php use Bitrix\Main; require_once __DIR__ . '/delivery.php'; require_once __DIR__ . '/deliveryrules.php'; require_once __DIR__ . '/store.php'; require_once __DIR__ . '/order.php'; require_once __DIR__ . '/orderregistry.php'; require_once __DIR__ . '/environment.php'; $eventManager = Main\EventManager::getInstance(); $eventManager->addEventHandler('yandex.market', 'onTradingEntityEnvironmentBuildList', function() { return new Main\EventResult(Main\EventResult::SUCCESS, [ 'CODE' => 'user', 'ENVIRONMENT' => PhpInterface\YandexMarket\Trading\Environment::class, ]); }); |
1. Создал папку /local/php_interface/lib/yandex_market в нее поместил файлы environment.php и delivery.php
2. в Папке /local/php_interface создал файл autoload.php
Код |
---|
<?php Bitrix\Main\Loader::registerAutoLoadClasses(null, [ 'PhpInterface\YandexMarket\Trading\Delivery' => '/local/php_interface/lib/yandex_market/delivery.php', 'PhpInterface\YandexMarket\Trading\DeliveryRules' => '/local/php_interface/lib/yandex_market/deliveryrules.php', 'PhpInterface\YandexMarket\Trading\Environment' => '/local/php_interface/lib/yandex_market/store.php', 'PhpInterface\YandexMarket\Trading\Order' => '/local/php_interface/lib/yandex_market/order.php', 'PhpInterface\YandexMarket\Trading\OrderRegistry' => '/local/php_interface/lib/yandex_market/orderregistry.php', 'PhpInterface\YandexMarket\Trading\Store' => '/local/php_interface/lib/yandex_market/environment.php' ] ); |
Код |
---|
<? require_once($_SERVER['DOCUMENT_ROOT'] . '/local/php_interface/autoload.php'); use Bitrix\Main; use Bitrix\Main\EventManager; use Bitrix\Main\EventResult; use Bitrix\Main\Loader; use Bitrix\Highloadblock as HL; use Bitrix\Main\Entity; $eventManager = EventManager::getInstance(); $eventManager->addEventHandler('yandex.market', 'onTradingEntityEnvironmentBuildList', function () { return new Main\EventResult(Main\EventResult::SUCCESS, [ 'CODE' => 'user', 'ENVIRONMENT' => PhpInterface\YandexMarket\Trading\Environment::class, ]); }); |
Обработчик зарегистрировался. Сайт работает, init.php отработал.
код в консоли возвращает:
Код |
---|
use Bitrix\Main\EventManager; $handlers = EventManager::getInstance()->findEventHandlers("yandex.market", "onTradingEntityEnvironmentBuildList"); echo var_dump($handlers, true); |
array (size=7)
'FROM_MODULE_ID' => string 'yandex.market' (length=13)
'MESSAGE_ID' => string 'onTradingEntityEnvironmentBuildList' (length=35)
'CALLBACK' =>
object(Closure)[72]
'SORT' => int 100
'FULL_PATH' => boolean false
'VERSION' => int 2
'TO_NAME' => string 'callable' (length=8)
Но теперь при работе модуле яндекса возникает ошибка
PhpInterface\YandexMarket\Trading\Environment must extends Yandex\Market\Trading\Entity\Reference\Environment for user (100)
Правильно ли я подключил классы и обработчик событий из исходников?