diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/checkboxes/tree.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/checkboxes/tree.phtml index 25aaaea0ffe2b98a6e46a7e133c53b743603530e..284f241b3ba54f834f2d5057bf1a67458645aa03 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/checkboxes/tree.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/checkboxes/tree.phtml @@ -10,7 +10,7 @@ <?php $_divId = 'tree-div_' . time() ?> <div id="<?php /* @escapeNotVerified */ echo $_divId ?>" class="tree"></div> -<script id="ie-deferred-loader" defer="defer" src=""></script> +<script id="ie-deferred-loader" defer="defer" src="//:"></script> <script> require([ 'jquery', diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/widget/tree.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/widget/tree.phtml index 9e303fe921dfd328453c0f736a107fa4be70e6fa..ae65d2658978a3f2e74dc04278ce9d803dda471a 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/widget/tree.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/category/widget/tree.phtml @@ -11,7 +11,7 @@ <?php $_divId = 'tree' . $block->getId() ?> <div id="<?php /* @escapeNotVerified */ echo $_divId ?>" class="tree"></div> <!--[if IE]> -<script id="ie-deferred-loader" defer="defer" src=""></script> +<script id="ie-deferred-loader" defer="defer" src="//:"></script> <![endif]--> <script> require(['jquery', "prototype", "extjs/ext-tree-checkbox"], function(jQuery){ diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/set/main.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/set/main.phtml index f1bba6cc3c07ca0603e149afc8f0ad24b342a467..b3a7002ef417ecb3cc14006aa34b6844a32d8a67 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/set/main.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/set/main.phtml @@ -38,7 +38,7 @@ <span class="title"><?php /* @escapeNotVerified */ echo __('Unassigned Attributes') ?></span> </div> <div id="tree-div2" class="attribute-set-tree"></div> - <script id="ie-deferred-loader" defer="defer" src=""></script> + <script id="ie-deferred-loader" defer="defer" src="//:"></script> <script> define("tree-panel", [ diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product.php b/app/code/Magento/CatalogImportExport/Model/Import/Product.php index 57498355c51a6f38130c39b8f7c88c3ba0a72873..2005eb49493e2ddc98b8f8036db075f3431e7b7d 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product.php @@ -1963,7 +1963,7 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity $productIdsToReindex[] = $row['product_id']; $row['website_id'] = $this->stockConfiguration->getDefaultScopeId(); - $row['stock_id'] = $this->stockRegistry->getStock()->getStockId(); + $row['stock_id'] = $this->stockRegistry->getStock($row['website_id'])->getStockId(); $stockItemDo = $this->stockRegistry->getStockItem($row['product_id'], $row['website_id']); $existStockData = $stockItemDo->getData(); diff --git a/app/code/Magento/CatalogInventory/Api/StockRegistryInterface.php b/app/code/Magento/CatalogInventory/Api/StockRegistryInterface.php index 27b45dc6771632f08a2f8aa62619d6324bcf7d02..2566aff49b0dc9cea7412906f8096ea9df7d48f6 100644 --- a/app/code/Magento/CatalogInventory/Api/StockRegistryInterface.php +++ b/app/code/Magento/CatalogInventory/Api/StockRegistryInterface.php @@ -12,10 +12,10 @@ namespace Magento\CatalogInventory\Api; interface StockRegistryInterface { /** - * @param int|null $stockId + * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockInterface */ - public function getStock($stockId = null); + public function getStock($scopeId = null); /** * @param int $productId diff --git a/app/code/Magento/CatalogInventory/Api/StockStatusCriteriaInterface.php b/app/code/Magento/CatalogInventory/Api/StockStatusCriteriaInterface.php index 44d3c1be11fab1f18b79bb0cf269198688c54eee..bb3d101e97f9f830c81941e0cfc0670e79ad6f49 100644 --- a/app/code/Magento/CatalogInventory/Api/StockStatusCriteriaInterface.php +++ b/app/code/Magento/CatalogInventory/Api/StockStatusCriteriaInterface.php @@ -15,7 +15,7 @@ interface StockStatusCriteriaInterface extends \Magento\Framework\Api\CriteriaIn * Add Criteria object * * @param \Magento\CatalogInventory\Api\StockStatusCriteriaInterface $criteria - * @return void + * @return bool */ public function addCriteria(\Magento\CatalogInventory\Api\StockStatusCriteriaInterface $criteria); @@ -23,7 +23,7 @@ interface StockStatusCriteriaInterface extends \Magento\Framework\Api\CriteriaIn * Filter by scope(s) * * @param int $scope - * @return void + * @return bool */ public function setScopeFilter($scope); @@ -31,7 +31,7 @@ interface StockStatusCriteriaInterface extends \Magento\Framework\Api\CriteriaIn * Add product(s) filter * * @param int $products - * @return void + * @return bool */ public function setProductsFilter($products); @@ -39,7 +39,7 @@ interface StockStatusCriteriaInterface extends \Magento\Framework\Api\CriteriaIn * Add filter by quantity * * @param float $qty - * @return void + * @return bool */ public function setQtyFilter($qty); } diff --git a/app/code/Magento/CatalogInventory/Helper/Stock.php b/app/code/Magento/CatalogInventory/Helper/Stock.php index 4706a60bf5250a18f4ebcfb7dd10efc9cf3fe8ed..8a227f53ebc1fce93a93a809ab5a0c1e887c06c4 100644 --- a/app/code/Magento/CatalogInventory/Helper/Stock.php +++ b/app/code/Magento/CatalogInventory/Helper/Stock.php @@ -6,7 +6,6 @@ namespace Magento\CatalogInventory\Helper; use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface; -use Magento\CatalogInventory\Model\Spi\StockResolverInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\CatalogInventory\Model\ResourceModel\Stock\StatusFactory; @@ -48,45 +47,36 @@ class Stock */ private $stockRegistryProvider; - /** - * @var StockResolverInterface - */ - protected $stockResolver; - /** * @param StoreManagerInterface $storeManager * @param ScopeConfigInterface $scopeConfig * @param StatusFactory $stockStatusFactory * @param StockRegistryProviderInterface $stockRegistryProvider - * @param StockResolverInterface $stockResolver */ public function __construct( StoreManagerInterface $storeManager, ScopeConfigInterface $scopeConfig, StatusFactory $stockStatusFactory, - StockRegistryProviderInterface $stockRegistryProvider, - StockResolverInterface $stockResolver + StockRegistryProviderInterface $stockRegistryProvider ) { $this->storeManager = $storeManager; $this->scopeConfig = $scopeConfig; $this->stockStatusFactory = $stockStatusFactory; $this->stockRegistryProvider = $stockRegistryProvider; - $this->stockResolver = $stockResolver; } /** * Assign stock status information to product * * @param Product $product - * @param int $stockStatus + * @param int $status * @return void */ - public function assignStatusToProduct(Product $product, $stockStatus = null) + public function assignStatusToProduct(Product $product, $status = null) { - if ($stockStatus === null) { - $productId = $product->getId(); - $stockId = $this->stockResolver->getStockId($productId, $product->getStore()->getWebsiteId()); - $stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $stockId); + if ($status === null) { + $websiteId = $product->getStore()->getWebsiteId(); + $stockStatus = $this->stockRegistryProvider->getStockStatus($product->getId(), $websiteId); $status = $stockStatus->getStockStatus(); } $product->setIsSalable($status); @@ -103,8 +93,7 @@ class Stock $websiteId = $this->storeManager->getStore($productCollection->getStoreId())->getWebsiteId(); foreach ($productCollection as $product) { $productId = $product->getId(); - $stockId = $this->stockResolver->getStockId($productId, $websiteId); - $stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $stockId); + $stockStatus = $this->stockRegistryProvider->getStockStatus($productId, $websiteId); $status = $stockStatus->getStockStatus(); $product->setIsSalable($status); } diff --git a/app/code/Magento/CatalogInventory/Model/Spi/StockRegistryProviderInterface.php b/app/code/Magento/CatalogInventory/Model/Spi/StockRegistryProviderInterface.php index a08aa33533301bd12c4c285da368de9a9a4492ec..8fb68a2c997be868f117803c18c292f74f2e4076 100644 --- a/app/code/Magento/CatalogInventory/Model/Spi/StockRegistryProviderInterface.php +++ b/app/code/Magento/CatalogInventory/Model/Spi/StockRegistryProviderInterface.php @@ -11,22 +11,22 @@ namespace Magento\CatalogInventory\Model\Spi; interface StockRegistryProviderInterface { /** - * @param int|null $stockId + * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockInterface */ - public function getStock($stockId); + public function getStock($scopeId); /** * @param int $productId - * @param int $stockId + * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockItemInterface */ - public function getStockItem($productId, $stockId); + public function getStockItem($productId, $scopeId); /** * @param int $productId - * @param int $stockId + * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockStatusInterface */ - public function getStockStatus($productId, $stockId); + public function getStockStatus($productId, $scopeId); } diff --git a/app/code/Magento/CatalogInventory/Model/Spi/StockResolverInterface.php b/app/code/Magento/CatalogInventory/Model/Spi/StockResolverInterface.php deleted file mode 100644 index b4f9df8f079da74b7d5ad09a0ccdd675fbcc8978..0000000000000000000000000000000000000000 --- a/app/code/Magento/CatalogInventory/Model/Spi/StockResolverInterface.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\CatalogInventory\Model\Spi; - -/** - * Interface StockResolverInterface - */ -interface StockResolverInterface -{ - /** - * @param int $productId - * @param int $websiteId - * @return int - */ - public function getStockId($productId, $websiteId); -} diff --git a/app/code/Magento/CatalogInventory/Model/Stock/Item.php b/app/code/Magento/CatalogInventory/Model/Stock/Item.php index b97977fd3c013e006c53232b490aedd7f7f857cc..3c4c7bfdf143f7ff892af8d03207e07c8dd90f06 100644 --- a/app/code/Magento/CatalogInventory/Model/Stock/Item.php +++ b/app/code/Magento/CatalogInventory/Model/Stock/Item.php @@ -177,7 +177,7 @@ class Item extends AbstractExtensibleModel implements StockItemInterface { $stockId = $this->getData(static::STOCK_ID); if ($stockId === null) { - $stockId = $this->stockRegistry->getStock()->getStockId(); + $stockId = $this->stockRegistry->getStock($this->getWebsiteId())->getStockId(); } return (int) $stockId; } diff --git a/app/code/Magento/CatalogInventory/Model/StockIndex.php b/app/code/Magento/CatalogInventory/Model/StockIndex.php index d961f52ff519f1eaf604207deb5e6bc287396565..4c6f6521c97949980222f9ff310f418a13ba247f 100644 --- a/app/code/Magento/CatalogInventory/Model/StockIndex.php +++ b/app/code/Magento/CatalogInventory/Model/StockIndex.php @@ -13,7 +13,6 @@ use Magento\Catalog\Model\Product\Website as ProductWebsite; use Magento\Catalog\Model\ProductFactory; use Magento\CatalogInventory\Api\StockIndexInterface; use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface; -use Magento\CatalogInventory\Model\Spi\StockResolverInterface; use Magento\Catalog\Api\ProductRepositoryInterface; /** @@ -56,31 +55,22 @@ class StockIndex implements StockIndexInterface */ protected $productTypes = []; - - /** - * @var StockResolverInterface - */ - protected $stockResolver; - /** * @param StockRegistryProviderInterface $stockRegistryProvider * @param ProductRepositoryInterface $productRepository * @param ProductWebsite $productWebsite * @param ProductType $productType - * @param StockResolverInterface $stockResolver */ public function __construct( StockRegistryProviderInterface $stockRegistryProvider, ProductRepositoryInterface $productRepository, ProductWebsite $productWebsite, - ProductType $productType, - StockResolverInterface $stockResolver + ProductType $productType ) { $this->stockRegistryProvider = $stockRegistryProvider; $this->productRepository = $productRepository; $this->productWebsite = $productWebsite; $this->productType = $productType; - $this->stockResolver = $stockResolver; } /** @@ -122,8 +112,7 @@ class StockIndex implements StockIndexInterface */ public function updateProductStockStatus($productId, $websiteId) { - $stockId = $this->stockResolver->getStockId($productId, $websiteId); - $item = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $item = $this->stockRegistryProvider->getStockItem($productId, $websiteId); $status = \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK; $qty = 0; @@ -242,8 +231,7 @@ class StockIndex implements StockIndexInterface } foreach ($parentIds as $parentId) { - $stockId = $this->stockResolver->getStockId($productId, $websiteId); - $item = $this->stockRegistryProvider->getStockItem($parentId, $stockId); + $item = $this->stockRegistryProvider->getStockItem($parentId, $websiteId); $status = \Magento\CatalogInventory\Model\Stock\Status::STATUS_IN_STOCK; $qty = 0; if ($item->getItemId()) { diff --git a/app/code/Magento/CatalogInventory/Model/StockManagement.php b/app/code/Magento/CatalogInventory/Model/StockManagement.php index 7b08d2a757ebcdd98eed33dd94e87d0b1496eb97..9415c464c18c1e4b9a0bb0a41d3e1cc587b0bfed 100644 --- a/app/code/Magento/CatalogInventory/Model/StockManagement.php +++ b/app/code/Magento/CatalogInventory/Model/StockManagement.php @@ -10,7 +10,6 @@ use Magento\CatalogInventory\Api\StockConfigurationInterface; use Magento\CatalogInventory\Api\StockManagementInterface; use Magento\CatalogInventory\Model\ResourceModel\QtyCounterInterface; use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface; -use Magento\CatalogInventory\Model\Spi\StockResolverInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\CatalogInventory\Model\ResourceModel\Stock as ResourceStock; @@ -49,11 +48,6 @@ class StockManagement implements StockManagementInterface */ private $qtyCounter; - /** - * @var StockResolverInterface - */ - protected $stockResolver; - /** * @param ResourceStock $stockResource * @param StockRegistryProviderInterface $stockRegistryProvider @@ -61,7 +55,6 @@ class StockManagement implements StockManagementInterface * @param StockConfigurationInterface $stockConfiguration * @param ProductRepositoryInterface $productRepository * @param QtyCounterInterface $qtyCounter - * @param StockResolverInterface $stockResolver */ public function __construct( ResourceStock $stockResource, @@ -69,8 +62,7 @@ class StockManagement implements StockManagementInterface StockState $stockState, StockConfigurationInterface $stockConfiguration, ProductRepositoryInterface $productRepository, - QtyCounterInterface $qtyCounter, - StockResolverInterface $stockResolver + QtyCounterInterface $qtyCounter ) { $this->stockRegistryProvider = $stockRegistryProvider; $this->stockState = $stockState; @@ -78,7 +70,6 @@ class StockManagement implements StockManagementInterface $this->productRepository = $productRepository; $this->qtyCounter = $qtyCounter; $this->resource = $stockResource; - $this->stockResolver = $stockResolver; } /** @@ -93,9 +84,9 @@ class StockManagement implements StockManagementInterface */ public function registerProductsSale($items, $websiteId = null) { - if (!$websiteId) { - $websiteId = $this->stockConfiguration->getDefaultScopeId(); - } + //if (!$websiteId) { + $websiteId = $this->stockConfiguration->getDefaultScopeId(); + //} $this->getResource()->beginTransaction(); $lockedItems = $this->getResource()->lockProductsStock(array_keys($items), $websiteId); $fullSaveItems = $registeredItems = []; @@ -103,8 +94,7 @@ class StockManagement implements StockManagementInterface $productId = $lockedItemRecord['product_id']; /** @var StockItemInterface $stockItem */ $orderedQty = $items[$productId]; - $stockId = $this->stockResolver->getStockId($productId, $websiteId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId); $canSubtractQty = $stockItem->getItemId() && $this->canSubtractQty($stockItem); if (!$canSubtractQty || !$this->stockConfiguration->isQty($lockedItemRecord['type_id'])) { continue; @@ -142,9 +132,9 @@ class StockManagement implements StockManagementInterface */ public function revertProductsSale($items, $websiteId = null) { - if (!$websiteId) { - $websiteId = $this->stockConfiguration->getDefaultScopeId(); - } + //if (!$websiteId) { + $websiteId = $this->stockConfiguration->getDefaultScopeId(); + //} $this->qtyCounter->correctItemsQty($items, $websiteId, '+'); return true; } @@ -159,11 +149,10 @@ class StockManagement implements StockManagementInterface */ public function backItemQty($productId, $qty, $scopeId = null) { - if (!$scopeId) { - $scopeId = $this->stockConfiguration->getDefaultScopeId(); - } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + //if (!$scopeId) { + $scopeId = $this->stockConfiguration->getDefaultScopeId(); + //} + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId); if ($stockItem->getItemId() && $this->stockConfiguration->isQty($this->getProductType($productId))) { if ($this->canSubtractQty($stockItem)) { $stockItem->setQty($stockItem->getQty() + $qty); diff --git a/app/code/Magento/CatalogInventory/Model/StockRegistry.php b/app/code/Magento/CatalogInventory/Model/StockRegistry.php index d72719fdb3a0501e274a9d9d5b3990c072e5e3c0..fda30523c39ab445b8588ed5f65d0ea40e2e4e8f 100644 --- a/app/code/Magento/CatalogInventory/Model/StockRegistry.php +++ b/app/code/Magento/CatalogInventory/Model/StockRegistry.php @@ -11,9 +11,7 @@ use Magento\CatalogInventory\Api\StockConfigurationInterface; use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory; use Magento\CatalogInventory\Api\StockItemRepositoryInterface; use Magento\CatalogInventory\Api\StockRegistryInterface; -use Magento\CatalogInventory\Model\Spi\StockResolverInterface; use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface; -use Magento\CatalogInventory\Model\Spi\StockStateProviderInterface; /** * Class StockRegistry @@ -47,49 +45,37 @@ class StockRegistry implements StockRegistryInterface */ protected $criteriaFactory; - /** - * @var \Magento\CatalogInventory\Model\Spi\StockResolverInterface - */ - protected $stockResolver; - - /** - * @var StockStateProviderInterface - */ - protected $stockStateProvider; - /** * @param StockConfigurationInterface $stockConfiguration * @param StockRegistryProviderInterface $stockRegistryProvider * @param StockItemRepositoryInterface $stockItemRepository * @param StockItemCriteriaInterfaceFactory $criteriaFactory * @param ProductFactory $productFactory - * @param StockResolverInterface $stockResolver - * @param StockStateProviderInterface $stockStateProvider */ public function __construct( StockConfigurationInterface $stockConfiguration, StockRegistryProviderInterface $stockRegistryProvider, StockItemRepositoryInterface $stockItemRepository, StockItemCriteriaInterfaceFactory $criteriaFactory, - ProductFactory $productFactory, - StockResolverInterface $stockResolver, - StockStateProviderInterface $stockStateProvider + ProductFactory $productFactory ) { $this->stockConfiguration = $stockConfiguration; $this->stockRegistryProvider = $stockRegistryProvider; $this->stockItemRepository = $stockItemRepository; $this->criteriaFactory = $criteriaFactory; $this->productFactory = $productFactory; - $this->stockResolver = $stockResolver; - $this->stockStateProvider = $stockStateProvider; } /** - * @inheritdoc + * @param int $scopeId + * @return \Magento\CatalogInventory\Api\Data\StockInterface */ - public function getStock($stockId = null) + public function getStock($scopeId = null) { - return $this->stockRegistryProvider->getStock($stockId); + //if (!$scopeId) { + $scopeId = $this->stockConfiguration->getDefaultScopeId(); + //} + return $this->stockRegistryProvider->getStock($scopeId); } /** @@ -99,12 +85,10 @@ class StockRegistry implements StockRegistryInterface */ public function getStockItem($productId, $scopeId = null) { - if (!$scopeId) { - $scopeId = $this->stockConfiguration->getDefaultScopeId(); - } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - - return $this->stockRegistryProvider->getStockItem($productId, $stockId); + //if (!$scopeId) { + $scopeId = $this->stockConfiguration->getDefaultScopeId(); + //} + return $this->stockRegistryProvider->getStockItem($productId, $scopeId); } /** @@ -115,12 +99,11 @@ class StockRegistry implements StockRegistryInterface */ public function getStockItemBySku($productSku, $scopeId = null) { - if (!$scopeId) { - $scopeId = $this->stockConfiguration->getDefaultScopeId(); - } + //if (!$scopeId) { + $scopeId = $this->stockConfiguration->getDefaultScopeId(); + //} $productId = $this->resolveProductId($productSku); - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - return $this->stockRegistryProvider->getStockItem($productId, $stockId); + return $this->stockRegistryProvider->getStockItem($productId, $scopeId); } /** @@ -130,11 +113,10 @@ class StockRegistry implements StockRegistryInterface */ public function getStockStatus($productId, $scopeId = null) { - if (!$scopeId) { - $scopeId = $this->stockConfiguration->getDefaultScopeId(); - } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - return $this->stockRegistryProvider->getStockStatus($productId, $stockId); + //if (!$scopeId) { + $scopeId = $this->stockConfiguration->getDefaultScopeId(); + //} + return $this->stockRegistryProvider->getStockStatus($productId, $scopeId); } /** @@ -145,12 +127,11 @@ class StockRegistry implements StockRegistryInterface */ public function getStockStatusBySku($productSku, $scopeId = null) { - if (!$scopeId) { - $scopeId = $this->stockConfiguration->getDefaultScopeId(); - } + //if (!$scopeId) { + $scopeId = $this->stockConfiguration->getDefaultScopeId(); + //} $productId = $this->resolveProductId($productSku); - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - return $this->getStockStatus($productId, $stockId); + return $this->getStockStatus($productId, $scopeId); } /** @@ -161,11 +142,10 @@ class StockRegistry implements StockRegistryInterface */ public function getProductStockStatus($productId, $scopeId = null) { - if (!$scopeId) { - $scopeId = $this->stockConfiguration->getDefaultScopeId(); - } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - $stockStatus = $this->getStockStatus($productId, $stockId); + //if (!$scopeId) { + $scopeId = $this->stockConfiguration->getDefaultScopeId(); + //} + $stockStatus = $this->getStockStatus($productId, $scopeId); return $stockStatus->getStockStatus(); } @@ -177,12 +157,11 @@ class StockRegistry implements StockRegistryInterface */ public function getProductStockStatusBySku($productSku, $scopeId = null) { - if (!$scopeId) { - $scopeId = $this->stockConfiguration->getDefaultScopeId(); - } + //if (!$scopeId) { + $scopeId = $this->stockConfiguration->getDefaultScopeId(); + //} $productId = $this->resolveProductId($productSku); - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - return $this->getProductStockStatus($productId, $stockId); + return $this->getProductStockStatus($productId, $scopeId); } /** diff --git a/app/code/Magento/CatalogInventory/Model/StockRegistryProvider.php b/app/code/Magento/CatalogInventory/Model/StockRegistryProvider.php index 0e103e2cddd14ff07bccc59a2239ca5d40a1a787..e8f7ae5cc723fb8219aaf9990c1d23017cb35b4e 100644 --- a/app/code/Magento/CatalogInventory/Model/StockRegistryProvider.php +++ b/app/code/Magento/CatalogInventory/Model/StockRegistryProvider.php @@ -15,13 +15,11 @@ use Magento\CatalogInventory\Api\Data\StockStatusInterfaceFactory; use Magento\CatalogInventory\Api\StockCriteriaInterfaceFactory; use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory; use Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory; -use Magento\CatalogInventory\Api\StockConfigurationInterface; use Magento\Store\Model\StoreManagerInterface; /** * Class StockRegistryProvider * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ class StockRegistryProvider implements StockRegistryProviderInterface { @@ -70,11 +68,6 @@ class StockRegistryProvider implements StockRegistryProviderInterface */ protected $stockStatusCriteriaFactory; - /** - * @var StockConfigurationInterface - */ - protected $stockConfiguration; - /** * @var array */ @@ -100,7 +93,6 @@ class StockRegistryProvider implements StockRegistryProviderInterface * @param StockCriteriaInterfaceFactory $stockCriteriaFactory * @param StockItemCriteriaInterfaceFactory $stockItemCriteriaFactory * @param StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory - * @param StockConfigurationInterface $stockConfiguration */ public function __construct( StockRepositoryInterface $stockRepository, @@ -111,8 +103,7 @@ class StockRegistryProvider implements StockRegistryProviderInterface StockStatusInterfaceFactory $stockStatusFactory, StockCriteriaInterfaceFactory $stockCriteriaFactory, StockItemCriteriaInterfaceFactory $stockItemCriteriaFactory, - StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory, - StockConfigurationInterface $stockConfiguration + StockStatusCriteriaInterfaceFactory $stockStatusCriteriaFactory ) { $this->stockRepository = $stockRepository; $this->stockFactory = $stockFactory; @@ -120,49 +111,43 @@ class StockRegistryProvider implements StockRegistryProviderInterface $this->stockItemFactory = $stockItemFactory; $this->stockStatusRepository = $stockStatusRepository; $this->stockStatusFactory = $stockStatusFactory; + $this->stockCriteriaFactory = $stockCriteriaFactory; $this->stockItemCriteriaFactory = $stockItemCriteriaFactory; $this->stockStatusCriteriaFactory = $stockStatusCriteriaFactory; - $this->stockConfiguration = $stockConfiguration; } /** - * @inheritdoc + * @param int|null $scopeId + * @return \Magento\CatalogInventory\Api\Data\StockInterface */ - public function getStock($stockId) + public function getStock($scopeId) { - if (!isset($this->stocks[$stockId])) { - if ($stockId !== null) { - $stock = $this->stockRepository->get($stockId); - } else { - /** @var \Magento\CatalogInventory\Api\StockCriteriaInterface $criteria */ - $criteria = $this->stockCriteriaFactory->create(); - $criteria->setScopeFilter($this->stockConfiguration->getDefaultScopeId()); - $collection = $this->stockRepository->getList($criteria); - $stock = current($collection->getItems()); - } + if (!isset($this->stocks[$scopeId])) { + $criteria = $this->stockCriteriaFactory->create(); + $criteria->setScopeFilter($scopeId); + $collection = $this->stockRepository->getList($criteria); + $stock = current($collection->getItems()); if ($stock && $stock->getStockId()) { - $this->stocks[$stockId] = $stock; + $this->stocks[$scopeId] = $stock; } else { return $this->stockFactory->create(); } } - return $this->stocks[$stockId]; + return $this->stocks[$scopeId]; } /** * @param int $productId - * @param int $stockId + * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockItemInterface */ - public function getStockItem($productId, $stockId) + public function getStockItem($productId, $scopeId) { - $key = $stockId . '/' . $productId; + $key = $scopeId . '/' . $productId; if (!isset($this->stockItems[$key])) { - /** @var \Magento\CatalogInventory\Api\StockItemCriteriaInterface $criteria */ $criteria = $this->stockItemCriteriaFactory->create(); $criteria->setProductsFilter($productId); - $criteria->setStockFilter($this->getStock($stockId)); $collection = $this->stockItemRepository->getList($criteria); $stockItem = current($collection->getItems()); if ($stockItem && $stockItem->getItemId()) { @@ -176,17 +161,16 @@ class StockRegistryProvider implements StockRegistryProviderInterface /** * @param int $productId - * @param int $stockId + * @param int $scopeId * @return \Magento\CatalogInventory\Api\Data\StockStatusInterface */ - public function getStockStatus($productId, $stockId) + public function getStockStatus($productId, $scopeId) { - $key = $stockId . '/' . $productId; + $key = $scopeId . '/' . $productId; if (!isset($this->stockStatuses[$key])) { - /** @var \Magento\CatalogInventory\Api\stockStatusCriteriaInterface $criteria */ $criteria = $this->stockStatusCriteriaFactory->create(); $criteria->setProductsFilter($productId); - $criteria->addFilter('stock', 'stock_id', $stockId); + $criteria->setScopeFilter($scopeId); $collection = $this->stockStatusRepository->getList($criteria); $stockStatus = current($collection->getItems()); if ($stockStatus && $stockStatus->getProductId()) { diff --git a/app/code/Magento/CatalogInventory/Model/StockResolver.php b/app/code/Magento/CatalogInventory/Model/StockResolver.php deleted file mode 100644 index 8e7c096d37047e7ae2c4cc40da87b6cbcb3f2c16..0000000000000000000000000000000000000000 --- a/app/code/Magento/CatalogInventory/Model/StockResolver.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\CatalogInventory\Model; - -use Magento\CatalogInventory\Model\Spi\StockResolverInterface; - -/** - * Class StockResolver - */ -class StockResolver implements StockResolverInterface -{ - const DEFAULT_STOCK_ID = 1; - - /** - * @inheritdoc - */ - public function getStockId($productId, $websiteId) - { - $stockId = self::DEFAULT_STOCK_ID; - return $stockId; - } -} diff --git a/app/code/Magento/CatalogInventory/Model/StockState.php b/app/code/Magento/CatalogInventory/Model/StockState.php index e64906691ad79ca2e8c65ddfe7738711b628101a..c3d0dc9aef0fd317d0d69e8b1b06b01b5af4f7e7 100644 --- a/app/code/Magento/CatalogInventory/Model/StockState.php +++ b/app/code/Magento/CatalogInventory/Model/StockState.php @@ -9,7 +9,6 @@ use Magento\CatalogInventory\Api\StockConfigurationInterface; use Magento\CatalogInventory\Api\StockStateInterface; use Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface; use Magento\CatalogInventory\Model\Spi\StockStateProviderInterface; -use Magento\CatalogInventory\Model\Spi\StockResolverInterface; /** * Interface StockState @@ -31,27 +30,19 @@ class StockState implements StockStateInterface */ protected $stockConfiguration; - /** - * @var StockResolverInterface - */ - protected $stockResolver; - /** * @param StockStateProviderInterface $stockStateProvider * @param StockRegistryProviderInterface $stockRegistryProvider * @param StockConfigurationInterface $stockConfiguration - * @param StockResolverInterface $stockResolver */ public function __construct( StockStateProviderInterface $stockStateProvider, StockRegistryProviderInterface $stockRegistryProvider, - StockConfigurationInterface $stockConfiguration, - StockResolverInterface $stockResolver + StockConfigurationInterface $stockConfiguration ) { $this->stockStateProvider = $stockStateProvider; $this->stockRegistryProvider = $stockRegistryProvider; $this->stockConfiguration = $stockConfiguration; - $this->stockResolver = $stockResolver; } /** @@ -64,8 +55,7 @@ class StockState implements StockStateInterface if ($scopeId === null) { $scopeId = $this->stockConfiguration->getDefaultScopeId(); } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId); return $this->stockStateProvider->verifyStock($stockItem); } @@ -79,8 +69,7 @@ class StockState implements StockStateInterface if ($scopeId === null) { $scopeId = $this->stockConfiguration->getDefaultScopeId(); } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId); return $this->stockStateProvider->verifyNotification($stockItem); } @@ -98,8 +87,7 @@ class StockState implements StockStateInterface if ($scopeId === null) { $scopeId = $this->stockConfiguration->getDefaultScopeId(); } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId); return $this->stockStateProvider->checkQty($stockItem, $qty); } @@ -117,8 +105,7 @@ class StockState implements StockStateInterface if ($scopeId === null) { $scopeId = $this->stockConfiguration->getDefaultScopeId(); } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId); return $this->stockStateProvider->suggestQty($stockItem, $qty); } @@ -134,8 +121,7 @@ class StockState implements StockStateInterface if ($scopeId === null) { $scopeId = $this->stockConfiguration->getDefaultScopeId(); } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId); return $this->stockStateProvider->getStockQty($stockItem); } @@ -150,8 +136,7 @@ class StockState implements StockStateInterface if ($websiteId === null) { $websiteId = $this->stockConfiguration->getDefaultScopeId(); } - $stockId = $this->stockResolver->getStockId($productId, $websiteId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $websiteId); return $this->stockStateProvider->checkQtyIncrements($stockItem, $qty); } @@ -168,8 +153,7 @@ class StockState implements StockStateInterface if ($scopeId === null) { $scopeId = $this->stockConfiguration->getDefaultScopeId(); } - $stockId = $this->stockResolver->getStockId($productId, $scopeId); - $stockItem = $this->stockRegistryProvider->getStockItem($productId, $stockId); + $stockItem = $this->stockRegistryProvider->getStockItem($productId, $scopeId); return $this->stockStateProvider->checkQuoteItemQty($stockItem, $itemQty, $qtyToCheck, $origQty); } } diff --git a/app/code/Magento/CatalogInventory/Observer/AddInventoryDataObserver.php b/app/code/Magento/CatalogInventory/Observer/AddInventoryDataObserver.php index 402807a624217f3989c2adc6f6371c1f3b05cb68..2e9ce4a393fab4de8e9ce06f8cc163aea9a10658 100644 --- a/app/code/Magento/CatalogInventory/Observer/AddInventoryDataObserver.php +++ b/app/code/Magento/CatalogInventory/Observer/AddInventoryDataObserver.php @@ -34,10 +34,7 @@ class AddInventoryDataObserver implements ObserverInterface { $product = $observer->getEvent()->getProduct(); if ($product instanceof \Magento\Catalog\Model\Product) { - $this->stockHelper->assignStatusToProduct( - $product, - $product->getStockStatus() - ); + $this->stockHelper->assignStatusToProduct($product); } } } diff --git a/app/code/Magento/CatalogInventory/Observer/SaveInventoryDataObserver.php b/app/code/Magento/CatalogInventory/Observer/SaveInventoryDataObserver.php index 84c6e31dbac4557fef31dbdd13fa57bb8ee1ef4b..08bf961fb7278d5dc624a637512bd6c3e4fc5a6e 100644 --- a/app/code/Magento/CatalogInventory/Observer/SaveInventoryDataObserver.php +++ b/app/code/Magento/CatalogInventory/Observer/SaveInventoryDataObserver.php @@ -11,7 +11,6 @@ use Magento\CatalogInventory\Api\StockConfigurationInterface; use Magento\CatalogInventory\Api\StockIndexInterface; use Magento\CatalogInventory\Api\StockItemRepositoryInterface; use Magento\CatalogInventory\Api\StockRegistryInterface; -use Magento\CatalogInventory\Model\Spi\StockResolverInterface; use Magento\Framework\Event\Observer as EventObserver; class SaveInventoryDataObserver implements ObserverInterface @@ -36,11 +35,6 @@ class SaveInventoryDataObserver implements ObserverInterface */ protected $stockItemRepository; - /** - * @var StockResolverInterface - */ - protected $stockResolver; - /** * @var array */ @@ -80,20 +74,17 @@ class SaveInventoryDataObserver implements ObserverInterface * @param StockConfigurationInterface $stockConfiguration * @param StockRegistryInterface $stockRegistry * @param StockItemRepositoryInterface $stockItemRepository - * @param StockResolverInterface $stockResolver */ public function __construct( StockIndexInterface $stockIndex, StockConfigurationInterface $stockConfiguration, StockRegistryInterface $stockRegistry, - StockItemRepositoryInterface $stockItemRepository, - StockResolverInterface $stockResolver + StockItemRepositoryInterface $stockItemRepository ) { $this->stockIndex = $stockIndex; $this->stockConfiguration = $stockConfiguration; $this->stockRegistry = $stockRegistry; $this->stockItemRepository = $stockItemRepository; - $this->stockResolver = $stockResolver; } /** @@ -134,8 +125,7 @@ class SaveInventoryDataObserver implements ObserverInterface if (!isset($stockItemData['website_id'])) { $stockItemData['website_id'] = $this->stockConfiguration->getDefaultScopeId(); } - $stockItemData['stock_id'] = $this->stockResolver - ->getStockId($stockItemData['product_id'], $stockItemData['website_id']); + $stockItemData['stock_id'] = $this->stockRegistry->getStock($stockItemData['website_id'])->getStockId(); foreach ($this->paramListToCheck as $dataKey => $configPath) { if (null !== $product->getData($configPath['item']) && null === $product->getData($configPath['config'])) { diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Api/StockRegistryTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Api/StockRegistryTest.php index 435defef554e54a259e707d770b9cc894ccba025..02c631727a4b564dfebad116b996c0a078420c39 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Api/StockRegistryTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Api/StockRegistryTest.php @@ -58,7 +58,6 @@ class StockRegistryTest extends \PHPUnit_Framework_TestCase protected $product; protected $productId = 111; - protected $stockId = 112; protected $productSku = 'simple'; protected $websiteId = 111; @@ -136,7 +135,7 @@ class StockRegistryTest extends \PHPUnit_Framework_TestCase public function testGetStock() { - $this->assertEquals($this->stock, $this->stockRegistry->getStock($this->stockId)); + $this->assertEquals($this->stock, $this->stockRegistry->getStock($this->websiteId)); } public function testGetStockItem() diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Helper/StockTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Helper/StockTest.php index 65173103377f4266eb5ce169d52b35863b74cfcd..cb4209de616e798498590461c9db2e3e1891657d 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Helper/StockTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Helper/StockTest.php @@ -37,11 +37,6 @@ class StockTest extends \PHPUnit_Framework_TestCase */ protected $statusFactoryMock; - /** - * @var \Magento\CatalogInventory\Model\Spi\StockResolverInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $stockResolverMock; - protected function setUp() { $this->stockRegistryProviderMock = $this->getMockBuilder( @@ -60,26 +55,18 @@ class StockTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->stockResolverMock = - $this->getMockBuilder('Magento\CatalogInventory\Model\Spi\StockResolverInterface') - ->disableOriginalConstructor() - ->setMethods(['getStockId']) - ->getMock(); $this->stock = new Stock( $this->storeManagerMock, $this->scopeConfigMock, $this->statusFactoryMock, - $this->stockRegistryProviderMock, - $this->stockResolverMock + $this->stockRegistryProviderMock ); } public function testAssignStatusToProduct() { - $websiteId = 0; - $productId = 2; - $stockId = 3; - $status = 1; + $websiteId = 1; + $status = 'test'; $stockStatusMock = $this->getMockBuilder('Magento\CatalogInventory\Api\Data\StockStatusInterface') ->disableOriginalConstructor() @@ -106,23 +93,15 @@ class StockTest extends \PHPUnit_Framework_TestCase $productMock->expects($this->once()) ->method('setIsSalable') ->with($status); - $productMock->expects($this->once()) - ->method('getId') - ->willReturn($productId); - $this->stockResolverMock->expects($this->once()) - ->method('getStockId') - ->with($productId, $websiteId) - ->willReturn($stockId); $this->assertNull($this->stock->assignStatusToProduct($productMock)); } public function testAddStockStatusToProducts() { $storeId = 1; - $websiteId = 0; $productId = 2; - $stockId = 3; - $status = 1; + $status = 'test'; + $productMock = $this->getMockBuilder('Magento\Catalog\Model\Product') ->disableOriginalConstructor() ->setMethods(['setIsSalable', 'getId']) @@ -158,21 +137,14 @@ class StockTest extends \PHPUnit_Framework_TestCase $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') ->disableOriginalConstructor() ->getMock(); - $storeMock->expects($this->once()) - ->method('getWebsiteId') - ->willReturn($websiteId); $this->storeManagerMock->expects($this->once()) ->method('getStore') - ->with($storeId) ->willReturn($storeMock); $this->stockRegistryProviderMock->expects($this->once()) ->method('getStockStatus') ->withAnyParameters() ->willReturn($stockStatusMock); - $this->stockResolverMock->expects($this->once()) - ->method('getStockId') - ->with($productId, $websiteId) - ->willReturn($stockId); + $this->assertNull($this->stock->addStockStatusToProducts($productCollectionMock)); } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Spi/StockRegistryProviderTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Spi/StockRegistryProviderTest.php index 5cf08ca76f3a35e8ad7a91ddae0eba033997a957..8328208440b80f2200511934d54fcb1886409035 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Spi/StockRegistryProviderTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Spi/StockRegistryProviderTest.php @@ -9,20 +9,45 @@ use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHe /** * Class StockRegistryProviderTest + * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.TooManyFields) */ class StockRegistryProviderTest extends \PHPUnit_Framework_TestCase { + /** @var ObjectManagerHelper */ + protected $objectManagerHelper; + /** * @var \Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $stockRegistryProvider; + /** + * @var \Magento\CatalogInventory\Api\Data\StockInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $stock; + + /** + * @var \Magento\CatalogInventory\Api\Data\StockItemInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $stockItem; + /** * @var \Magento\CatalogInventory\Api\Data\StockStatusInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $stockStatus; + /** + * @var \Magento\CatalogInventory\Api\Data\StockStatusInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $stockStatusFactory; + + /** + * @var \Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $stockItemFactory; + /** * @var \Magento\CatalogInventory\Api\Data\StockInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject */ @@ -58,6 +83,11 @@ class StockRegistryProviderTest extends \PHPUnit_Framework_TestCase */ protected $stockStatusCriteriaFactory; + /** + * @var \Magento\CatalogInventory\Api\StockCriteriaInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $stockCriteria; + /** * @var \Magento\CatalogInventory\Api\StockItemCriteriaInterface|\PHPUnit_Framework_MockObject_MockObject */ @@ -68,88 +98,132 @@ class StockRegistryProviderTest extends \PHPUnit_Framework_TestCase */ protected $stockStatusCriteria; - /** - * @var \Magento\CatalogInventory\Api\StockConfigurationInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $stockConfiguration; + protected $productId = 111; + protected $productSku = 'simple'; + protected $scopeId = 111; /** - * @var array + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - protected $productData = [ - 'stock_id' => 111, - 'product_id' => 112, - 'product_sku' => 'simple', - 'scope_id' => 113 - ]; - protected function setUp() { - $objectManagerHelper = new ObjectManagerHelper($this); + $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->stockFactory = $this->getMockBuilder('\Magento\CatalogInventory\Api\Data\StockInterfaceFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $stockItemFactory = $this->getMockBuilder('\Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory') - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $stockStatusFactory = $this->getMockBuilder( - '\Magento\CatalogInventory\Api\Data\StockStatusInterfaceFactory' - ) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $stockStatusFactory->expects($this->any())->method('create')->willReturn($this->stockStatus); - $this->stockCriteriaFactory = $this->getMockBuilder( - 'Magento\CatalogInventory\Api\StockCriteriaInterfaceFactory' - ) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->stockItemCriteriaFactory = $this->getMockBuilder( - 'Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory' - ) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->stockStatusCriteriaFactory = $this->getMockBuilder( - 'Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory' - ) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); + $this->stock = $this->getMockForAbstractClass( + 'Magento\CatalogInventory\Api\Data\StockInterface', + ['__wakeup', 'getStockId'], + '', + false + ); + $this->stockItem = $this->getMockForAbstractClass( + 'Magento\CatalogInventory\Api\Data\StockItemInterface', + ['__wakeup', 'getItemId'], + '', + false + ); + $this->stockStatus = $this->getMockForAbstractClass( + 'Magento\CatalogInventory\Api\Data\StockStatusInterface', + ['__wakeup', 'getProductId'], + '', + false + ); + + $this->stockFactory = $this->getMock( + '\Magento\CatalogInventory\Api\Data\StockInterfaceFactory', + ['create'], + [], + '', + false + ); + $this->stockFactory->expects($this->any())->method('create')->willReturn($this->stock); + + $this->stockItemFactory = $this->getMock( + '\Magento\CatalogInventory\Api\Data\StockItemInterfaceFactory', + ['create'], + [], + '', + false + ); + $this->stockItemFactory->expects($this->any())->method('create')->willReturn($this->stockItem); + + $this->stockStatusFactory = $this->getMock( + '\Magento\CatalogInventory\Api\Data\StockStatusInterfaceFactory', + ['create'], + [], + '', + false + ); + $this->stockStatusFactory->expects($this->any())->method('create')->willReturn($this->stockStatus); $this->stockRepository = $this->getMockBuilder('\Magento\CatalogInventory\Api\StockRepositoryInterface') ->disableOriginalConstructor() ->getMock(); + $this->stockItemRepository = $this->getMockBuilder('\Magento\CatalogInventory\Api\StockItemRepositoryInterface') ->disableOriginalConstructor() ->getMock(); + $this->stockStatusRepository = $this->getMockBuilder( '\Magento\CatalogInventory\Api\StockStatusRepositoryInterface' ) ->disableOriginalConstructor() ->getMock(); - $this->stockConfiguration = $this->getMockBuilder('Magento\CatalogInventory\Api\StockConfigurationInterface') - ->disableOriginalConstructor() - ->setMethods(['getDefaultScopeId']) - ->getMockForAbstractClass(); - $this->stockRegistryProvider = $objectManagerHelper->getObject( + $this->stockCriteriaFactory = $this->getMock( + 'Magento\CatalogInventory\Api\StockCriteriaInterfaceFactory', + ['create'], + [], + '', + false + ); + $this->stockCriteria = $this->getMockForAbstractClass( + 'Magento\CatalogInventory\Api\StockCriteriaInterface', + ['setScopeFilter'], + '', + false + ); + + $this->stockItemCriteriaFactory = $this->getMock( + 'Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory', + ['create'], + [], + '', + false + ); + $this->stockItemCriteria = $this->getMockForAbstractClass( + 'Magento\CatalogInventory\Api\StockItemCriteriaInterface', + ['setProductsFilter', 'setScopeFilter'], + '', + false + ); + + $this->stockStatusCriteriaFactory = $this->getMock( + 'Magento\CatalogInventory\Api\StockStatusCriteriaInterfaceFactory', + ['create'], + [], + '', + false + ); + $this->stockStatusCriteria = $this->getMockForAbstractClass( + 'Magento\CatalogInventory\Api\StockStatusCriteriaInterface', + ['setProductsFilter', 'setScopeFilter'], + '', + false + ); + + $this->stockRegistryProvider = $this->objectManagerHelper->getObject( '\Magento\CatalogInventory\Model\StockRegistryProvider', [ 'stockRepository' => $this->stockRepository, 'stockFactory' => $this->stockFactory, 'stockItemRepository' => $this->stockItemRepository, - 'stockItemFactory' => $stockItemFactory, + 'stockItemFactory' => $this->stockItemFactory, 'stockStatusRepository' => $this->stockStatusRepository, - 'stockStatusFactory' => $stockStatusFactory, + 'stockStatusFactory' => $this->stockStatusFactory, + 'stockCriteriaFactory' => $this->stockCriteriaFactory, 'stockItemCriteriaFactory' => $this->stockItemCriteriaFactory, - 'stockStatusCriteriaFactory' => $this->stockStatusCriteriaFactory, - 'stockConfiguration' => $this->stockConfiguration + 'stockStatusCriteriaFactory' => $this->stockStatusCriteriaFactory ] ); } @@ -159,114 +233,63 @@ class StockRegistryProviderTest extends \PHPUnit_Framework_TestCase $this->stockRegistryProvider = null; } - public function testGetStockWithStock() + public function testGetStock() { - $stock = $this->getMockBuilder('Magento\CatalogInventory\Api\Data\StockInterface') - ->disableOriginalConstructor() - ->setMethods(['getStockId']) - ->getMockForAbstractClass(); - $this->stockFactory->expects($this->any())->method('create')->willReturn($stock); - $stock->expects($this->once())->method('getStockId')->willReturn($this->productData['stock_id']); - $this->stockRepository->expects($this->once())->method('get')->willReturn($stock); - $this->assertEquals($stock, $this->stockRegistryProvider->getStock($this->productData['stock_id'])); - } - - public function testGetStockWithoutStock() - { - $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId') - ->willReturn($this->productData['scope_id']); - $stock = $this->getMockBuilder('Magento\CatalogInventory\Api\Data\StockInterface') - ->disableOriginalConstructor() - ->setMethods(['getStockId']) - ->getMockForAbstractClass(); - $stock->expects($this->once())->method('getStockId')->willReturn($this->productData['stock_id']); - $stockCollection = $this->getMockBuilder('Magento\CatalogInventory\Api\Data\StockCollectionInterface') - ->disableOriginalConstructor() - ->setMethods(['getItems']) - ->getMockForAbstractClass(); - $stockCriteria = $this->getMockBuilder('\Magento\CatalogInventory\Api\StockCriteriaInterface') - ->disableOriginalConstructor() - ->setMethods(['getItems']) - ->getMockForAbstractClass(); - $stockCriteria->expects($this->once())->method('setScopeFilter')->with($this->productData['scope_id']) - ->willReturnSelf(); - $this->stockCriteriaFactory->expects($this->once())->method('create')->willReturn($stockCriteria); - $this->stockRepository->expects($this->once())->method('getList') - ->with($stockCriteria)->willReturn($stockCollection); - $stockCollection->expects($this->once())->method('getItems')->willReturn([$stock]); - $this->assertEquals($stock, $this->stockRegistryProvider->getStock(null)); + $this->stockCriteriaFactory->expects($this->once())->method('create')->willReturn($this->stockCriteria); + $this->stockCriteria->expects($this->once())->method('setScopeFilter')->willReturn(null); + $stockCollection = $this->getMock( + '\Magento\CatalogInventory\Model\ResourceModel\Stock\Collection', + ['getFirstItem', '__wakeup', 'getItems'], + [], + '', + false + ); + $stockCollection->expects($this->once())->method('getItems')->willReturn([$this->stock]); + $this->stockRepository->expects($this->once())->method('getList')->willReturn($stockCollection); + $this->stock->expects($this->once())->method('getStockId')->willReturn(true); + $this->assertEquals($this->stock, $this->stockRegistryProvider->getStock($this->scopeId)); } public function testGetStockItem() { - $stock = $this->getMockBuilder('Magento\CatalogInventory\Api\Data\StockInterface') - ->disableOriginalConstructor() - ->setMethods(['getStockId']) - ->getMockForAbstractClass(); - $this->stockRepository->expects($this->once())->method('get')->willReturn($stock); - $stockItemCriteria = $this->getMockBuilder('Magento\CatalogInventory\Api\StockItemCriteriaInterface') - ->disableOriginalConstructor() - ->setMethods(['setProductsFilter', 'setStockFilter']) - ->getMockForAbstractClass(); - $this->stockItemCriteriaFactory->expects($this->once())->method('create')->willReturn($stockItemCriteria); - $stockItemCriteria->expects($this->once())->method('setProductsFilter')->with($this->productData['product_id']) - ->willReturnSelf(); - $stock->expects($this->once())->method('getStockId')->willReturn($this->productData['stock_id']); - $stockItemCriteria->expects($this->once())->method('setStockFilter')->with($stock) - ->willReturnSelf(); - $stockItemCollection = $this->getMockBuilder( - '\Magento\CatalogInventory\Model\ResourceModel\Stock\Item\Collection' - ) - ->disableOriginalConstructor() - ->setMethods(['getFirstItem', 'getItems']) - ->getMock(); - $stockItem = $this->getMockBuilder('Magento\CatalogInventory\Api\Data\StockItemInterface') - ->disableOriginalConstructor() - ->setMethods(['getItemId']) - ->getMockForAbstractClass(); - $stockItemCollection->expects($this->once())->method('getItems')->willReturn([$stockItem]); + $this->stockItemCriteriaFactory->expects($this->once())->method('create')->willReturn($this->stockItemCriteria); + $this->stockItemCriteria->expects($this->once())->method('setProductsFilter')->willReturn(null); + $stockItemCollection = $this->getMock( + '\Magento\CatalogInventory\Model\ResourceModel\Stock\Item\Collection', + ['getFirstItem', '__wakeup', 'getItems'], + [], + '', + false + ); + $stockItemCollection->expects($this->once())->method('getItems')->willReturn([$this->stockItem]); $this->stockItemRepository->expects($this->once())->method('getList')->willReturn($stockItemCollection); - $stockItem->expects($this->once())->method('getItemId')->willReturn(true); + $this->stockItem->expects($this->once())->method('getItemId')->willReturn(true); $this->assertEquals( - $stockItem, - $this->stockRegistryProvider->getStockItem($this->productData['product_id'], $this->productData['stock_id']) + $this->stockItem, + $this->stockRegistryProvider->getStockItem($this->productId, $this->scopeId) ); } public function testGetStockStatus() { - $stockStatusCriteria = $this->getMockBuilder('Magento\CatalogInventory\Api\StockStatusCriteriaInterface') - ->disableOriginalConstructor() - ->setMethods(['setProductsFilter', 'addFilter']) - ->getMockForAbstractClass(); $this->stockStatusCriteriaFactory->expects($this->once()) ->method('create') - ->willReturn($stockStatusCriteria); - $stockStatusCriteria->expects($this->once())->method('setProductsFilter') - ->with($this->productData['product_id']) - ->willReturnSelf(); - $stockStatusCriteria->expects($this->once())->method('addFilter') - ->with('stock', 'stock_id', $this->productData['stock_id']) - ->willReturnSelf(); - $stockStatusCollection = $this->getMockBuilder( - '\Magento\CatalogInventory\Model\ResourceModel\Stock\Status\Collection' - ) - ->disableOriginalConstructor() - ->setMethods(['getFirstItem', 'getItems']) - ->getMock(); - $stockStatus = $this->getMockBuilder('Magento\CatalogInventory\Api\Data\StockStatusInterface') - ->disableOriginalConstructor() - ->setMethods(['getProductId']) - ->getMockForAbstractClass(); - $stockStatusCollection->expects($this->once())->method('getItems')->willReturn([$stockStatus]); - $stockStatus->expects($this->once())->method('getProductId')->willReturn($this->productData['product_id']); + ->willReturn($this->stockStatusCriteria); + $this->stockStatusCriteria->expects($this->once())->method('setScopeFilter')->willReturn(null); + $this->stockStatusCriteria->expects($this->once())->method('setProductsFilter')->willReturn(null); + $stockStatusCollection = $this->getMock( + '\Magento\CatalogInventory\Model\ResourceModel\Stock\Status\Collection', + ['getFirstItem', '__wakeup', 'getItems'], + [], + '', + false + ); + $stockStatusCollection->expects($this->once())->method('getItems')->willReturn([$this->stockStatus]); $this->stockStatusRepository->expects($this->once())->method('getList')->willReturn($stockStatusCollection); + $this->stockStatus->expects($this->once())->method('getProductId')->willReturn($this->productId); $this->assertEquals( - $stockStatus, - $this->stockRegistryProvider->getStockStatus( - $this->productData['product_id'], - $this->productData['stock_id'] - ) + $this->stockStatus, + $this->stockRegistryProvider->getStockStatus($this->productId, $this->scopeId) ); } } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php index a81f930ccb6ce51ef9cab945d67498e7b0e46638..27188a0efd3520d18b7e93d83e0485bdd30f64c4 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Stock/ItemTest.php @@ -63,9 +63,9 @@ class ItemTest extends \PHPUnit_Framework_TestCase protected $resource; /** - * @var \Magento\CatalogInventory\Api\StockRegistryInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\CatalogInventory\Model\ResourceModel\Stock\Item\Collection|\PHPUnit_Framework_MockObject_MockObject */ - protected $stockRegistry; + protected $resourceCollection; /** * @var int @@ -117,8 +117,13 @@ class ItemTest extends \PHPUnit_Framework_TestCase false ); - $this->stockRegistry = $this->getMockBuilder('Magento\CatalogInventory\Api\StockRegistryInterface') - ->getMockForAbstractClass(); + $this->resourceCollection = $this->getMock( + 'Magento\CatalogInventory\Model\ResourceModel\Stock\Item\Collection', + [], + [], + '', + false + ); $this->objectManagerHelper = new ObjectManagerHelper($this); @@ -132,7 +137,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase 'stockConfiguration' => $this->stockConfiguration, 'stockItemRepository' => $this->stockItemRepository, 'resource' => $this->resource, - 'stockRegistry' => $this->stockRegistry + 'stockItemRegistry' => $this->resourceCollection ] ); } @@ -452,14 +457,4 @@ class ItemTest extends \PHPUnit_Framework_TestCase ], ]; } - - public function testGetStockId() - { - $stockId = 1; - $stock = $this->getMockBuilder('Magento\CatalogInventory\Api\Data\StockInterface') - ->getMockForAbstractClass(); - $this->stockRegistry->expects($this->once())->method('getStock')->willReturn($stock); - $stock->expects($this->once())->method('getStockId')->willReturn($stockId); - $this->assertEquals($stockId, $this->item->getStockId()); - } } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Observer/AddInventoryDataObserverTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Observer/AddInventoryDataObserverTest.php index 9688a418119027ae889d39a296aa861fc2f27d5d..68a73ac1eecaae3c6a075d73697a402b3b9a37c8 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Observer/AddInventoryDataObserverTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Observer/AddInventoryDataObserverTest.php @@ -57,24 +57,17 @@ class AddInventoryDataObserverTest extends \PHPUnit_Framework_TestCase public function testAddInventoryData() { - $stockStatus = true; - $product = $this->getMockBuilder('Magento\Catalog\Model\Product') ->disableOriginalConstructor() - ->setMethods(['getStockStatus']) ->getMock(); - $product->expects($this->once()) - ->method('getStockStatus') - ->will($this->returnValue($stockStatus)); - $this->event->expects($this->once()) ->method('getProduct') ->will($this->returnValue($product)); $this->stockHelper->expects($this->once()) ->method('assignStatusToProduct') - ->with($product, $stockStatus) + ->with($product) ->will($this->returnSelf()); $this->observer->execute($this->eventObserver); diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Observer/SaveInventoryDataObserverTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Observer/SaveInventoryDataObserverTest.php index 17ca09b6e24fdf54eb566a71890820076b928ce3..96604e75d92946e9cf614139db7ddda4558cec22 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Observer/SaveInventoryDataObserverTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Observer/SaveInventoryDataObserverTest.php @@ -19,26 +19,6 @@ class SaveInventoryDataObserverTest extends \PHPUnit_Framework_TestCase */ protected $stockIndex; - /** - * @var \Magento\CatalogInventory\Api\StockConfigurationInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $stockConfiguration; - - /** - * @var \Magento\CatalogInventory\Model\Spi\stockResolverInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $stockResolver; - - /** - * @var \Magento\CatalogInventory\Api\StockRegistryInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $stockRegistry; - - /** - * @var \Magento\CatalogInventory\Api\StockItemRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject - */ - protected $stockItemRepository; - /** * @var \Magento\Framework\Event|\PHPUnit_Framework_MockObject_MockObject */ @@ -51,30 +31,12 @@ class SaveInventoryDataObserverTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->stockIndex = $this->getMockBuilder('Magento\CatalogInventory\Api\StockIndexInterface') - ->disableOriginalConstructor() - ->setMethods(['rebuild']) - ->getMockForAbstractClass(); - - $this->stockConfiguration = $this->getMockBuilder('Magento\CatalogInventory\Api\StockConfigurationInterface') - ->disableOriginalConstructor() - ->setMethods(['getDefaultScopeId']) - ->getMockForAbstractClass(); - - $this->stockResolver = $this->getMockBuilder('Magento\CatalogInventory\Model\Spi\StockResolverInterface') - ->disableOriginalConstructor() - ->setMethods(['getStockId']) - ->getMockForAbstractClass(); - - $this->stockRegistry = $this->getMockBuilder('Magento\CatalogInventory\Api\StockRegistryInterface') - ->disableOriginalConstructor() - ->setMethods(['getStockItem']) - ->getMockForAbstractClass(); - - $this->stockItemRepository = $this->getMockBuilder('Magento\CatalogInventory\Api\StockItemRepositoryInterface') - ->disableOriginalConstructor() - ->setMethods(['save']) - ->getMockForAbstractClass(); + $this->stockIndex = $this->getMockForAbstractClass( + 'Magento\CatalogInventory\Api\StockIndexInterface', + ['rebuild'], + '', + false + ); $this->event = $this->getMockBuilder('Magento\Framework\Event') ->disableOriginalConstructor() @@ -94,15 +56,11 @@ class SaveInventoryDataObserverTest extends \PHPUnit_Framework_TestCase 'Magento\CatalogInventory\Observer\SaveInventoryDataObserver', [ 'stockIndex' => $this->stockIndex, - 'stockConfiguration' => $this->stockConfiguration, - 'stockResolver' => $this->stockResolver, - 'stockRegistry' => $this->stockRegistry, - 'stockItemRepository' => $this->stockItemRepository ] ); } - public function testSaveInventoryDataWithoutStockData() + public function testSaveInventoryData() { $productId = 4; $websiteId = 5; @@ -134,49 +92,4 @@ class SaveInventoryDataObserverTest extends \PHPUnit_Framework_TestCase $this->observer->execute($this->eventObserver); } - - public function testSaveInventoryDataWithStockData() - { - $stockItemData = [ - 'qty' => 4, - 'product_id' => 2, - 'website_id' => 3, - 'stock_id' => 1, - 'qty_correction' => -1 - ]; - - $product = $this->getMock( - 'Magento\Catalog\Model\Product', - ['getStockData', 'getId', 'getData'], - [], - '', - false - ); - $product->expects($this->exactly(2))->method('getStockData')->will($this->returnValue( - ['qty' => $stockItemData['qty']] - )); - $product->expects($this->once())->method('getId')->will($this->returnValue($stockItemData['product_id'])); - $product->expects($this->any())->method('getData')->willReturnMap( - [ - ['stock_data/original_inventory_qty', null, $stockItemData['qty']+1] - ] - ); - $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId') - ->willReturn($stockItemData['website_id']); - $this->stockResolver->expects($this->once())->method('getStockId') - ->with($stockItemData['product_id'], $stockItemData['website_id']) - ->willReturn($stockItemData['stock_id']); - $stockItem = $this->getMockBuilder('\Magento\CatalogInventory\Api\Data\StockItemInterface') - ->disableOriginalConstructor() - ->setMethods(['addData']) - ->getMockForAbstractClass(); - $this->stockRegistry->expects($this->once())->method('getStockItem') - ->with($stockItemData['product_id'], $stockItemData['website_id']) - ->willReturn($stockItem); - $stockItem->expects($this->once())->method('addData')->with($stockItemData)->willReturnSelf(); - $this->stockItemRepository->expects($this->once())->method('save')->with($stockItem); - $this->event->expects($this->once())->method('getProduct')->will($this->returnValue($product)); - - $this->observer->execute($this->eventObserver); - } } diff --git a/app/code/Magento/CatalogInventory/etc/di.xml b/app/code/Magento/CatalogInventory/etc/di.xml index 40f9bf2d1275d44e8822cd021fd9610b00ad71c6..fbce94514ebff09f03060a95ca5bea4a5c698fcf 100644 --- a/app/code/Magento/CatalogInventory/etc/di.xml +++ b/app/code/Magento/CatalogInventory/etc/di.xml @@ -30,8 +30,7 @@ <preference for="Magento\CatalogInventory\Model\Spi\StockRegistryProviderInterface" type="Magento\CatalogInventory\Model\StockRegistryProvider" /> <preference for="Magento\CatalogInventory\Model\Spi\StockStateProviderInterface" type="Magento\CatalogInventory\Model\StockStateProvider" /> - <preference for="Magento\CatalogInventory\Model\Spi\StockResolverInterface" type="Magento\CatalogInventory\Model\StockResolver" /> - + <preference for="Magento\CatalogInventory\Model\ResourceModel\QtyCounterInterface" type="\Magento\CatalogInventory\Model\ResourceModel\Stock" /> <type name="Magento\Catalog\Model\Product\Attribute\Repository"> <plugin name="filterCustomAttribute" type="Magento\CatalogInventory\Model\Plugin\FilterCustomAttribute" /> diff --git a/app/code/Magento/Downloadable/view/adminhtml/web/downloadable-type-handler.js b/app/code/Magento/Downloadable/view/adminhtml/web/downloadable-type-handler.js index 12521c18ca6c17c335f758c82311832dcc6ef2ae..e8e61c26b49cfb7e318d712e65b05f920c0a0f73 100644 --- a/app/code/Magento/Downloadable/view/adminhtml/web/downloadable-type-handler.js +++ b/app/code/Magento/Downloadable/view/adminhtml/web/downloadable-type-handler.js @@ -65,7 +65,10 @@ define([ if (productType.type.current === 'downloadable') { weight.change(false); weight.$weightSwitcher().one('change', function () { - $(document).trigger('setTypeProduct', null); + $(document).trigger( + 'setTypeProduct', + productType.type.init === 'downloadable' ? 'virtual' : productType.type.init + ); }); this.show(); } else { diff --git a/app/code/Magento/Paypal/etc/adminhtml/system.xml b/app/code/Magento/Paypal/etc/adminhtml/system.xml index d716794f5ca8e67649354ac71a070af028661239..545dc858eee17321cf00ff06e79d73277a8c2707 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/system.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/system.xml @@ -51,6 +51,7 @@ <group id="wpp_usuk" sortOrder="40" extends="payment_us/paypal_payment_gateways/paypal_payflowpro_with_express_checkout"> <label>Payments Pro (Includes Express Checkout)</label> <attribute type="activity_path">payment/paypal_payment_pro/active</attribute> + <more_url>https://www.paypal.com/us/webapps/mpp/paypal-payments-pro?partner_id=NB9WWHYEMVUMS</more_url> <group id="paypal_payflow_required" translate="label" showInDefault="1" showInWebsite="1" sortOrder="10"> <field id="enable_paypal_payflow"> <attribute type="shared">0</attribute> diff --git a/app/code/Magento/Ui/view/base/web/js/form/components/button.js b/app/code/Magento/Ui/view/base/web/js/form/components/button.js new file mode 100644 index 0000000000000000000000000000000000000000..b5373ff1648b7f2c3db97e8333551781c09b09e1 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/js/form/components/button.js @@ -0,0 +1,103 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'uiElement', + 'uiRegistry', + 'uiLayout', + 'mageUtils' +], function (Element, registry, layout, utils) { + 'use strict'; + + return Element.extend({ + defaults: { + additionalClasses: {}, + displayArea: 'outsideGroup', + displayAsLink: false, + elementTmpl: 'ui/form/element/button', + template: 'ui/form/components/button/simple' + }, + + /** + * Initializes component. + * + * @returns {Object} Chainable. + */ + initialize: function () { + return this._super() + ._setClasses(); + }, + + /** + * Performs configured actions + */ + action: function () { + this.actions.forEach(this.applyAction, this); + }, + + /** + * Apply action on target component, + * but previously create this component from template if it is not existed + * + * @param {Object} action - action configuration + */ + applyAction: function (action) { + var targetName = action.targetName, + params = action.params, + actionName = action.actionName, + target; + + if (!registry.has(targetName)) { + this.getFromTemplate(targetName); + } + target = registry.async(targetName); + + if (target && typeof target === 'function' && actionName) { + target(actionName, params); + } + }, + + /** + * Create target component from template + * + * @param {Object} targetName - name of component, + * that supposed to be a template and need to be initialized + */ + getFromTemplate: function (targetName) { + var parentName = targetName.split('.'), + index = parentName.pop(), + child; + + parentName = parentName.join('.'); + child = utils.template({ + parent: parentName, + name: index, + nodeTemplate: targetName + }); + layout([child]); + }, + + /** + * Extends 'additionalClasses' object. + * + * @returns {Object} Chainable. + */ + _setClasses: function () { + if (typeof this.additionalClasses === 'string') { + this.additionalClasses = this.additionalClasses + .trim() + .split(' ') + .reduce(function (classes, name) { + classes[name] = true; + + return classes; + }, {} + ); + } + + return this; + } + }); +}); diff --git a/app/code/Magento/Ui/view/base/web/js/lib/core/element/links.js b/app/code/Magento/Ui/view/base/web/js/lib/core/element/links.js index c769be3775f46ddba47d5d9110974fc2bd5782da..1ac9b45a46e86a9df232db8993932a886c3bcd8c 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/core/element/links.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/core/element/links.js @@ -51,7 +51,7 @@ define([ } if (owner.component !== target.component) { - value = utils.copy(value); + value = data.inversionValue ? !utils.copy(value) : utils.copy(value); } component.set(property, value); @@ -149,6 +149,11 @@ define([ function transfer(owner, data) { var args = _.toArray(arguments); + if (data.target.substr(0,1) === '!') { + data.target = data.target.substr(1); + data.inversionValue = true; + } + if (owner.name === data.target) { args.unshift(owner); diff --git a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/outer_click.js b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/outer_click.js index 839a87481a38631267f295c9908abf2873d74f4d..7fa3ff22af8975b62d23b3f9c07ff3ab8d813c39 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/outer_click.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/knockout/bindings/outer_click.js @@ -15,6 +15,30 @@ define([ onlyIfVisible: true }; + /** + * Checks if element sis visible. + * + * @param {Element} el + * @returns {Boolean} + */ + function isVisible(el) { + var style = window.getComputedStyle(el), + visibility = { + display: 'none', + visibility: 'hidden', + opacity: '0' + }, + visible = true; + + _.each(visibility, function (val, key) { + if (style[key] === val) { + visible = false; + } + }); + + return visible; + } + /** * Document click handler which in case if event target is not * a descendant of provided container element, @@ -33,7 +57,7 @@ define([ } if (config.onlyIfVisible) { - if (!_.isNull(container.offsetParent)) { + if (!_.isNull(container.offsetParent) && isVisible(container)) { callback(); } } else { diff --git a/app/code/Magento/Ui/view/base/web/js/modal/modal-component.js b/app/code/Magento/Ui/view/base/web/js/modal/modal-component.js new file mode 100644 index 0000000000000000000000000000000000000000..cccf95e00bf54f2a667e85fab4d5f12b435728a5 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/js/modal/modal-component.js @@ -0,0 +1,315 @@ +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'Magento_Ui/js/lib/view/utils/async', + 'uiCollection', + 'uiRegistry', + 'underscore', + './modal' +], function ($, Collection, registry, _) { + 'use strict'; + + return Collection.extend({ + defaults: { + template: 'ui/modal/modal-component', + options: { + title: '', + buttons: [], + keyEventHandlers: {} + }, + valid: true, + listens: { + state: 'onState' + }, + modalClass: 'modal-component' + }, + + /** + * Initializes component. + * + * @returns {Object} Chainable. + */ + initialize: function () { + this._super(); + _.bindAll(this, + 'initModal', + 'openModal', + 'closeModal', + 'toggleModal', + 'setPrevValues', + 'actionCancel', + 'validate'); + this.initializeContent(); + + return this; + }, + + /** + * Initializes modal configuration + * + * @returns {Object} Chainable. + */ + initConfig: function () { + return this._super() + .initSelector() + .initModalEvents(); + }, + + /** + * Configure modal selector + * + * @returns {Object} Chainable. + */ + initSelector: function () { + this.contentSelector = '.' + this.modalClass; + this.options.modalClass = this.name.replace(/\./g, '_'); + this.rootSelector = '.' + this.options.modalClass; + + return this; + }, + + /** + * Configure modal keyboard handlers + * and outer click + * + * @returns {Object} Chainable. + */ + initModalEvents: function () { + this.options.keyEventHandlers.escapeKey = this.options.outerClickHandler = this.actionCancel.bind(this); + + return this; + }, + + /** + * Initialize modal's content components + */ + initializeContent: function () { + $.async(this.contentSelector, this, this.initModal); + }, + + /** + * Init toolbar section so other components will be able to place something in it + */ + initToolbarSection: function () { + this.set('toolbarSection', this.modal.data('modal').modal.find('header').get(0)); + }, + + /** + * Initializes observable properties. + * + * @returns {Object} Chainable. + */ + initObservable: function () { + this._super(); + this.observe('state'); + + return this; + }, + + /** + * Wrap content in a modal of certain type + * + * @param {HTMLElement} element + * @returns {Object} Chainable. + */ + initModal: function (element) { + if (!this.modal) { + this.overrideModalButtonCallback(); + this.options.modalCloseBtnHandler = this.actionCancel; + this.modal = $(element).modal(this.options); + this.initToolbarSection(); + + if (this.waitCbk) { + this.waitCbk(); + this.waitCbk = null; + } + } + + return this; + }, + + /** + * Open modal + */ + openModal: function () { + if (this.modal) { + this.state(true); + } else { + this.waitCbk = this.openModal; + } + }, + + /** + * Close modal + */ + closeModal: function () { + if (this.modal) { + this.state(false); + } else { + this.waitCbk = this.closeModal; + } + }, + + /** + * Toggle modal + */ + toggleModal: function () { + if (this.modal) { + this.state(!this.state()); + } else { + this.waitCbk = this.toggleModal; + } + }, + + /** + * Wrap content in a modal of certain type + * + * @param {Boolean} state + */ + onState: function (state) { + if (state) { + this.modal.modal('openModal'); + this.applyData(); + } else { + this.modal.modal('closeModal'); + } + }, + + /** + * Validate everything validatable in modal + */ + validate: function (elem) { + if (typeof elem.validate === 'function') { + this.valid = this.valid & elem.validate().valid; + } else if (elem.elems) { + elem.elems().forEach(this.validate, this); + } + }, + + /** + * Reset data from provider + */ + resetData: function () { + this.elems().forEach(this.resetValue, this); + }, + + /** + * Update 'applied' property with data from modal content + */ + applyData: function () { + var applied = {}; + + this.elems().forEach(this.gatherValues.bind(this, applied), this); + this.applied = applied; + }, + + /** + * Gather values from modal content + * + * @param {Array} applied + * @param {HTMLElement} elem + */ + gatherValues: function (applied, elem) { + if (typeof elem.value === 'function') { + applied[elem.index] = elem.value(); + } else if (elem.elems) { + elem.elems().forEach(this.gatherValues.bind(this, applied), this); + } + }, + + /** + * Set to previous values from modal content + * + * @param {HTMLElement} elem + */ + setPrevValues: function (elem) { + if (typeof elem.value === 'function') { + this.modal.focus(); + elem.value(this.applied[elem.index]); + } else if (elem.elems) { + elem.elems().forEach(this.setPrevValues, this); + } + }, + + /** + * Triggers some method in every modal child elem, if this method is defined + * + * @param {Object} action - action configuration, + * must contain actionName and targetName and + * can contain params + */ + triggerAction: function (action) { + var targetName = action.targetName, + params = action.params, + actionName = action.actionName, + target; + + target = registry.async(targetName); + + if (target && typeof target === 'function' && actionName) { + target(actionName, params); + } + }, + + /** + * Override modal buttons callback placeholders with real callbacks + */ + overrideModalButtonCallback: function () { + var buttons = this.options.buttons; + + if (buttons && buttons.length) { + buttons.forEach(function (button) { + button.click = this.getButtonClickHandler(button.actions); + }, this); + } + }, + + /** + * Generate button click handler based on button's 'actions' configuration + */ + getButtonClickHandler: function (actionsConfig) { + var actions = actionsConfig.map( + function (actionConfig) { + if (_.isObject(actionConfig)) { + return this.triggerAction.bind(this, actionConfig); + } + + return this[actionConfig] ? this[actionConfig].bind(this) : function () {}; + }, this); + + return function () { + actions.forEach( + function (action) { + action(); + } + ); + }; + }, + + /** + * Cancels changes in modal: + * returning elems values to the previous state, + * and close modal + */ + actionCancel: function () { + this.elems().forEach(this.setPrevValues, this); + this.closeModal(); + }, + + /** + * Accept changes in modal by not preventing them. + * Can be extended by exporting 'gatherValues' result somewhere + */ + actionDone: function () { + this.valid = true; + this.elems().forEach(this.validate, this); + + if (this.valid) { + this.closeModal(); + } + } + }); +}); diff --git a/app/code/Magento/Ui/view/base/web/js/modal/modal.js b/app/code/Magento/Ui/view/base/web/js/modal/modal.js index 23011d607cdadc301ee6cf4cebeb148b400c0260..5dcfc53459baad6607edce1f13be49e708ead692 100644 --- a/app/code/Magento/Ui/view/base/web/js/modal/modal.js +++ b/app/code/Magento/Ui/view/base/web/js/modal/modal.js @@ -118,13 +118,14 @@ define([ 'closeModal' ); + _.extend(this.keyEventHandlers, this.options.keyEventHandlers); this.options.transitionEvent = transitionEvent; this._createWrapper(); this._renderModal(); this._createButtons(); $(this.options.trigger).on('click', _.bind(this.toggleModal, this)); this._on(this.modal.find(this.options.modalCloseBtn), { - 'click': this.closeModal + 'click': this.options.modalCloseBtnHandler ? this.options.modalCloseBtnHandler : this.closeModal }); this._on(this.element, { 'openModal': this.openModal, @@ -374,7 +375,8 @@ define([ * Creates overlay, append it to wrapper, set previous click event on overlay. */ _createOverlay: function () { - var events; + var events, + outerClickHandler = this.options.outerClickHandler || this.closeModal; this.overlay = $('.' + this.options.overlayClass); @@ -386,7 +388,7 @@ define([ } events = $._data(this.overlay.get(0), 'events'); events ? this.prevOverlayHandler = events.click[0].handler : false; - this.options.clickableOverlay ? this.overlay.unbind().on('click', this.closeModal) : false; + this.options.clickableOverlay ? this.overlay.unbind().on('click', outerClickHandler) : false; }, /** diff --git a/app/code/Magento/Ui/view/base/web/templates/form/components/button/simple.html b/app/code/Magento/Ui/view/base/web/templates/form/components/button/simple.html new file mode 100644 index 0000000000000000000000000000000000000000..d562e699c843a584fabd5f35905ca5e92ef8ad96 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/templates/form/components/button/simple.html @@ -0,0 +1,7 @@ +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<render args="elementTmpl"/> \ No newline at end of file diff --git a/app/code/Magento/Ui/view/base/web/templates/form/element/button.html b/app/code/Magento/Ui/view/base/web/templates/form/element/button.html new file mode 100644 index 0000000000000000000000000000000000000000..8f337ce7acb966b57b511b1535ceedb6117cdc03 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/templates/form/element/button.html @@ -0,0 +1,14 @@ +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> +<button type="button" + css=" + 'action-advanced': $data.displayAsLink, + 'action-secondary': !$data.displayAsLink + " + click="action" + text="title"> +</button> \ No newline at end of file diff --git a/app/code/Magento/Ui/view/base/web/templates/modal/modal-component.html b/app/code/Magento/Ui/view/base/web/templates/modal/modal-component.html new file mode 100644 index 0000000000000000000000000000000000000000..e39c27e0741232496319e1385a667b181ee623f7 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/templates/modal/modal-component.html @@ -0,0 +1,12 @@ +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +--> + +<div data-bind="css: modalClass"> + <!-- ko foreach: { data: elems, as: 'element' } --> + <!-- ko template: element.getTemplate() --><!-- /ko --> + <!-- /ko --> +</div> \ No newline at end of file diff --git a/app/code/Magento/UrlRewrite/view/adminhtml/templates/categories.phtml b/app/code/Magento/UrlRewrite/view/adminhtml/templates/categories.phtml index 5c27c009b445158c3714fb1464a0c68234537211..420638d5a8ea77aa27b603ba4f8fcdc9d6f4db76 100644 --- a/app/code/Magento/UrlRewrite/view/adminhtml/templates/categories.phtml +++ b/app/code/Magento/UrlRewrite/view/adminhtml/templates/categories.phtml @@ -13,14 +13,14 @@ <div class="content" style="clear: both;"> <input type="hidden" name="categories" id="product_categories" value="" /> <?php if ($block->getRoot()): ?> - <div data-mage-init='<?php + <div data-mage-init="<?php echo $block->escapeHtml($this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode([ 'categoryTree' => [ 'data' => $block->getTreeArray(null), 'url' => $block->getLoadTreeUrl(), ], ])); - ?>' class="jstree-default"></div> + ?>" class="jstree-default"></div> <?php endif; ?> </div> </fieldset> diff --git a/app/code/Magento/Widget/view/adminhtml/templates/catalog/category/widget/tree.phtml b/app/code/Magento/Widget/view/adminhtml/templates/catalog/category/widget/tree.phtml index 135880f5f314214efdc4d95540f489a5fc7bd8fe..89d2b75a3b882322a91f953208242673130ae5b9 100644 --- a/app/code/Magento/Widget/view/adminhtml/templates/catalog/category/widget/tree.phtml +++ b/app/code/Magento/Widget/view/adminhtml/templates/catalog/category/widget/tree.phtml @@ -10,7 +10,7 @@ <?php $_divId = 'tree' . $block->getId() ?> <div id="<?php /* @escapeNotVerified */ echo $_divId ?>" class="tree"></div> -<script id="ie-deferred-loader" defer="defer" src=""></script> +<script id="ie-deferred-loader" defer="defer" src="//:"></script> <script> require(['jquery', "prototype", "extjs/ext-tree-checkbox"], function(jQuery){ diff --git a/app/code/Magento/Widget/view/adminhtml/templates/instance/edit/layout.phtml b/app/code/Magento/Widget/view/adminhtml/templates/instance/edit/layout.phtml index 6831ca32a007b1c5abe9f67b322e76fe5ee38749..a98b8df1fd5deb0e3b50ee395f4a9102cca68083 100644 --- a/app/code/Magento/Widget/view/adminhtml/templates/instance/edit/layout.phtml +++ b/app/code/Magento/Widget/view/adminhtml/templates/instance/edit/layout.phtml @@ -15,7 +15,7 @@ <div class="actions"><?php echo $block->getAddLayoutButtonHtml() ?></div> </div> </fieldset> -<script id="ie-deferred-loader" defer="defer" src=""></script> +<script id="ie-deferred-loader" defer="defer" src="//:"></script> <script> require([ 'jquery',