/**
  * 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]);
 }
 public function setUp()
 {
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false);
     $resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', [], [], '', false);
     $this->responseMock = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false);
     $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', ['create'], [], '', false);
     $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\Manager', [], [], '', false);
     $this->customerCollectionMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->getMock();
     $this->customerCollectionFactoryMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $redirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock();
     $resultFactoryMock->expects($this->any())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($redirectMock);
     $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirectMock);
     $this->contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock);
     $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock);
     $this->contextMock->expects($this->once())->method('getResponse')->willReturn($this->responseMock);
     $this->contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock);
     $this->contextMock->expects($this->any())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory);
     $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($resultFactoryMock);
     $this->filterMock = $this->getMock('Magento\\Ui\\Component\\MassAction\\Filter', [], [], '', false);
     $this->filterMock->expects($this->once())->method('getCollection')->with($this->customerCollectionMock)->willReturnArgument(0);
     $this->customerCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->customerCollectionMock);
     $this->customerRepositoryMock = $this->getMockBuilder('Magento\\Customer\\Api\\CustomerRepositoryInterface')->getMockForAbstractClass();
     $this->massAction = $objectManagerHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\MassAssignGroup', ['context' => $this->contextMock, 'filter' => $this->filterMock, 'collectionFactory' => $this->customerCollectionFactoryMock, 'customerRepository' => $this->customerRepositoryMock]);
 }
Esempio n. 3
0
 /**
  * @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;
 }
Esempio n. 4
0
 /**
  * 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('*/*/');
 }
Esempio n. 5
0
 /**
  * @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');
 }
Esempio n. 6
0
 /**
  * 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('*/*/');
 }
Esempio n. 7
0
 /**
  * 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('*/*/');
 }
Esempio n. 8
0
 /**
  * Execute controller.
  *
  * @return $this
  */
 public function execute()
 {
     $collection = $this->filter->getCollection($this->collectionFactory->create());
     try {
         $this->_allAction($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(static::REDIRECT_URL);
 }
 /**
  * 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('*/*/');
 }
 /**
  * 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('*/*/');
 }
Esempio n. 11
0
 /**
  * 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('*/*/');
 }
Esempio n. 12
0
 public function setUp()
 {
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false);
     $resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', [], [], '', false);
     $this->responseMock = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false);
     $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', [], [], '', false);
     $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\Manager', [], [], '', false);
     $this->orderCollectionMock = $this->getMockBuilder('Magento\\Sales\\Model\\ResourceModel\\Order\\Collection')->disableOriginalConstructor()->getMock();
     $orderCollection = 'Magento\\Sales\\Model\\ResourceModel\\Order\\CollectionFactory';
     $this->orderCollectionFactoryMock = $this->getMockBuilder($orderCollection)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false);
     $this->actionFlagMock = $this->getMock('Magento\\Framework\\App\\ActionFlag', ['get', 'set'], [], '', false);
     $this->helperMock = $this->getMock('\\Magento\\Backend\\Helper\\Data', ['getUrl'], [], '', false);
     $this->resultRedirectMock = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false);
     $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirectMock);
     $redirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock();
     $resultFactoryMock->expects($this->any())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($redirectMock);
     $this->contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock);
     $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock);
     $this->contextMock->expects($this->once())->method('getResponse')->willReturn($this->responseMock);
     $this->contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock);
     $this->contextMock->expects($this->once())->method('getSession')->willReturn($this->sessionMock);
     $this->contextMock->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlagMock);
     $this->contextMock->expects($this->once())->method('getHelper')->willReturn($this->helperMock);
     $this->contextMock->expects($this->once())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory);
     $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($resultFactoryMock);
     $this->filterMock = $this->getMock('Magento\\Ui\\Component\\MassAction\\Filter', [], [], '', false);
     $this->filterMock->expects($this->once())->method('getCollection')->with($this->orderCollectionMock)->willReturn($this->orderCollectionMock);
     $this->orderCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->orderCollectionMock);
     $this->massAction = $objectManagerHelper->getObject('Magento\\Sales\\Controller\\Adminhtml\\Order\\MassUnhold', ['context' => $this->contextMock, 'filter' => $this->filterMock, 'collectionFactory' => $this->orderCollectionFactoryMock]);
 }
Esempio n. 13
0
 public function testExecutePageRequested()
 {
     $this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(['placeholder' => true]);
     $this->request->expects($this->any())->method('getParams')->willReturn(['namespace' => 'product_listing', 'exclude' => true, 'filters' => ['placeholder' => true]]);
     $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]);
     $this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]);
     $collection = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->setMethods(['getAllIds'])->disableOriginalConstructor()->getMock();
     $collection->expects($this->any())->method('getAllIds')->willReturn([1, 2, 3]);
     $this->filter->expects($this->any())->method('getCollection')->with($collection)->willReturn($collection);
     $this->collectionFactory->expects($this->any())->method('create')->willReturn($collection);
     $title = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->setMethods(['prepend'])->disableOriginalConstructor()->getMock();
     $config = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->setMethods(['getTitle'])->disableOriginalConstructor()->getMock();
     $config->expects($this->any())->method('getTitle')->willReturn($title);
     $this->resultPage->expects($this->any())->method('getConfig')->willReturn($config);
     $this->assertSame($this->resultPage, $this->object->execute());
 }
Esempio n. 14
0
 /**
  * @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;
 }
Esempio n. 15
0
 /**
  * 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]);
 }
Esempio n. 16
0
 /**
  * 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('*/*/');
 }
 /**
  * Returns Filters with options
  *
  * @return array
  */
 public function getOptions()
 {
     $options = [];
     $component = $this->filter->getComponent();
     $childComponents = $component->getChildComponents();
     $listingTop = $childComponents['listing_top'];
     foreach ($listingTop->getChildComponents() as $child) {
         if ($child instanceof Filters) {
             foreach ($child->getChildComponents() as $filter) {
                 if ($filter instanceof Select) {
                     $options[$filter->getName()] = $this->getFilterOptions($filter);
                 }
             }
         }
     }
     return $options;
 }
 /**
  * Return component referer url
  * TODO: Technical dept referer url should be implement as a part of Action configuration in in appropriate way
  *
  * @return null|string
  */
 protected function getComponentRefererUrl()
 {
     return $this->filter->getComponentRefererUrl() ?: 'sales/*/';
 }
Esempio n. 19
0
 /**
  * Return component referer url
  * TODO: Technical dept referer url should be implement as a part of Action configuration in in appropriate way
  *
  * @return null|string
  */
 protected function getComponentRefererUrl()
 {
     return $this->filter->getComponentRefererUrl() ?: 'customer/*/index';
 }