Skip to content

Commit

Permalink
MAGETWO-50542: Revert backward incompatible changes for Catalog module
Browse files Browse the repository at this point in the history
  • Loading branch information
Volodymyr Klymenko committed Mar 24, 2016
1 parent 2ad378a commit 90f4dec
Show file tree
Hide file tree
Showing 91 changed files with 1,482 additions and 488 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected function _prepareBundlePriceByType($priceType, $entityIds = null)
'=?',
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
);
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
$this->_addAttributeToSelect($select, 'status', "e.$linkField", 'cs.store_id', $statusCond, true);
if ($this->moduleManager->isEnabled('Magento_Tax')) {
$taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', "e.$linkField", 'cs.store_id');
Expand Down Expand Up @@ -404,7 +404,7 @@ protected function _calculateBundleSelectionPrice($priceType)
);
}

$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
$select = $connection->select()->from(
['i' => $this->_getBundlePriceTable()],
['entity_id', 'customer_group_id', 'website_id']
Expand Down Expand Up @@ -484,7 +484,7 @@ protected function _prepareBundlePrice($entityIds = null)
protected function _prepareTierPriceIndex($entityIds = null)
{
$connection = $this->getConnection();
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
// remove index by bundle products
$select = $connection->select()->from(
['i' => $this->_getTierPriceIndexTable()],
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function _getBundleOptionTable()
protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryTable = false)
{
$this->_cleanBundleOptionStockData();
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
$idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable();
$connection = $this->getConnection();
$select = $connection->select()->from(
Expand Down Expand Up @@ -118,7 +118,7 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT
protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false)
{
$this->_prepareBundleOptionStockData($entityIds, $usePrimaryTable);
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
$connection = $this->getConnection();
$select = $connection->select()->from(
['e' => $this->getTable('catalog_product_entity')],
Expand Down
27 changes: 18 additions & 9 deletions app/code/Magento/Catalog/Controller/Adminhtml/Category/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@ class Edit extends \Magento\Catalog\Controller\Adminhtml\Category
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
*/
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $resultPageFactory,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
parent::__construct($context);
$this->resultPageFactory = $resultPageFactory;
$this->resultJsonFactory = $resultJsonFactory;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -52,20 +49,20 @@ public function __construct(
public function execute()
{
$storeId = (int)$this->getRequest()->getParam('store');
$store = $this->storeManager->getStore($storeId);
$this->storeManager->setCurrentStore($store->getCode());
$store = $this->getStoreManager()->getStore($storeId);
$this->getStoreManager()->setCurrentStore($store->getCode());

$categoryId = (int)$this->getRequest()->getParam('id');

if (!$categoryId) {
if ($storeId) {
$categoryId = (int)$this->storeManager->getStore($storeId)->getRootCategoryId();
$categoryId = (int)$this->getStoreManager()->getStore($storeId)->getRootCategoryId();
} else {
$defaultStoreView = $this->storeManager->getDefaultStoreView();
$defaultStoreView = $this->getStoreManager()->getDefaultStoreView();
if ($defaultStoreView) {
$categoryId = (int)$defaultStoreView->getRootCategoryId();
} else {
$stores = $this->storeManager->getStores();
$stores = $this->getStoreManager()->getStores();
if (count($stores)) {
$store = reset($stores);
$categoryId = (int)$store->getRootCategoryId();
Expand Down Expand Up @@ -109,4 +106,16 @@ public function execute()

return $resultPage;
}

/**
* @return \Magento\Store\Model\StoreManagerInterface
*/
private function getStoreManager()
{
if (null === $this->storeManager) {
$this->storeManager = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Store\Model\StoreManagerInterface');
}
return $this->storeManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AddAttributeToTemplate extends \Magento\Catalog\Controller\Adminhtml\Produ
protected $attributeGroupFactory;

/**
* @var AttributeManagementInterfaces
* @var AttributeManagementInterface
*/
protected $attributeManagement;

Expand All @@ -82,42 +82,15 @@ 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 AttributeRepositoryInterface $attributeRepository
* @param AttributeSetRepositoryInterface $attributeSetRepository
* @param AttributeGroupRepositoryInterface $attributeGroupRepository
* @param AttributeGroupInterfaceFactory $attributeGroupFactory
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param SortOrderBuilder $sortOrderBuilder
* @param AttributeManagementInterface $attributeManagement
* @param LoggerInterface $logger
* @param ExtensionAttributesFactory $extensionAttributesFactory
* @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,
AttributeRepositoryInterface $attributeRepository,
AttributeSetRepositoryInterface $attributeSetRepository,
AttributeGroupRepositoryInterface $attributeGroupRepository,
AttributeGroupInterfaceFactory $attributeGroupFactory,
SearchCriteriaBuilder $searchCriteriaBuilder,
SortOrderBuilder $sortOrderBuilder,
AttributeManagementInterface $attributeManagement,
LoggerInterface $logger,
ExtensionAttributesFactory $extensionAttributesFactory
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
parent::__construct($context, $productBuilder);
$this->resultJsonFactory = $resultJsonFactory;
$this->attributeRepository = $attributeRepository;
$this->attributeSetRepository = $attributeSetRepository;
$this->attributeGroupRepository = $attributeGroupRepository;
$this->attributeGroupFactory = $attributeGroupFactory;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->sortOrderBuilder = $sortOrderBuilder;
$this->attributeManagement = $attributeManagement;
$this->logger = $logger;
$this->extensionAttributesFactory = $extensionAttributesFactory;
}

/**
Expand All @@ -133,22 +106,22 @@ public function execute()

try {
/** @var AttributeSetInterface $attributeSet */
$attributeSet = $this->attributeSetRepository->get($request->getParam('templateId'));
$attributeSet = $this->getAttributeSetRepository()->get($request->getParam('templateId'));
$groupCode = $request->getParam('groupCode');
$groupName = $request->getParam('groupName');
$groupSortOrder = $request->getParam('groupSortOrder');

$attributeSearchCriteria = $this->getBasicAttributeSearchCriteriaBuilder()->create();
$attributeGroupSearchCriteria = $this->searchCriteriaBuilder
$attributeGroupSearchCriteria = $this->getSearchCriteriaBuilder()
->addFilter('attribute_set_id', $attributeSet->getAttributeSetId())
->addFilter('attribute_group_code', $groupCode)
->addSortOrder($this->sortOrderBuilder->setAscendingDirection()->create())
->addSortOrder($this->getSortOrderBuilder()->setAscendingDirection()->create())
->setPageSize(1)
->create();

try {
/** @var AttributeGroupInterface[] $attributeGroupItems */
$attributeGroupItems = $this->attributeGroupRepository->getList($attributeGroupSearchCriteria)
$attributeGroupItems = $this->getAttributeGroupRepository()->getList($attributeGroupSearchCriteria)
->getItems();

if (!$attributeGroupItems) {
Expand All @@ -159,28 +132,28 @@ public function execute()
$attributeGroup = reset($attributeGroupItems);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
/** @var AttributeGroupInterface $attributeGroup */
$attributeGroup = $this->attributeGroupFactory->create();
$attributeGroup = $this->getAttributeGroupFactory()->create();
}

$extensionAttributes = $attributeGroup->getExtensionAttributes()
?: $this->extensionAttributesFactory->create(AttributeGroupInterface::class);
?: $this->getExtensionAttributesFactory()->create(AttributeGroupInterface::class);

$extensionAttributes->setAttributeGroupCode($groupCode);
$extensionAttributes->setSortOrder($groupSortOrder);
$attributeGroup->setAttributeGroupName($groupName);
$attributeGroup->setAttributeSetId($attributeSet->getAttributeSetId());
$attributeGroup->setExtensionAttributes($extensionAttributes);

$this->attributeGroupRepository->save($attributeGroup);
$this->getAttributeGroupRepository()->save($attributeGroup);

/** @var AttributeInterface[] $attributesItems */
$attributesItems = $this->attributeRepository->getList(
$attributesItems = $this->getAttributeRepository()->getList(
ProductAttributeInterface::ENTITY_TYPE_CODE,
$attributeSearchCriteria
)->getItems();

array_walk($attributesItems, function (AttributeInterface $attribute) use ($attributeSet, $attributeGroup) {
$this->attributeManagement->assign(
$this->getAttributeManagement()->assign(
ProductAttributeInterface::ENTITY_TYPE_CODE,
$attributeSet->getAttributeSetId(),
$attributeGroup->getAttributeGroupId(),
Expand All @@ -192,7 +165,7 @@ public function execute()
$response->setError(true);
$response->setMessage($e->getMessage());
} catch (\Exception $e) {
$this->logger->critical($e);
$this->getLogger()->critical($e);
$response->setError(true);
$response->setMessage(__('Unable to add attribute'));
}
Expand All @@ -214,8 +187,116 @@ private function getBasicAttributeSearchCriteriaBuilder()
throw new LocalizedException(__('Please, specify attributes'));
}

return $this->searchCriteriaBuilder
return $this->getSearchCriteriaBuilder()
->addFilter('attribute_set_id', new \Zend_Db_Expr('null'), 'is')
->addFilter('attribute_id', [$attributeIds['selected']], 'in');
}

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

/**
* @return AttributeSetRepositoryInterface
*/
private function getAttributeSetRepository()
{
if (null === $this->attributeSetRepository) {
$this->attributeSetRepository = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Catalog\Api\AttributeSetRepositoryInterface');
}
return $this->attributeSetRepository;
}

/**
* @return AttributeGroupRepositoryInterface
*/
private function getAttributeGroupRepository()
{
if (null === $this->attributeGroupRepository) {
$this->attributeGroupRepository = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Eav\Api\AttributeGroupRepositoryInterface');
}
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
*/
private function getSearchCriteriaBuilder()
{
if (null === $this->searchCriteriaBuilder) {
$this->searchCriteriaBuilder = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Framework\Api\SearchCriteriaBuilder');
}
return $this->searchCriteriaBuilder;
}

/**
* @return SortOrderBuilder
*/
private function getSortOrderBuilder()
{
if (null === $this->sortOrderBuilder) {
$this->sortOrderBuilder = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Framework\Api\SortOrderBuilder');
}
return $this->sortOrderBuilder;
}

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

/**
* @return LoggerInterface
*/
private function getLogger()
{
if (null === $this->logger) {
$this->logger = \Magento\Framework\App\ObjectManager::getInstance()
->get('Psr\Log\LoggerInterface');
}
return $this->logger;
}

/**
* @return ExtensionAttributesFactory
*/
private function getExtensionAttributesFactory()
{
if (null === $this->extensionAttributesFactory) {
$this->extensionAttributesFactory = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Framework\Api\ExtensionAttributesFactory');
}
return $this->extensionAttributesFactory;
}
}
22 changes: 16 additions & 6 deletions app/code/Magento/Catalog/Controller/Adminhtml/Product/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,18 @@ class Builder
* @param Logger $logger
* @param Registry $registry
* @param WysiwygModel\Config $wysiwygConfig
* @param StoreFactory $storeFactory
*/
public function __construct(
ProductFactory $productFactory,
Logger $logger,
Registry $registry,
WysiwygModel\Config $wysiwygConfig,
StoreFactory $storeFactory
) {
WysiwygModel\Config $wysiwygConfig
)
{
$this->productFactory = $productFactory;
$this->logger = $logger;
$this->registry = $registry;
$this->wysiwygConfig = $wysiwygConfig;
$this->storeFactory = $storeFactory;
}

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

$typeId = $request->getParam('type');
Expand Down Expand Up @@ -102,4 +100,16 @@ 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;
}
}
Loading

0 comments on commit 90f4dec

Please sign in to comment.