Skip to content

Commit

Permalink
Merge pull request #507 from magento-firedrakes/MAGETWO-39905
Browse files Browse the repository at this point in the history
[Firedrakes] UI components compatibility with Search API
  • Loading branch information
vpelipenko committed Aug 10, 2015
2 parents f93986f + 7987275 commit 1fb448a
Show file tree
Hide file tree
Showing 152 changed files with 5,715 additions and 5,465 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,58 @@
*/
namespace Magento\Catalog\Controller\Adminhtml\Product;

use Magento\Catalog\Model\Resource\Product\Collection;
use Magento\Framework\Controller\ResultFactory;
use Magento\Catalog\Controller\Adminhtml\Product\Builder;
use Magento\Backend\App\Action\Context;
use Magento\Ui\Component\MassAction\Filter;
use Magento\Catalog\Model\Resource\Product\CollectionFactory;

class MassDelete extends \Magento\Catalog\Controller\Adminhtml\Product
{
/**
* Field id
* Massactions filter
*
* @var Filter
*/
const ID_FIELD = 'entity_id';
protected $filter;

/**
* Redirect url
* @var CollectionFactory
*/
const REDIRECT_URL = 'catalog/*/index';
protected $collectionFactory;

/**
* Resource collection
*
* @var string
* @param Context $context
* @param Builder $productBuilder
* @param Filter $filter
* @param CollectionFactory $collectionFactory
*/
protected $collection = 'Magento\Catalog\Model\Resource\Product\Collection';
public function __construct(
Context $context,
Builder $productBuilder,
Filter $filter,
CollectionFactory $collectionFactory
) {
$this->filter = $filter;
$this->collectionFactory = $collectionFactory;
parent::__construct($context, $productBuilder);
}

/**
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$selected = $this->getRequest()->getParam('selected');
$excluded = $this->getRequest()->getParam('excluded');

$collection = $this->_objectManager->create($this->collection);
try {
if (!empty($excluded)) {
$collection->addFieldToFilter(static::ID_FIELD, ['nin' => $excluded]);
$this->massAction($collection);
} elseif (!empty($selected)) {
$collection->addFieldToFilter(static::ID_FIELD, ['in' => $selected]);
$this->massAction($collection);
} else {
$this->messageManager->addError(__('Please select product(s).'));
}
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
}

/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath(static::REDIRECT_URL);
}

/**
* Cancel selected orders
*
* @param Collection $collection
* @return void
*/
protected function massAction($collection)
{
$count = 0;
$collection = $this->filter->getCollection($this->collectionFactory->create());
$productDeleted = 0;
foreach ($collection->getItems() as $product) {
$product->delete();
++$count;
$productDeleted++;
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $count));
$this->messageManager->addSuccess(
__('A total of %1 record(s) have been deleted.', $productDeleted)
);

return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('catalog/*/index');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class Collection extends \Magento\Catalog\Model\Resource\Collection\AbstractColl
*/
const MAIN_TABLE_ALIAS = 'e';

/**
* @var string
*/
protected $_idFieldName = 'entity_id';

/**
* Catalog Product Flat is enabled cache per store
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct(StoreManagerInterface $storeManager)
public function addFilter(Collection $collection, $field, $condition = null)
{
if (isset($condition['eq']) && $condition['eq']) {
/** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */
$collection->addStoreFilter($this->storeManager->getStore($condition['eq']));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ public function __construct(
$this->addFilterStrategies = $addFilterStrategies;
}

/**
* Get collection
*
* @return \Magento\Catalog\Model\Resource\Product\Collection
*/
protected function getCollection()
{
return $this->collection;
}

/**
* Get data
*
Expand Down Expand Up @@ -104,12 +94,17 @@ public function addField($field, $alias = null)
/**
* {@inheritdoc}
*/
public function addFilter($condition, $field = null, $type = 'regular')
public function addFilter(\Magento\Framework\Api\Filter $filter)
{
if (isset($this->addFilterStrategies[$field])) {
$this->addFilterStrategies[$field]->addFilter($this->getCollection(), $field, $condition);
if (isset($this->addFilterStrategies[$filter->getField()])) {
$this->addFilterStrategies[$filter->getField()]
->addFilter(
$this->getCollection(),
$filter->getField(),
[$filter->getConditionType() => $filter->getValue()]
);
} else {
parent::addFilter($condition, $field);
parent::addFilter($filter);
}
}
}
145 changes: 0 additions & 145 deletions app/code/Magento/Cms/Controller/Adminhtml/AbstractMassDelete.php

This file was deleted.

Loading

0 comments on commit 1fb448a

Please sign in to comment.