Skip to content

Commit

Permalink
Merge pull request #1835 from magento-panda/PANDA-FIXES-2.1
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-83631: [Backport for 2.1.x] Loaded quote items collection contains removed product items
- MAGETWO-72312: Incorrect count for category filter at layered navigation for configurable with no available options
- MAGETWO-69036: Lazy-loaders cause fatal errors in production mode on cloud
  • Loading branch information
dvoskoboinikov authored Dec 12, 2017
2 parents 95eaf87 + 3f9d515 commit 477f536
Show file tree
Hide file tree
Showing 83 changed files with 3,108 additions and 1,166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,23 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
* @param \Magento\Backend\App\Action\Context $context
* @param Builder $productBuilder
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param AttributeGroupInterfaceFactory|null $attributeGroupFactory
* @throws \RuntimeException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Catalog\Controller\Adminhtml\Product\Builder $productBuilder,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Eav\Api\Data\AttributeGroupInterfaceFactory $attributeGroupFactory = null
) {
parent::__construct($context, $productBuilder);
$this->resultJsonFactory = $resultJsonFactory;
if (null === $attributeGroupFactory) {
$attributeGroupFactory = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Eav\Api\Data\AttributeGroupInterfaceFactory::class);
}
$this->attributeGroupFactory = $attributeGroupFactory;
}

/**
Expand Down Expand Up @@ -132,7 +140,7 @@ public function execute()
$attributeGroup = reset($attributeGroupItems);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
/** @var AttributeGroupInterface $attributeGroup */
$attributeGroup = $this->getAttributeGroupFactory()->create();
$attributeGroup = $this->attributeGroupFactory->create();
}

$extensionAttributes = $attributeGroup->getExtensionAttributes()
Expand Down Expand Up @@ -228,18 +236,6 @@ private function getAttributeGroupRepository()
return $this->attributeGroupRepository;
}

/**
* @return AttributeGroupInterfaceFactory
*/
private function getAttributeGroupFactory()
{
if (null === $this->attributeGroupFactory) {
$this->attributeGroupFactory = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Eav\Api\Data\AttributeGroupInterfaceFactory');
}
return $this->attributeGroupFactory;
}

/**
* @return SearchCriteriaBuilder
*/
Expand Down
24 changes: 10 additions & 14 deletions app/code/Magento/Catalog/Controller/Adminhtml/Product/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ class Builder
* @param Logger $logger
* @param Registry $registry
* @param WysiwygModel\Config $wysiwygConfig
* @param StoreFactory|null $storeFactory
* @throws \RuntimeException
*/
public function __construct(
ProductFactory $productFactory,
Logger $logger,
Registry $registry,
WysiwygModel\Config $wysiwygConfig
WysiwygModel\Config $wysiwygConfig,
StoreFactory $storeFactory = null
) {
$this->productFactory = $productFactory;
$this->logger = $logger;
$this->registry = $registry;
$this->wysiwygConfig = $wysiwygConfig;
if (null === $storeFactory) {
$storeFactory = \Magento\Framework\App\ObjectManager::getInstance()
->get(StoreFactory::class);
}
$this->storeFactory = $storeFactory;
}

/**
Expand All @@ -70,7 +78,7 @@ public function build(RequestInterface $request)
/** @var $product \Magento\Catalog\Model\Product */
$product = $this->productFactory->create();
$product->setStoreId($request->getParam('store', 0));
$store = $this->getStoreFactory()->create();
$store = $this->storeFactory->create();
$store->load($request->getParam('store', 0));

$typeId = $request->getParam('type');
Expand Down Expand Up @@ -99,16 +107,4 @@ public function build(RequestInterface $request)
$this->wysiwygConfig->setStoreId($request->getParam('store'));
return $product;
}

