Обновление запланированной цены Magento 2 Commerce удаляет изображения - PullRequest
0 голосов
/ 17 октября 2018

Для интернет-магазина, над которым я работаю, мне нужно импортировать обновления цен.Я создал скрипт импорта, который делает это для меня.Итак, у меня есть консольная команда, которая говорит с классом конвертера.Этот класс конвертера делает следующее:



    /** @var  \Magento\Framework\Api\SearchResultsInterface $priceData */
    $priceData = $this->priceRepository->getToProcess();

    if ($priceData->getTotalCount()) {
        /**
         * @var  int $counter
         * @var  ItemInterface $priceItem
         */
        $counter = 0;
        foreach ($priceData->getItems() as $priceItem) {
            $this->outputInterface->writeln('importing price ' . ++$counter . ' of ' . $priceData->getTotalCount(),
                $this->getOutputInterface()::VERBOSITY_VERBOSE);
            $jsonData = json_decode($priceItem->getJson(), true);
            if (is_array($jsonData)) {
                $priceAttributes = $jsonData['@attributes'];

                $itemNo = $priceAttributes['ItemNo'];
                $priceType = $priceAttributes['PriceType'];
                $productCollection = $this->getProductsByItemNo($itemNo);

                $this->outputInterface->writeln('Processing price update for' . $itemNo,
                    $this->getOutputInterface()::VERBOSITY_VERBOSE);

                if ($productCollection->getTotalCount() > 0) {
                    foreach ($productCollection->getItems() as $product) {
                        $product->getMediaGalleryEntries();
                        $product->setMediaGalleryEntries($product->getMediaGalleryEntries());
                        /** @var ProductInterface $product */
                        if ($priceType == 1) {
                            //set content update for this date
                            if (!empty($priceAttributes['StartingDate'])) {
                                $startDt = \Datetime::createFromFormat('Y-m-d', $priceAttributes['StartingDate']);
                                $nowDt = new \Datetime();

                                if ($startDt outputInterface->writeln('Start date is in the past. skipping price update ' . $product->getSku(),
                                        $this->getOutputInterface()::VERBOSITY_VERBOSE);
                                    continue;
                                }

                                $stagingUpdate = $this->stagingUpdateFactory->create();
                                $stagingUpdate->setName("Schedule special price for product " . $product->getSku());

                                if ($startDt > $nowDt) {
                                    $this->outputInterface->writeln('Start date in the future, staging update ' . $product->getSku(),
                                        $this->getOutputInterface()::VERBOSITY_VERBOSE);
                                    $stagingUpdate->setStartTime($startDt->format('Y-m-d H:i:s'));
                                }

                                if (!empty($priceAttributes['EndingDate'])) {
                                    $endDt = \Datetime::createFromFormat('Y-m-d', $priceAttributes['EndingDate']);

                                    if ($endDt == $startDt) {
                                        $this->outputInterface->writeln('End date is equal to start Date. This is not possible in Magento. Skipping update ' . $product->getSku(),
                                            $this->getOutputInterface()::VERBOSITY_VERBOSE);
                                        unset($stagingUpdate);
                                        continue;
                                    }

                                    $stagingUpdate->setEndTime($endDt->format('Y-m-d H:i:s'));
                                }

                                $stagingUpdate = $this->stagingUpdateRepository->save($stagingUpdate);
                                $this->versionManager->setCurrentVersionId($stagingUpdate->getId());
                                $product->setSpecialPrice($priceAttributes['UnitPrice']);
                                $this->productStaging->schedule($product, $stagingUpdate->getId());
                            } else {
                                $this->productRepository->save($product);
                            }
                        } else {
                            $product->setPrice($priceAttributes['UnitPrice']);
                            $product->setSpecialPrice(null);
                            $this->productRepository->save($product);
                        }
                    }
                } else {
                    $this->outputInterface->writeln('sku  ' . $itemNo . ' not found',
                        $this->getOutputInterface()::VERBOSITY_VERBOSE);
                }
            }

            $priceItem->setProcessDt(new \DateTime());
            $this->priceRepository->save($priceItem);
        }
    } else {
        $this->getOutputInterface()->writeln('No Prices found',
            $this->getOutputInterface()::VERBOSITY_VERBOSE);
    }

Все это прекрасно работает.В Magento я вижу мой график обновления и добавлена ​​специальная цена, которая должна быть там, так что это нормально.

Проблема здесь в том, что образы обновления пропали.Поэтому при применении запланированного обновления изображения продуктов удаляются.Как это можно исправить?

добавить

->unsetData('media_gallery');
не помогает.

У кого-нибудь есть хорошее предложение, как это исправить?

Мы работаем в Magento Commerce 2.2.3, PHP 7.1.21 и NGINX версии 1.12.2

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...