本文整理匯總了PHP中Magento\Ui\Component\MassAction\Filter::getCollection方法的典型用法代碼示例。如果您正苦於以下問題:PHP Filter::getCollection方法的具體用法?PHP Filter::getCollection怎麽用?PHP Filter::getCollection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Ui\Component\MassAction\Filter
的用法示例。
在下文中一共展示了Filter::getCollection方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
/**
* Update product(s) status action
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$productIds = $collection->getAllIds();
$storeId = (int) $this->getRequest()->getParam('store', 0);
$attributeSetId = (int) $this->getRequest()->getParam('changeattributeset');
try {
foreach ($collection->getItems() as $product) {
//echo get_class($product->getTypeInstance());die();
if ($this->validateConfigurable($product, $attributeSetId, $storeId) == false) {
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
break;
}
$product->setAttributeSetId($attributeSetId)->setStoreId($storeId);
}
$collection->save();
//$product->getTypeInstance();
$this->messageManager->addSuccess(__('A total of %1 record(s) have been updated.', count($productIds)));
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->_getSession()->addException($e, __('Something went wrong while updating the product(s) atrribute set.'));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
}
示例2: executeInternal
/**
* @return \Magento\Framework\Controller\ResultInterface
*/
public function executeInternal()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$this->attributeHelper->setProductIds($collection->getAllIds());
if (!$this->_validateProducts()) {
return $this->resultRedirectFactory->create()->setPath('catalog/product/', ['_current' => true]);
}
$resultPage = $this->resultPageFactory->create();
$resultPage->getConfig()->getTitle()->prepend(__('Update Attributes'));
return $resultPage;
}
示例3: execute
/**
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$productDeleted = 0;
foreach ($collection->getItems() as $product) {
$product->delete();
$productDeleted++;
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $productDeleted));
return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('catalog/*/index');
}
示例4: execute
/**
* Dispatch request
*
* @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $item) {
$item->delete();
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.'), $collectionSize);
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
示例5: execute
/**
* Execute action
*
* @return \Magento\Backend\Model\View\Result\Redirect
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
foreach ($collection as $item) {
$item->setStatus(false);
$item->save();
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been disabled.', $collection->getSize()));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
示例6: executeInternal
/**
* Execute action
*
* @return \Magento\Backend\Model\View\Result\Redirect
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
*/
public function executeInternal()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $page) {
$page->delete();
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collectionSize));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
示例7: execute
/**
* Execute action
*
* @return \Magento\Backend\Model\View\Result\Redirect
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
*/
public function execute()
{
try {
$collection = $this->filter->getCollection($this->collectionFactory->create());
return $this->massAction($collection);
} 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($this->redirectUrl);
}
}
示例8: execute
/**
* Dispatch request
*
* @return \Magento\Framework\Controller\ResultInterface|ResponseInterface
* @throws \Magento\Framework\Exception\NotFoundException
*/
public function execute()
{
/** @var Collection $collection */
$collection = $this->filter->getCollection($this->teaserItemCollectionFactory->create());
/** @var TeaserItem $teaserItem */
foreach ($collection as $teaserItem) {
$teaserItem->delete();
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $collection->getSize()));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
示例9: execute
/**
* execute action
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$delete = 0;
foreach ($collection as $item) {
/** @var \Mageplaza\Blog\Model\Topic $item */
$item->delete();
$delete++;
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
示例10: execute
/**
* Execute action
*
* @return \Magento\Backend\Model\View\Result\Redirect
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
*/
public function execute()
{
$key = 'status';
$value = 1;
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $row) {
$row->setData($key, $value);
$row->save();
}
$this->messageManager->addSuccess(__('A total of %1 record(s) have been changed.', $collectionSize));
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}
示例11: execute
/**
* @return mixed
*/
public function execute()
{
try {
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
foreach ($collection as $article) {
$this->doTheAction($article);
}
$this->messageManager->addSuccess(__($this->successMessage, $collectionSize));
} catch (LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __($this->errorMessage));
}
$redirectResult = $this->resultRedirectFactory->create();
$redirectResult->setPath('gemtoo_blog/*/index');
return $redirectResult;
}
示例12: execute
/**
* Update product(s) status action
*
* @return \Magento\Backend\Model\View\Result\Redirect
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$productIds = $collection->getAllIds();
$storeId = (int) $this->getRequest()->getParam('store', 0);
$status = (int) $this->getRequest()->getParam('status');
try {
$this->_validateMassStatus($productIds, $status);
$this->_objectManager->get('Magento\\Catalog\\Model\\Product\\Action')->updateAttributes($productIds, ['status' => $status], $storeId);
$this->messageManager->addSuccess(__('A total of %1 record(s) have been updated.', count($productIds)));
$this->_productPriceIndexerProcessor->reindexList($productIds);
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->_getSession()->addException($e, __('Something went wrong while updating the product(s) status.'));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('catalog/*/', ['store' => $storeId]);
}
示例13: execute
/**
* Execute action
*
* @return \Magento\Backend\Model\View\Result\Redirect
* @throws \Magento\Framework\Exception\LocalizedException|\Exception
*/
public function execute()
{
$collection = $this->filter->getCollection($this->collectionFactory->create());
$collectionSize = $collection->getSize();
$deletedItems = 0;
foreach ($collection as $synonymGroup) {
try {
$this->synGroupRepository->delete($synonymGroup);
$deletedItems++;
} catch (\Exception $e) {
$this->messageManager->addError($e->getMessage());
}
}
if ($deletedItems != 0) {
if ($collectionSize != $deletedItems) {
$this->messageManager->addError(__('Failed to delete %1 synonym group(s).', $collectionSize - $deletedItems));
}
$this->messageManager->addSuccess(__('A total of %1 synonym group(s) have been deleted.', $deletedItems));
}
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
$resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT);
return $resultRedirect->setPath('*/*/');
}