/**
* @return StoreFactory
*/
private function getStoreFactory()
{
if (null === $this->storeFactory) {
$this->storeFactory = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Store\Model\StoreFactory');
}
return $this->storeFactory;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
*/
namespace Magento\Catalog\Controller\Adminhtml\Product\Initialization;

use Magento\Backend\Helper\Js;
use Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory as CustomOptionFactory;
use Magento\Catalog\Api\Data\ProductLinkInterfaceFactory as ProductLinkFactory;
use Magento\Catalog\Api\ProductRepositoryInterface\Proxy as ProductRepository;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks;
use Magento\Catalog\Model\Product\Link\Resolver as LinkResolver;
use Magento\Catalog\Model\Product\LinkTypeProvider;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Stdlib\DateTime\Filter\Date as DateFilter;
use Magento\Framework\Stdlib\DateTime\Filter\DateTime;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class Helper
Expand All @@ -20,12 +26,12 @@
class Helper
{
/**
* @var \Magento\Framework\App\RequestInterface
* @var RequestInterface
*/
protected $request;

/**
* @var \Magento\Store\Model\StoreManagerInterface
* @var StoreManagerInterface
*/
protected $storeManager;

Expand All @@ -35,12 +41,12 @@ class Helper
protected $stockFilter;

/**
* @var \Magento\Backend\Helper\Js
* @var Js
*/
protected $jsHelper;

/**
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
* @var Date
*
* @deprecated
*/
Expand Down Expand Up @@ -72,42 +78,76 @@ class Helper
private $linkResolver;

/**
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
* @var DateTime
*/
private $dateTimeFilter;

/**
* @var \Magento\Catalog\Model\Product\LinkTypeProvider
* @var LinkTypeProvider
*/
private $linkTypeProvider;

/**
* Helper constructor.
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param RequestInterface $request
* @param StoreManagerInterface $storeManager
* @param StockDataFilter $stockFilter
* @param ProductLinks $productLinks
* @param \Magento\Backend\Helper\Js $jsHelper
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
* @param Js $jsHelper
* @param DateFilter $dateFilter
* @param LinkTypeProvider|null $linkTypeProvider
* @param CustomOptionFactory|null $customOptionFactory
* @param ProductLinkFactory|null $productLinkFactory
* @param ProductRepository|null $productRepository
* @param DateTime|null $dateTimeFilter
* @param LinkResolver|null $linkResolver
* @throws \RuntimeException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Framework\App\RequestInterface $request,
\Magento\Store\Model\StoreManagerInterface $storeManager,
RequestInterface $request,
StoreManagerInterface $storeManager,
StockDataFilter $stockFilter,
\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $productLinks,
\Magento\Backend\Helper\Js $jsHelper,
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider = null
ProductLinks $productLinks,
Js $jsHelper,
DateFilter $dateFilter,
LinkTypeProvider $linkTypeProvider = null,
CustomOptionFactory $customOptionFactory = null,
ProductLinkFactory $productLinkFactory = null,
ProductRepository $productRepository = null,
DateTime $dateTimeFilter = null,
LinkResolver $linkResolver = null
) {
if (null === $linkTypeProvider) {
$linkTypeProvider = ObjectManager::getInstance()->get(LinkTypeProvider::class);
}
if (null === $customOptionFactory) {
$customOptionFactory = ObjectManager::getInstance()->get(CustomOptionFactory::class);
}
if (null === $productLinkFactory) {
$productLinkFactory = ObjectManager::getInstance()->get(ProductLinkFactory::class);
}
if (null === $productRepository) {
$productRepository = ObjectManager::getInstance()->get(ProductRepository::class);
}
if (null === $dateTimeFilter) {
$dateTimeFilter = ObjectManager::getInstance()->get(DateTime::class);
}
if (null === $linkResolver) {
$linkResolver = ObjectManager::getInstance()->get(LinkResolver::class);
}
$this->request = $request;
$this->storeManager = $storeManager;
$this->stockFilter = $stockFilter;
$this->productLinks = $productLinks;
$this->jsHelper = $jsHelper;
$this->dateFilter = $dateFilter;
$this->linkTypeProvider = $linkTypeProvider ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Model\Product\LinkTypeProvider::class);
$this->linkTypeProvider = $linkTypeProvider;
$this->customOptionFactory = $customOptionFactory;
$this->productLinkFactory = $productLinkFactory;
$this->productRepository = $productRepository;
$this->dateTimeFilter = $dateTimeFilter;
$this->linkResolver = $linkResolver;
}

/**
Expand Down Expand Up @@ -159,7 +199,7 @@ public function initializeFromData(Product $product, array $productData)
foreach ($attributes as $attrKey => $attribute) {
if ($attribute->getBackend()->getType() == 'datetime') {
if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
$dateFieldFilters[$attrKey] = $this->dateTimeFilter;
}
}
}
Expand Down Expand Up @@ -222,11 +262,12 @@ public function initialize(Product $product)
*
* @param Product $product
* @return Product
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function setProductLinks(Product $product)
{
$links = $this->getLinkResolver()->getLinks();
$links = $this->linkResolver->getLinks();

$product->setProductLinks([]);

Expand All @@ -251,8 +292,8 @@ protected function setProductLinks(Product $product)
continue;
}

$linkProduct = $this->getProductRepository()->getById($linkData['id']);
$link = $this->getProductLinkFactory()->create();
$linkProduct = $this->productRepository->getById($linkData['id']);
$link = $this->productLinkFactory->create();
$link->setSku($product->getSku())
->setLinkedProductSku($linkProduct->getSku())
->setLinkType($linkType)
Expand Down Expand Up @@ -360,73 +401,6 @@ private function overwriteValue($optionId, $option, $overwriteOptions)
return $option;
}

/**
* @return CustomOptionFactory
*/
private function getCustomOptionFactory()
{
if (null === $this->customOptionFactory) {
$this->customOptionFactory = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class);
}

return $this->customOptionFactory;
}

/**
* @return ProductLinkFactory
*/
private function getProductLinkFactory()
{
if (null === $this->productLinkFactory) {
$this->productLinkFactory = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Api\Data\ProductLinkInterfaceFactory::class);
}

return $this->productLinkFactory;
}

