Skip to content

Commit

Permalink
Merge pull request #4 from DivanteLtd/develop
Browse files Browse the repository at this point in the history
Update version to work with new Pimcore
  • Loading branch information
bartoszherba authored Feb 21, 2019
2 parents 9ed7617 + 05501e3 commit df2aeae
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* @package Divante\PimcoreIntegration
* @author Bartosz Herba <[email protected]>
* @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;
}
}
29 changes: 29 additions & 0 deletions Queue/Action/TypeStrategy/ConfigurableProductStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions Queue/Action/UpdateAssetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?><!--
/**
* @package Divante_PimcoreIntegration
* @author Mateusz Bukowski <mbukowski@divante.pl>
* @author Bartosz Herba <bherba@divante.pl>
* @copyright 2018 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/
Expand All @@ -28,6 +28,7 @@
<preference for="Divante\PimcoreIntegration\Api\AttributeSetRepositoryInterface" type="Divante\PimcoreIntegration\Model\Catalog\Product\Attribute\SetRepository"/>
<preference for="Divante\PimcoreIntegration\Http\Response\Transformator\Data\PropertyResolverInterface" type="Divante\PimcoreIntegration\Http\Response\Transformator\Data\PropertyResolver"/>
<preference for="Divante\PimcoreIntegration\Queue\Action\Product\GalleryImagesUpdaterInterface" type="Divante\PimcoreIntegration\Queue\Action\Product\GalleryImagesUpdater"/>
<preference for="Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Attribute\InStockOptionSelectBuilder" type="Divante\PimcoreIntegration\Plugin\Model\ResourceModel\Attribute\InStockOptionSelectBuilder" />
<type name="Divante\PimcoreIntegration\System\Config">
<arguments>
<argument name="scope" xsi:type="string">store</argument>
Expand Down
3 changes: 2 additions & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Divante_PimcoreIntegration" setup_version="1.0.4.13">
<module name="Divante_PimcoreIntegration" setup_version="1.0.5">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_ConfigurableProduct"/>
<module name="Magento_Cms"/>
</sequence>
</module>
Expand Down

0 comments on commit df2aeae

Please sign in to comment.