* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ require_once dirname(__FILE__) . '/../RetailcrmPrestashopLoader.php'; class RetailcrmIcmlUpdateUrlEvent extends RetailcrmAbstractEvent implements RetailcrmEventInterface { /** * {@inheritDoc} */ public function execute() { if ($this->isRunning()) { return false; } $this->setRunning(); $shops = $this->getShops(); foreach ($shops as $shop) { RetailcrmContextSwitcher::setShopContext((int) $shop['id_shop']); if (!file_exists(RetailcrmCatalogHelper::getIcmlFilePath())) { continue; } $api = RetailcrmTools::getApiClient(); if (empty($api)) { continue; } $reference = new RetailcrmReferences($api); $site = $reference->getSite(); // todo remove duplicated code if (empty($site)) { continue; } $newYmlUrl = RetailcrmCatalogHelper::getIcmlFileLink(); $siteCode = $site['code']; if ($newYmlUrl !== $site['ymlUrl']) { $api->sitesEdit([ 'code' => $siteCode, 'ymlUrl' => $newYmlUrl, ]); } } return true; } /** * {@inheritDoc} */ public function getName() { return 'RetailcrmIcmlUpdateUrlEvent'; } }