/**
* @return ProductRepository
*/
private function getProductRepository()
{
if (null === $this->productRepository) {
$this->productRepository = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Catalog\Api\ProductRepositoryInterface\Proxy::class);
}

return $this->productRepository;
}

/**
* @deprecated
* @return LinkResolver
*/
private function getLinkResolver()
{
if (!is_object($this->linkResolver)) {
$this->linkResolver = ObjectManager::getInstance()->get(LinkResolver::class);
}

return $this->linkResolver;
}

/**
* @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
*
* @deprecated
*/
private function getDateTimeFilter()
{
if ($this->dateTimeFilter === null) {
$this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class);
}

return $this->dateTimeFilter;
}

/**
* Fills $product with options from $productOptions array
*
Expand Down Expand Up @@ -464,7 +438,7 @@ function ($valueData) {
}
);
}
$customOption = $this->getCustomOptionFactory()->create(
$customOption = $this->customOptionFactory->create(
['data' => $customOptionData]
);
$customOption->setProductSku($product->getSku());
Expand Down
9 changes: 6 additions & 3 deletions app/code/Magento/Catalog/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ public function getParentId()
return $parentId;
}
$parentIds = $this->getParentIds();
return intval(array_pop($parentIds));
return (int)array_pop($parentIds);
}

/**
Expand Down Expand Up @@ -938,8 +938,11 @@ public function getAnchorsAbove()
*/
public function getProductCount()
{
$count = $this->_getResource()->getProductCount($this);
$this->setData(self::KEY_PRODUCT_COUNT, $count);
if (!$this->hasData(self::KEY_PRODUCT_COUNT)) {
$count = $this->_getResource()->getProductCount($this);
$this->setData(self::KEY_PRODUCT_COUNT, $count);
}

return $this->getData(self::KEY_PRODUCT_COUNT);
}

Expand Down
Loading

0 comments on commit 477f536

Please sign in to comment.