diff --git a/composer.json b/composer.json index ee77530d4f..d149426e10 100644 --- a/composer.json +++ b/composer.json @@ -107,7 +107,7 @@ "spryker/agent": "^1.0.0", "spryker/agent-gui": "^1.0.0", "spryker/alternative-products-rest-api": "^1.0.0", - "spryker/api": "^0.1.0", + "spryker/api": "^0.2.0", "spryker/api-query-builder": "^0.1.0", "spryker/application": "^3.0.0", "spryker/assertion": "^3.0.0", diff --git a/composer.lock b/composer.lock index 82f6b3a6fe..7611f41af9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f5d0917ecf3bdaf3d516d07e758fb68c", + "content-hash": "6cf886203ca7a4e2619e1e3c9d033e65", "packages": [ { "name": "aws/aws-sdk-php", - "version": "3.90.0", + "version": "3.90.1", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "c4e20a477f2ec8c880a9821f9e81641b8e3bb696" + "reference": "3262a84de9428766646223963c944b2be2cd09c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/c4e20a477f2ec8c880a9821f9e81641b8e3bb696", - "reference": "c4e20a477f2ec8c880a9821f9e81641b8e3bb696", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3262a84de9428766646223963c944b2be2cd09c0", + "reference": "3262a84de9428766646223963c944b2be2cd09c0", "shasum": "" }, "require": { @@ -86,7 +86,7 @@ "s3", "sdk" ], - "time": "2019-03-11T18:09:51+00:00" + "time": "2019-03-12T18:11:23+00:00" }, { "name": "codeitnowin/barcode", @@ -6978,16 +6978,16 @@ }, { "name": "spryker/api", - "version": "0.1.5", + "version": "0.2.0", "source": { "type": "git", "url": "https://github.com/spryker/api.git", - "reference": "dd74332739158176867c5087392cb331e1b6215e" + "reference": "9ed5a0e3978ba763e5884476bae13e8e3533de4e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spryker/api/zipball/dd74332739158176867c5087392cb331e1b6215e", - "reference": "dd74332739158176867c5087392cb331e1b6215e", + "url": "https://api.github.com/repos/spryker/api/zipball/9ed5a0e3978ba763e5884476bae13e8e3533de4e", + "reference": "9ed5a0e3978ba763e5884476bae13e8e3533de4e", "shasum": "" }, "require": { @@ -7024,38 +7024,33 @@ "proprietary" ], "description": "Api module", - "time": "2019-01-28T15:17:37+00:00" + "time": "2019-03-11T10:45:40+00:00" }, { "name": "spryker/api-query-builder", - "version": "0.1.1", + "version": "0.1.2", "source": { "type": "git", "url": "https://github.com/spryker/api-query-builder.git", - "reference": "a979f93ceaae09031cee3a9a2b9bd1acac115752" + "reference": "a8f9cf14a1ac60b197df697ac0b07474af68aad7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spryker/api-query-builder/zipball/a979f93ceaae09031cee3a9a2b9bd1acac115752", - "reference": "a979f93ceaae09031cee3a9a2b9bd1acac115752", + "url": "https://api.github.com/repos/spryker/api-query-builder/zipball/a8f9cf14a1ac60b197df697ac0b07474af68aad7", + "reference": "a8f9cf14a1ac60b197df697ac0b07474af68aad7", "shasum": "" }, "require": { "php": ">=7.1", - "spryker/api": "^0.1.0", + "spryker/api": "^0.1.0 || ^0.2.0", "spryker/kernel": "^3.0.0", "spryker/propel-orm": "^1.2.0", "spryker/propel-query-builder": "^0.3.0", "spryker/util-encoding": "^2.0.1" }, "require-dev": { - "spryker/assertion": "*", "spryker/code-sniffer": "*", - "spryker/config": "*", "spryker/product": "*", - "spryker/propel": "*", - "spryker/silex": "*", - "spryker/symfony": "^3.0.0", "spryker/testify": "*" }, "type": "library", @@ -7074,7 +7069,7 @@ "proprietary" ], "description": "ApiQueryBuilder module", - "time": "2018-08-13T10:09:37+00:00" + "time": "2019-03-11T12:00:44+00:00" }, { "name": "spryker/application", @@ -7210,11 +7205,19 @@ "Spryker": "src/" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-0": { + "Unit": "tests/" + } + }, + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "Assertion bundle", + "support": { + "source": "https://github.com/spryker/Assertion/tree/3.0.0" + }, "time": "2017-02-22T12:08:46+00:00" }, { @@ -8025,11 +8028,14 @@ "Spryker": "src/" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "Cache bundle", + "support": { + "source": "https://github.com/spryker/Cache/tree/3.1.0" + }, "time": "2017-04-10T13:13:21+00:00" }, { @@ -9033,11 +9039,14 @@ "Spryker": "src/" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "CategoryExporter module", + "support": { + "source": "https://github.com/spryker/CategoryExporter/tree/3.0.2" + }, "time": "2017-07-13T15:46:45+00:00" }, { @@ -11062,16 +11071,16 @@ }, { "name": "spryker/company-business-unit", - "version": "2.9.0", + "version": "2.9.1", "source": { "type": "git", "url": "https://github.com/spryker/company-business-unit.git", - "reference": "5c9d67033502ba4319a2e4c0a2d5000e92ae80c1" + "reference": "4aa26fec4d6edcf8615eb1ba52163815590ff5de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spryker/company-business-unit/zipball/5c9d67033502ba4319a2e4c0a2d5000e92ae80c1", - "reference": "5c9d67033502ba4319a2e4c0a2d5000e92ae80c1", + "url": "https://api.github.com/repos/spryker/company-business-unit/zipball/4aa26fec4d6edcf8615eb1ba52163815590ff5de", + "reference": "4aa26fec4d6edcf8615eb1ba52163815590ff5de", "shasum": "" }, "require": { @@ -11109,7 +11118,7 @@ "proprietary" ], "description": "CompanyBusinessUnit module", - "time": "2019-03-01T11:01:57+00:00" + "time": "2019-03-12T15:01:00+00:00" }, { "name": "spryker/company-business-unit-data-import", @@ -13140,21 +13149,22 @@ }, { "name": "spryker/customer-api", - "version": "0.1.3", + "version": "0.1.4", "source": { "type": "git", - "url": "https://github.com/spryker/CustomerApi.git", - "reference": "4394c0ea129e26096625a471d837928a7a5d0e9c" + "url": "https://github.com/spryker/customer-api.git", + "reference": "4ea45d833f81aa00ba1e61ea7379df80187a500b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spryker/CustomerApi/zipball/4394c0ea129e26096625a471d837928a7a5d0e9c", - "reference": "4394c0ea129e26096625a471d837928a7a5d0e9c", + "url": "https://api.github.com/repos/spryker/customer-api/zipball/4ea45d833f81aa00ba1e61ea7379df80187a500b", + "reference": "4ea45d833f81aa00ba1e61ea7379df80187a500b", "shasum": "" }, "require": { - "spryker/api": "^0.1", - "spryker/api-query-builder": "^0.1", + "php": ">=7.1", + "spryker/api": "^0.1.0 || ^0.2.0", + "spryker/api-query-builder": "^0.1.0", "spryker/customer": "^4.3.0 || ^5.0.0 || ^6.0.0 || ^7.0.0", "spryker/kernel": "^3.0.0", "spryker/propel-orm": "^1.2.0", @@ -13162,12 +13172,8 @@ "spryker/util-date-time": "^1.0.0" }, "require-dev": { - "spryker/application": "*", - "spryker/assertion": "*", "spryker/code-sniffer": "*", - "spryker/config": "*", "spryker/propel": "*", - "spryker/silex": "*", "spryker/testify": "*" }, "type": "library", @@ -13186,7 +13192,7 @@ "proprietary" ], "description": "CustomerApi module", - "time": "2017-11-10T15:08:30+00:00" + "time": "2019-03-11T12:00:44+00:00" }, { "name": "spryker/customer-catalog", @@ -14273,11 +14279,14 @@ "dev-master": "1.0.x-dev" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "Egulias module", + "support": { + "source": "https://github.com/spryker/Egulias/tree/1.0.0" + }, "time": "2017-11-09T13:55:22+00:00" }, { @@ -15318,11 +15327,19 @@ "Function": "tests/" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-0": { + "Unit": "tests/" + } + }, + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "Graph bundle", + "support": { + "source": "https://github.com/spryker/Graph/tree/3.0.0" + }, "time": "2017-02-22T12:08:46+00:00" }, { @@ -15348,11 +15365,14 @@ "dev-master": "2.0.x-dev" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "Graphviz module", + "support": { + "source": "https://github.com/spryker/Graphviz/tree/2.0.1" + }, "time": "2017-08-02T16:31:17+00:00" }, { @@ -15640,11 +15660,20 @@ "Spryker": "src/" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-0": { + "Functional": "tests/", + "Unit": "tests/" + } + }, + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "Invoice bundle", + "support": { + "source": "https://github.com/spryker/Invoice/tree/2.0.1" + }, "time": "2017-02-22T11:53:10+00:00" }, { @@ -19446,22 +19475,22 @@ }, { "name": "spryker/product-api", - "version": "0.1.2", + "version": "0.1.3", "source": { "type": "git", "url": "https://github.com/spryker/product-api.git", - "reference": "d4e91e3e0834c91b7d684fb0d0c03e2508f8bef0" + "reference": "a890b6bab2c9824de9ef25620013a96565269134" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spryker/product-api/zipball/d4e91e3e0834c91b7d684fb0d0c03e2508f8bef0", - "reference": "d4e91e3e0834c91b7d684fb0d0c03e2508f8bef0", + "url": "https://api.github.com/repos/spryker/product-api/zipball/a890b6bab2c9824de9ef25620013a96565269134", + "reference": "a890b6bab2c9824de9ef25620013a96565269134", "shasum": "" }, "require": { "php": ">=7.1", - "spryker/api": "^0.1", - "spryker/api-query-builder": "^0.1", + "spryker/api": "^0.1.0 || ^0.2.0", + "spryker/api-query-builder": "^0.1.0", "spryker/kernel": "^3.0.0", "spryker/product": "^5.0.0 || ^6.0.0", "spryker/propel-orm": "^1.2.0", @@ -19469,12 +19498,8 @@ "spryker/util-date-time": "^1.0.0" }, "require-dev": { - "spryker/application": "*", - "spryker/assertion": "*", "spryker/code-sniffer": "*", - "spryker/config": "*", "spryker/propel": "*", - "spryker/silex": "*", "spryker/testify": "*" }, "type": "library", @@ -19493,7 +19518,7 @@ "proprietary" ], "description": "ProductApi module", - "time": "2018-01-24T11:43:27+00:00" + "time": "2019-03-11T12:00:44+00:00" }, { "name": "spryker/product-attribute", @@ -24488,11 +24513,14 @@ "dev-master": "2.0.x-dev" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "Redis bundle", + "support": { + "source": "https://github.com/spryker/Redis/tree/2.0.1" + }, "time": "2017-04-26T15:15:36+00:00" }, { @@ -27743,11 +27771,19 @@ "Spryker\\": "src/Spryker/" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "SprykerTest\\": "tests/SprykerTest/" + } + }, + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "UtilDateTime module", + "support": { + "source": "https://github.com/spryker/UtilDateTime/tree/1.0.2" + }, "time": "2017-10-24T13:32:31+00:00" }, { @@ -27934,11 +27970,19 @@ "Spryker\\": "src/Spryker/" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "SprykerTest\\": "tests/SprykerTest/" + } + }, + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "UtilText module", + "support": { + "source": "https://github.com/spryker/UtilText/tree/master" + }, "time": "2017-10-24T13:32:31+00:00" }, { @@ -28015,11 +28059,19 @@ "Spryker\\": "src/Spryker/" } }, - "notification-url": "https://packagist.org/downloads/", + "autoload-dev": { + "psr-4": { + "SprykerTest\\": "tests/SprykerTest/" + } + }, + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "UtilValidate module", + "support": { + "source": "https://github.com/spryker/UtilValidate/tree/1.0.0" + }, "time": "2017-11-09T13:55:22+00:00" }, { @@ -28468,11 +28520,14 @@ "dev-master": "2.0.x-dev" } }, - "notification-url": "https://packagist.org/downloads/", + "notification-url": "https://code.foo.com/repo/private/downloads/", "license": [ "proprietary" ], "description": "Zend module", + "support": { + "source": "https://github.com/spryker/Zend/tree/2.1.0" + }, "time": "2017-08-02T16:31:17+00:00" }, { @@ -29466,7 +29521,7 @@ }, { "name": "Gert de Pagter", - "email": "backendtea@gmail.com" + "email": "BackEndTea@gmail.com" } ], "description": "Symfony polyfill for ctype functions", @@ -30669,16 +30724,16 @@ }, { "name": "twig/twig", - "version": "v1.37.1", + "version": "v1.38.2", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "66be9366c76cbf23e82e7171d47cbfa54a057a62" + "reference": "874adbd9222f928f6998732b25b01b41dff15b0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/66be9366c76cbf23e82e7171d47cbfa54a057a62", - "reference": "66be9366c76cbf23e82e7171d47cbfa54a057a62", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/874adbd9222f928f6998732b25b01b41dff15b0c", + "reference": "874adbd9222f928f6998732b25b01b41dff15b0c", "shasum": "" }, "require": { @@ -30693,7 +30748,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.37-dev" + "dev-master": "1.38-dev" } }, "autoload": { @@ -30731,7 +30786,7 @@ "keywords": [ "templating" ], - "time": "2019-01-14T14:59:29+00:00" + "time": "2019-03-12T18:45:24+00:00" }, { "name": "willdurand/negotiation", diff --git a/src/Pyz/Zed/DataImport/Business/DataImportBusinessFactory.php b/src/Pyz/Zed/DataImport/Business/DataImportBusinessFactory.php index 94401f130e..c72a23089a 100644 --- a/src/Pyz/Zed/DataImport/Business/DataImportBusinessFactory.php +++ b/src/Pyz/Zed/DataImport/Business/DataImportBusinessFactory.php @@ -384,10 +384,10 @@ public function createProductImageBulkPdoWriter(): DataSetWriterInterface public function createProductStockPropelWriter(): DataSetWriterInterface { return new ProductStockPropelDataSetWriter( - $this->getAvailabilityFacade(), $this->getProductBundleFacade(), $this->createProductRepository(), - $this->getStoreFacade() + $this->getStoreFacade(), + $this->getStockFacade() ); } @@ -789,14 +789,6 @@ protected function getStockFacade(): StockFacadeInterface return $this->getProvidedDependency(DataImportDependencyProvider::FACADE_STOCK); } - /** - * @return \Spryker\Zed\Availability\Business\AvailabilityFacadeInterface - */ - protected function getAvailabilityFacade() - { - return $this->getProvidedDependency(DataImportDependencyProvider::FACADE_AVAILABILITY); - } - /** * @return \Spryker\Zed\ProductBundle\Business\ProductBundleFacadeInterface */ diff --git a/src/Pyz/Zed/DataImport/Business/Model/ProductStock/Writer/ProductStockPropelDataSetWriter.php b/src/Pyz/Zed/DataImport/Business/Model/ProductStock/Writer/ProductStockPropelDataSetWriter.php index 30785860bc..d7f619e0b2 100644 --- a/src/Pyz/Zed/DataImport/Business/Model/ProductStock/Writer/ProductStockPropelDataSetWriter.php +++ b/src/Pyz/Zed/DataImport/Business/Model/ProductStock/Writer/ProductStockPropelDataSetWriter.php @@ -7,23 +7,41 @@ namespace Pyz\Zed\DataImport\Business\Model\ProductStock\Writer; +use Generated\Shared\Transfer\StoreTransfer; use Orm\Zed\Availability\Persistence\Map\SpyAvailabilityAbstractTableMap; +use Orm\Zed\Availability\Persistence\Map\SpyAvailabilityTableMap; +use Orm\Zed\Availability\Persistence\SpyAvailabilityAbstract; use Orm\Zed\Availability\Persistence\SpyAvailabilityAbstractQuery; +use Orm\Zed\Availability\Persistence\SpyAvailabilityQuery; +use Orm\Zed\Oms\Persistence\Map\SpyOmsProductReservationTableMap; +use Orm\Zed\Oms\Persistence\SpyOmsProductReservationQuery; +use Orm\Zed\Oms\Persistence\SpyOmsProductReservationStoreQuery; +use Orm\Zed\Stock\Persistence\Map\SpyStockProductTableMap; use Orm\Zed\Stock\Persistence\SpyStock; use Orm\Zed\Stock\Persistence\SpyStockProductQuery; use Orm\Zed\Stock\Persistence\SpyStockQuery; use Pyz\Zed\DataImport\Business\Model\Product\Repository\ProductRepositoryInterface; use Pyz\Zed\DataImport\Business\Model\ProductStock\ProductStockHydratorStep; -use Spryker\Zed\Availability\Business\AvailabilityFacadeInterface; use Spryker\Zed\Availability\Dependency\AvailabilityEvents; use Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface; use Spryker\Zed\DataImport\Business\Model\DataSet\DataSetWriterInterface; use Spryker\Zed\DataImport\Business\Model\Publisher\DataImporterPublisher; use Spryker\Zed\ProductBundle\Business\ProductBundleFacadeInterface; +use Spryker\Zed\PropelOrm\Business\Runtime\ActiveQuery\Criteria; +use Spryker\Zed\Stock\Business\StockFacadeInterface; use Spryker\Zed\Store\Business\StoreFacadeInterface; class ProductStockPropelDataSetWriter implements DataSetWriterInterface { + protected const KEY_AVAILABILITY_SKU = 'KEY_AVAILABILITY_SKU'; + protected const KEY_AVAILABILITY_QUANTITY = 'KEY_AVAILABILITY_QUANTITY'; + protected const KEY_AVAILABILITY_ID_STORE = 'KEY_AVAILABILITY_ID_STORE'; + protected const KEY_AVAILABILITY_IS_NEVER_OUT_OF_STOCK = 'KEY_AVAILABILITY_IS_NEVER_OUT_OF_STOCK'; + protected const KEY_AVAILABILITY_ID_AVAILABILITY_ABSTRACT = 'KEY_AVAILABILITY_ID_AVAILABILITY_ABSTRACT'; + + protected const COL_AVAILABILITY_TOTAL_QUANTITY = 'availabilityTotalQuantity'; + protected const COL_STOCK_PRODUCT_TOTAL_QUANTITY = 'stockProductTotalQuantity'; + /** * @var string[] */ @@ -34,11 +52,6 @@ class ProductStockPropelDataSetWriter implements DataSetWriterInterface */ protected $productRepository; - /** - * @var \Spryker\Zed\Availability\Business\AvailabilityFacadeInterface - */ - protected $availabilityFacade; - /** * @var \Spryker\Zed\ProductBundle\Business\ProductBundleFacadeInterface */ @@ -50,21 +63,26 @@ class ProductStockPropelDataSetWriter implements DataSetWriterInterface protected $storeFacade; /** - * @param \Spryker\Zed\Availability\Business\AvailabilityFacadeInterface $availabilityFacade + * @var \Spryker\Zed\Stock\Business\StockFacadeInterface + */ + protected $stockFacade; + + /** * @param \Spryker\Zed\ProductBundle\Business\ProductBundleFacadeInterface $productBundleFacade * @param \Pyz\Zed\DataImport\Business\Model\Product\Repository\ProductRepositoryInterface $productRepository * @param \Spryker\Zed\Store\Business\StoreFacadeInterface $storeFacade + * @param \Spryker\Zed\Stock\Business\StockFacadeInterface $stockFacade */ public function __construct( - AvailabilityFacadeInterface $availabilityFacade, ProductBundleFacadeInterface $productBundleFacade, ProductRepositoryInterface $productRepository, - StoreFacadeInterface $storeFacade + StoreFacadeInterface $storeFacade, + StockFacadeInterface $stockFacade ) { - $this->availabilityFacade = $availabilityFacade; $this->productBundleFacade = $productBundleFacade; $this->productRepository = $productRepository; $this->storeFacade = $storeFacade; + $this->stockFacade = $stockFacade; } /** @@ -77,8 +95,7 @@ public function write(DataSetInterface $dataSet): void $stockEntity = $this->createOrUpdateStock($dataSet); $this->createOrUpdateProductStock($dataSet, $stockEntity); $this->collectProductAbstractSku($dataSet); - - $this->availabilityFacade->updateAvailability($dataSet[ProductStockHydratorStep::KEY_CONCRETE_SKU]); + $this->updateAvailability($dataSet); if ($dataSet[ProductStockHydratorStep::KEY_IS_BUNDLE]) { $this->productBundleFacade->updateBundleAvailability($dataSet[ProductStockHydratorStep::KEY_CONCRETE_SKU]); @@ -123,9 +140,9 @@ protected function createOrUpdateStock(DataSetInterface $dataSet) protected function createOrUpdateProductStock(DataSetInterface $dataSet, SpyStock $stockEntity): void { $stockProductEntityTransfer = $dataSet[ProductStockHydratorStep::STOCK_PRODUCT_ENTITY_TRANSFER]; - $idProduct = $this->productRepository->getIdProductByConcreteSku($dataSet[ProductStockHydratorStep::KEY_CONCRETE_SKU]); + $idProductConcrete = $this->productRepository->getIdProductByConcreteSku($dataSet[ProductStockHydratorStep::KEY_CONCRETE_SKU]); $stockProductEntity = SpyStockProductQuery::create() - ->filterByFkProduct($idProduct) + ->filterByFkProduct($idProductConcrete) ->filterByFkStock($stockEntity->getIdStock()) ->findOneOrCreate(); $stockProductEntity->fromArray($stockProductEntityTransfer->modifiedToArray()); @@ -190,4 +207,253 @@ protected function getStoreIds(): array return $storeIds; } + + /** + * @param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet + * + * @return void + */ + protected function updateAvailability(DataSetInterface $dataSet): void + { + $storeTransfer = $this->storeFacade->getCurrentStore(); + + $this->updateAvailabilityForStore($dataSet, $storeTransfer); + + foreach ($storeTransfer->getStoresWithSharedPersistence() as $storeName) { + $storeTransfer = $this->storeFacade->getStoreByName($storeName); + $this->updateAvailabilityForStore($dataSet, $storeTransfer); + } + } + + /** + * @param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet + * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer + * + * @return void + */ + protected function updateAvailabilityForStore(DataSetInterface $dataSet, StoreTransfer $storeTransfer): void + { + $concreteSku = $dataSet[ProductStockHydratorStep::KEY_CONCRETE_SKU]; + $abstractSku = $this->productRepository->getAbstractSkuByConcreteSku($concreteSku); + $idStore = $this->getIdStore($storeTransfer); + + $stockProductQuantity = $this->getStockProductQuantityForStore($concreteSku, $storeTransfer); + $availabilityAbstractEntity = $this->getAvailabilityAbstract($abstractSku, $idStore); + $this->persistAvailabilityData([ + static::KEY_AVAILABILITY_SKU => $concreteSku, + static::KEY_AVAILABILITY_QUANTITY => $stockProductQuantity, + static::KEY_AVAILABILITY_ID_AVAILABILITY_ABSTRACT => $availabilityAbstractEntity->getIdAvailabilityAbstract(), + static::KEY_AVAILABILITY_ID_STORE => $idStore, + static::KEY_AVAILABILITY_IS_NEVER_OUT_OF_STOCK => $dataSet[ProductStockHydratorStep::KEY_IS_NEVER_OUT_OF_STOCK], + ]); + + $this->updateAbstractAvailabilityQuantity($availabilityAbstractEntity, $idStore); + } + + /** + * @param string $concreteSku + * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer + * + * @return int + */ + protected function getStockProductQuantityForStore(string $concreteSku, StoreTransfer $storeTransfer): int + { + $physicalItems = $this->calculateProductStockForSkuAndStore($concreteSku, $storeTransfer); + $reservedItems = $this->getReservationQuantityForStore($concreteSku, $storeTransfer); + $stockProductQuantity = $physicalItems - $reservedItems; + + return $stockProductQuantity > 0 ? $stockProductQuantity : 0; + } + + /** + * @param string $concreteSku + * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer + * + * @return int + */ + protected function calculateProductStockForSkuAndStore(string $concreteSku, StoreTransfer $storeTransfer): int + { + $idProductConcrete = $this->productRepository->getIdProductByConcreteSku($concreteSku); + $stockNames = $this->getStoreWarehouses($storeTransfer->getName()); + + return $this->getStockProductQuantityByIdProductAndStockNames($idProductConcrete, $stockNames); + } + + /** + * @param string $storeName + * + * @return array + */ + protected function getStoreWarehouses(string $storeName): array + { + return $this->stockFacade->getStoreToWarehouseMapping()[$storeName] ?? []; + } + + /** + * @param int $idProductConcrete + * @param string[] $stockNames + * + * @return int + */ + protected function getStockProductQuantityByIdProductAndStockNames(int $idProductConcrete, array $stockNames): int + { + $stockProductTotalQuantity = SpyStockProductQuery::create() + ->filterByFkProduct($idProductConcrete) + ->useStockQuery() + ->filterByName($stockNames, Criteria::IN) + ->endUse() + ->withColumn(sprintf('SUM(%s)', SpyStockProductTableMap::COL_QUANTITY), static::COL_STOCK_PRODUCT_TOTAL_QUANTITY) + ->select([static::COL_STOCK_PRODUCT_TOTAL_QUANTITY]) + ->findOne(); + + return (int)$stockProductTotalQuantity; + } + + /** + * @param string $sku + * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer + * + * @return int + */ + protected function getReservationQuantityForStore(string $sku, StoreTransfer $storeTransfer): int + { + $idStore = $this->getIdStore($storeTransfer); + + $reservations = SpyOmsProductReservationQuery::create() + ->filterBySku($sku) + ->filterByFkStore($idStore) + ->select([ + SpyOmsProductReservationTableMap::COL_RESERVATION_QUANTITY, + ]) + ->find() + ->toArray(); + + $reservationQuantity = 0; + + foreach ($reservations as $reservation) { + $reservationQuantity += $reservation[SpyOmsProductReservationTableMap::COL_RESERVATION_QUANTITY]; + } + + $reservationQuantity += $this->getReservationsFromOtherStores($sku, $storeTransfer); + + return $reservationQuantity; + } + + /** + * @param string $sku + * @param \Generated\Shared\Transfer\StoreTransfer $currentStoreTransfer + * + * @return int + */ + protected function getReservationsFromOtherStores(string $sku, StoreTransfer $currentStoreTransfer): int + { + $reservationQuantity = 0; + $reservationStores = SpyOmsProductReservationStoreQuery::create() + ->filterBySku($sku) + ->find(); + + foreach ($reservationStores as $omsProductReservationStoreEntity) { + if ($omsProductReservationStoreEntity->getStore() === $currentStoreTransfer->getName()) { + continue; + } + $reservationQuantity += $omsProductReservationStoreEntity->getReservationQuantity(); + } + + return $reservationQuantity; + } + + /** + * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer + * + * @return int + */ + protected function getIdStore(StoreTransfer $storeTransfer): int + { + if (!$storeTransfer->getIdStore()) { + $idStore = $this->storeFacade + ->getStoreByName($storeTransfer->getName()) + ->getIdStore(); + $storeTransfer->setIdStore($idStore); + } + + return $storeTransfer->getIdStore(); + } + + /** + * @param array $availabilityData + * + * @return void + */ + protected function persistAvailabilityData(array $availabilityData): void + { + $spyAvailabilityEntity = SpyAvailabilityQuery::create() + ->filterByFkStore($availabilityData[static::KEY_AVAILABILITY_ID_STORE]) + ->filterBySku($availabilityData[static::KEY_AVAILABILITY_SKU]) + ->findOneOrCreate(); + + $spyAvailabilityEntity->setFkAvailabilityAbstract($availabilityData[static::KEY_AVAILABILITY_ID_AVAILABILITY_ABSTRACT]); + $spyAvailabilityEntity->setQuantity($availabilityData[static::KEY_AVAILABILITY_QUANTITY]); + $spyAvailabilityEntity->setIsNeverOutOfStock($availabilityData[static::KEY_AVAILABILITY_IS_NEVER_OUT_OF_STOCK]); + + $spyAvailabilityEntity->save(); + } + + /** + * @param string $abstractSku + * @param int $idStore + * + * @return \Orm\Zed\Availability\Persistence\SpyAvailabilityAbstract + */ + protected function getAvailabilityAbstract(string $abstractSku, int $idStore): SpyAvailabilityAbstract + { + $availabilityAbstractEntity = SpyAvailabilityAbstractQuery::create() + ->filterByAbstractSku($abstractSku) + ->filterByFkStore($idStore) + ->findOne(); + + if ($availabilityAbstractEntity !== null) { + return $availabilityAbstractEntity; + } + + return $this->createAvailabilityAbstract($abstractSku, $idStore); + } + + /** + * @param string $abstractSku + * @param int $idStore + * + * @return \Orm\Zed\Availability\Persistence\SpyAvailabilityAbstract + */ + protected function createAvailabilityAbstract(string $abstractSku, int $idStore): SpyAvailabilityAbstract + { + $availableAbstractEntity = (new SpyAvailabilityAbstract()) + ->setAbstractSku($abstractSku) + ->setFkStore($idStore); + + $availableAbstractEntity->save(); + + return $availableAbstractEntity; + } + + /** + * @param \Orm\Zed\Availability\Persistence\SpyAvailabilityAbstract $availabilityAbstractEntity + * @param int $idStore + * + * @return \Orm\Zed\Availability\Persistence\SpyAvailabilityAbstract + */ + protected function updateAbstractAvailabilityQuantity(SpyAvailabilityAbstract $availabilityAbstractEntity, int $idStore): SpyAvailabilityAbstract + { + $sumQuantity = SpyAvailabilityQuery::create() + ->filterByFkAvailabilityAbstract($availabilityAbstractEntity->getIdAvailabilityAbstract()) + ->filterByFkStore($idStore) + ->withColumn(sprintf('SUM(%s)', SpyAvailabilityTableMap::COL_QUANTITY), static::COL_AVAILABILITY_TOTAL_QUANTITY) + ->select([static::COL_AVAILABILITY_TOTAL_QUANTITY]) + ->findOne(); + + $availabilityAbstractEntity->setFkStore($idStore); + $availabilityAbstractEntity->setQuantity((int)$sumQuantity); + $availabilityAbstractEntity->save(); + + return $availabilityAbstractEntity; + } } diff --git a/src/Pyz/Zed/DataImport/DataImportDependencyProvider.php b/src/Pyz/Zed/DataImport/DataImportDependencyProvider.php index d88c9b0d64..398bf47612 100644 --- a/src/Pyz/Zed/DataImport/DataImportDependencyProvider.php +++ b/src/Pyz/Zed/DataImport/DataImportDependencyProvider.php @@ -54,7 +54,6 @@ class DataImportDependencyProvider extends SprykerDataImportDependencyProvider { - public const FACADE_AVAILABILITY = 'availability facade'; public const FACADE_CATEGORY = 'category facade'; public const FACADE_STORE = 'store facade'; public const FACADE_CURRENCY = 'currency facade'; @@ -75,7 +74,6 @@ public function provideBusinessLayerDependencies(Container $container) { $container = parent::provideBusinessLayerDependencies($container); - $container = $this->addAvailabilityFacade($container); $container = $this->addStockFacade($container); $container = $this->addCurrencyFacade($container); $container = $this->addStoreFacade($container); @@ -117,20 +115,6 @@ protected function addStoreFacade(Container $container) return $container; } - /** - * @param \Spryker\Zed\Kernel\Container $container - * - * @return \Spryker\Zed\Kernel\Container - */ - protected function addAvailabilityFacade(Container $container) - { - $container[static::FACADE_AVAILABILITY] = function (Container $container) { - return $container->getLocator()->availability()->facade(); - }; - - return $container; - } - /** * @param \Spryker\Zed\Kernel\Container $container * diff --git a/tests/PyzTest/Zed/DataImport/Business/Model/ProductStock/AbstractProductStockWriterTest.php b/tests/PyzTest/Zed/DataImport/Business/Model/ProductStock/AbstractProductStockWriterTest.php index db0dc71e90..c962700d64 100644 --- a/tests/PyzTest/Zed/DataImport/Business/Model/ProductStock/AbstractProductStockWriterTest.php +++ b/tests/PyzTest/Zed/DataImport/Business/Model/ProductStock/AbstractProductStockWriterTest.php @@ -56,12 +56,13 @@ protected function createDataSets(array $productSkus, array $warehouses): array $dataSet[ProductStockHydratorStep::KEY_IS_BUNDLE] = 0; $dataSet[ProductStockHydratorStep::KEY_CONCRETE_SKU] = $sku; + $dataSet[ProductStockHydratorStep::KEY_IS_NEVER_OUT_OF_STOCK] = 0; $dataSet[ProductStockHydratorStep::STOCK_ENTITY_TRANSFER] = (new SpyStockEntityTransfer()) ->setName($warehouses[$index] ?? $warehouses[0]); $dataSet[ProductStockHydratorStep::STOCK_PRODUCT_ENTITY_TRANSFER] = (new SpyStockProductEntityTransfer()) ->setQuantity(static::WAREHOUSES_QTY[$index]) - ->setIsNeverOutOfStock(0); + ->setIsNeverOutOfStock($dataSet[ProductStockHydratorStep::KEY_IS_NEVER_OUT_OF_STOCK]); $result[$sku] = $dataSet; }