diff --git a/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php b/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php new file mode 100644 index 0000000..2bae831 --- /dev/null +++ b/Plugin/Model/ResourceModel/Attribute/InStockOptionSelectBuilder.php @@ -0,0 +1,59 @@ + + * @copyright 2019 Divante Sp. z o.o. + * @license See LICENSE_DIVANTE.txt for license details. + */ + +namespace Divante\PimcoreIntegration\Plugin\Model\ResourceModel\Attribute; + +use Magento\CatalogInventory\Model\ResourceModel\Stock\Status; +use Magento\CatalogInventory\Model\Stock\Status as StockStatus; +use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface; +use Magento\Framework\DB\Select; + +/** + * Class InStockOptionSelectBuilder + */ +class InStockOptionSelectBuilder +{ + /** + * CatalogInventory Stock Status Resource Model. + * + * @var Status + */ + private $stockStatusResource; + + /** + * @param Status $stockStatusResource + */ + public function __construct(Status $stockStatusResource) + { + $this->stockStatusResource = $stockStatusResource; + } + + /** + * Add stock status filter to select. + * + * @param OptionSelectBuilderInterface $subject + * @param Select $select + * + * @return Select + * + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterGetSelect(OptionSelectBuilderInterface $subject, Select $select) + { + $select->joinInner( + ['stock' => $this->stockStatusResource->getMainTable()], + 'stock.product_id = entity.entity_id', + [] + )->where( + 'stock.stock_status IN (?)', + [StockStatus::STATUS_IN_STOCK, StockStatus::STATUS_OUT_OF_STOCK] + ); + + return $select; + } +} diff --git a/Queue/Action/TypeStrategy/ConfigurableProductStrategy.php b/Queue/Action/TypeStrategy/ConfigurableProductStrategy.php index b543193..a3d289d 100644 --- a/Queue/Action/TypeStrategy/ConfigurableProductStrategy.php +++ b/Queue/Action/TypeStrategy/ConfigurableProductStrategy.php @@ -11,6 +11,7 @@ use Divante\PimcoreIntegration\Exception\InvalidDataStructureException; use Divante\PimcoreIntegration\Http\Response\Transformator\Data\PropertyInterface; use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Catalog\Model\Product; use Magento\ConfigurableProduct\Helper\Product\Options\Factory as OptionsFactory; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; use Magento\Eav\Model\Config; @@ -81,6 +82,34 @@ public function execute(ProductInterface $product): ProductInterface ); } + foreach ($attrCodes as $code) { + $attribute = $this->eavConfig->getAttribute(Product::ENTITY, $code); + $options = $attribute->getOptions(); + array_shift($options); + + $attributeValues = []; + foreach ($options as $option) { + $attributeValues[] = [ + 'label' => $option->getLabel(), + 'attribute_id' => $attribute->getId(), + 'value_index' => $option->getValue(), + ]; + } + + $configurableAttributesData[] = + [ + 'attribute_id' => $attribute->getId(), + 'code' => $attribute->getAttributeCode(), + 'label' => $attribute->getStoreLabel(), + 'position' => '0', + 'values' => $attributeValues, + ]; + } + + $configurableOptions = $this->optionsFactory->create($configurableAttributesData); + $extensionAttributes = $product->getExtensionAttributes(); + $extensionAttributes->setConfigurableProductOptions($configurableOptions); + $product->setExtensionAttributes($extensionAttributes); $product->setTypeId(Configurable::TYPE_CODE); return $product; diff --git a/Queue/Action/UpdateAssetAction.php b/Queue/Action/UpdateAssetAction.php index 63c0642..3defe68 100644 --- a/Queue/Action/UpdateAssetAction.php +++ b/Queue/Action/UpdateAssetAction.php @@ -149,11 +149,10 @@ public function execute(QueueInterface $queue, $data = null): ActionResultInterf */ private function prepareRequest(AssetQueueInterface $queue): RequestClientInterface { - $this->request->setUri($this->urlBuilder->build('asset')) + $this->request->setUri($this->urlBuilder->build('asset/id/' . $queue->getAssetId())) ->setEventPrefix('asset') ->setMethod('GET') - ->setStoreViewId($queue->getStoreViewId()) - ->setQueryData(['id' => $queue->getAssetId()]); + ->setStoreViewId($queue->getStoreViewId()); return $this->request; } diff --git a/etc/di.xml b/etc/di.xml index 1f20367..879e57b 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -1,7 +1,7 @@ - + +