示例#1
0
 /**
  * Post new product
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $resultRedirect = $this->resultRedirectFactory->create();
     $request = $this->getRequest();
     $post = $request->getPostValue();
     if (!$post) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     /** @var \TurgayOzgur\C2C\Model\ProductFromCustomer $product */
     $product = $this->initializationHelper->initialize($this->productBuilder->build($request));
     $this->productTypeManager->processProduct($product);
     $imagePaths = $request->getParam('image');
     if ($imagePaths) {
         $isFirst = true;
         foreach ($imagePaths as $path) {
             $product->addImageToMediaGallery($path, $isFirst ? ['image', 'small_image', 'thumbnail'] : null, false, false);
             $isFirst = false;
         }
     }
     $product->setTypeId('simple');
     // Simple.
     $product->setAttributeSetId(4);
     // Default.
     $product->setStatus(1);
     // 1 - Enable, 2 - Disable.
     $product->setVisibility(4);
     $product->setSku($product->getName());
     $product->setCustomerId($this->_getSession()->getCustomerId());
     $product->save();
     $resultRedirect->setPath('C2C/customerproducts');
     return $resultRedirect;
 }
 protected function setUp()
 {
     $this->productBuilder = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Builder', ['build'], [], '', false);
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['addData', 'getSku', 'getTypeId', 'getStoreId', '__sleep', '__wakeup', 'getAttributes', 'setAttributeSetId'])->getMock();
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple'));
     $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue('1'));
     $this->product->expects($this->any())->method('getAttributes')->will($this->returnValue([]));
     $this->productBuilder->expects($this->any())->method('build')->will($this->returnValue($this->product));
     $this->resultPage = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Page')->disableOriginalConstructor()->getMock();
     $resultPageFactory = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resultPageFactory->expects($this->any())->method('create')->willReturn($this->resultPage);
     $this->resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->getMock();
     $resultForwardFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resultForwardFactory->expects($this->any())->method('create')->willReturn($this->resultForward);
     $this->resultPage->expects($this->any())->method('getLayout')->willReturn($this->layout);
     $this->resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', ['create'], [], '', false);
     $this->resultRedirect = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false);
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
     $this->initializationHelper = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper', [], [], '', false);
     $this->productFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\ProductFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->productFactory->expects($this->any())->method('create')->willReturn($this->product);
     $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false);
     $this->resultJsonFactory = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\JsonFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->resultJsonFactory->expects($this->any())->method('create')->willReturn($this->resultJson);
     $additionalParams = ['resultRedirectFactory' => $this->resultRedirectFactory];
     $this->action = (new ObjectManagerHelper($this))->getObject('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Validate', ['context' => $this->initContext($additionalParams), 'productBuilder' => $this->productBuilder, 'resultPageFactory' => $resultPageFactory, 'resultForwardFactory' => $resultForwardFactory, 'initializationHelper' => $this->initializationHelper, 'resultJsonFactory' => $this->resultJsonFactory, 'productFactory' => $this->productFactory]);
 }
示例#3
0
 /**
  * Get product reviews grid
  *
  * @return void
  */
 public function execute()
 {
     $product = $this->productBuilder->build($this->getRequest());
     $this->_view->loadLayout();
     $this->_view->getLayout()->getBlock('admin.product.reviews')->setProductId($product->getId())->setUseAjax(true);
     $this->_view->renderLayout();
 }
 /**
  * Add "super" attribute from popup window
  *
  * @return void
  */
 public function execute()
 {
     $this->_view->loadLayout('popup');
     $this->productBuilder->build($this->getRequest());
     $attributeBlock = $this->_view->getLayout()->createBlock('Magento\\ConfigurableProduct\\Block\\Adminhtml\\Product\\Attribute\\NewAttribute\\Product\\Created');
     $this->_addContent($attributeBlock);
     $this->_view->renderLayout();
 }
示例#5
0
 /**
  * {@inheritdoc}
  */
 public function execute()
 {
     $this->productBuilder->build($this->getRequest());
     /** @var \Magento\Framework\View\Result\Layout $resultLayout */
     $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_PAGE);
     $resultLayout->getLayout()->getUpdate()->removeHandle('default');
     return $resultLayout;
 }
示例#6
0
 /**
  * Get product reviews grid
  *
  * @return \Magento\Framework\View\Result\Layout
  */
 public function execute()
 {
     $product = $this->productBuilder->build($this->getRequest());
     /** @var \Magento\Framework\View\Result\Layout $resultLayout */
     $resultLayout = $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
     $resultLayout->getLayout()->getBlock('admin.product.reviews')->setProductId($product->getId())->setUseAjax(true);
     return $resultLayout;
 }
 public function testExecute()
 {
     $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock();
     $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product);
     $resultLayout = $this->getMock(\Magento\Framework\View\Result\Layout::class, [], [], '', false);
     $this->resultFactory->expects($this->once())->method('create')->with(ResultFactory::TYPE_LAYOUT)->willReturn($resultLayout);
     $this->assertInstanceOf(\Magento\Framework\View\Result\Layout::class, $this->controller->execute());
 }
示例#8
0
 public function testExecute()
 {
     $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock();
     $layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface');
     $block = $this->getMockBuilder('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Bundle')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock();
     $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product);
     $this->initializationHelper->expects($this->any())->method('initialize')->willReturn($product);
     $this->response->expects($this->once())->method('setBody')->willReturnSelf();
     $this->view->expects($this->once())->method('getLayout')->willReturn($layout);
     $layout->expects($this->once())->method('createBlock')->willReturn($block);
     $block->expects($this->once())->method('toHtml')->willReturnSelf();
     $this->controller->execute();
 }
 public function testExecute()
 {
     $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock();
     $layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface');
     $block = $this->getMockBuilder('Magento\\ConfigurableProduct\\Block\\Adminhtml\\Product\\Attribute\\NewAttribute\\Product\\Created')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock();
     $this->view->expects($this->once())->method('loadLayout')->with('popup')->willReturnSelf();
     $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product);
     $this->view->expects($this->any())->method('getLayout')->willReturn($layout);
     $layout->expects($this->once())->method('createBlock')->willReturn($block);
     $layout->expects($this->once())->method('setChild')->willReturnSelf();
     $this->view->expects($this->any())->method('renderLayout')->willReturnSelf();
     $this->controller->execute();
 }
示例#10
0
 protected function setUp()
 {
     $this->productBuilder = $this->getMock('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Builder', ['build'], [], '', false);
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['addData', 'getTypeId', 'getStoreId', '__sleep', '__wakeup'])->getMock();
     $this->product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple'));
     $this->product->expects($this->any())->method('getStoreId')->will($this->returnValue('1'));
     $this->productBuilder->expects($this->any())->method('build')->will($this->returnValue($this->product));
     $this->resultPage = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Page')->disableOriginalConstructor()->getMock();
     $resultPageFactory = $this->getMockBuilder('Magento\\Framework\\View\\Result\\PageFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resultPageFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->resultPage);
     $this->resultForward = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Forward')->disableOriginalConstructor()->getMock();
     $resultForwardFactory = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\ForwardFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $resultForwardFactory->expects($this->any())->method('create')->willReturn($this->resultForward);
     $this->action = new \Magento\Catalog\Controller\Adminhtml\Product\NewAction($this->initContext(), $this->productBuilder, $this->getMockBuilder('Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\StockDataFilter')->disableOriginalConstructor()->getMock(), $resultPageFactory, $resultForwardFactory);
     $this->resultPage->expects($this->atLeastOnce())->method('getLayout')->willReturn($this->layout);
 }
示例#11
0
文件: Index.php 项目: aiesh/magento2
 /**
  * Generate product variations matrix
  *
  * @return void
  */
 public function execute()
 {
     $this->_saveAttributeOptions();
     $this->getRequest()->setParam('variations-matrix', array());
     $this->initializationHelper->initialize($this->productBuilder->build($this->getRequest()));
     $this->_view->loadLayout();
     $this->_view->renderLayout();
 }
示例#12
0
 /**
  * {@inheritdoc}
  */
 public function build(\Magento\Framework\App\RequestInterface $request)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'build');
     if (!$pluginInfo) {
         return parent::build($request);
     } else {
         return $this->___callPlugins('build', func_get_args(), $pluginInfo);
     }
 }
示例#13
0
 /**
  * get current product
  * @return \Magento\Catalog\Model\Product
  */
 public function getProduct()
 {
     if (is_null($this->_product)) {
         if ($this->registry->registry('current_product')) {
             $this->_product = $this->registry->registry('current_product');
         } else {
             $product = $this->productBuilder->build($this->getRequest());
             $this->_product = $product;
         }
     }
     return $this->_product;
 }
示例#14
0
 protected function setUp()
 {
     $this->objectManager = new ObjectManager($this);
     $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
     $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)->disableOriginalConstructor()->getMock();
     $this->layoutMock = $this->getMockBuilder(LayoutInterface::class)->disableOriginalConstructor()->getMock();
     $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
     $this->productBuilderMock = $this->getMockBuilder(Builder::class)->disableOriginalConstructor()->getMock();
     $this->resultMock = $this->getMockBuilder(ResultInterface::class)->setMethods(['forward', 'setJsonData', 'getLayout'])->getMockForAbstractClass();
     $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass();
     $this->uiComponentMock = $this->getMockBuilder(UiComponent::class)->disableOriginalConstructor()->getMock();
     $this->processorMock = $this->getMockBuilder(ProcessorInterface::class)->getMockForAbstractClass();
     $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock);
     $this->resultFactoryMock->expects($this->any())->method('create')->willReturn($this->resultMock);
     $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock);
     $this->productBuilderMock->expects($this->any())->method('build')->willReturn($this->productMock);
     $this->layoutMock->expects($this->any())->method('getBlock')->willReturn($this->uiComponentMock);
     $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->processorMock);
     $this->resultMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock);
     $this->model = $this->objectManager->getObject(Reload::class, ['context' => $this->contextMock, 'productBuilder' => $this->productBuilderMock, 'layout' => $this->layoutMock]);
 }
示例#15
0
 public function testBuildWhenProductNotExist()
 {
     $valueMap = [['id', null, null], ['store', 0, 'some_store'], ['type', null, 'type_id'], ['set', null, 3], ['store', null, 'store']];
     $this->requestMock->expects($this->any())->method('getParam')->will($this->returnValueMap($valueMap));
     $this->productFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->productMock));
     $this->productMock->expects($this->once())->method('setStoreId')->with('some_store')->will($this->returnSelf());
     $productValueMap = [['type_id', $this->productMock], [\Magento\Catalog\Model\Product\Type::DEFAULT_TYPE, $this->productMock]];
     $this->productMock->expects($this->any())->method('setTypeId')->will($this->returnValueMap($productValueMap));
     $this->productMock->expects($this->never())->method('load');
     $this->productMock->expects($this->once())->method('setAttributeSetId')->with(3)->will($this->returnSelf());
     $registryValueMap = [['product', $this->productMock, $this->registryMock], ['current_product', $this->productMock, $this->registryMock]];
     $this->registryMock->expects($this->any())->method('register')->will($this->returnValueMap($registryValueMap));
     $this->wysiwygConfigMock->expects($this->once())->method('setStoreId')->with('store');
     $this->assertEquals($this->productMock, $this->builder->build($this->requestMock));
 }
示例#16
0
 /**
  * @inheritdoc
  */
 public function execute()
 {
     $this->productBuilder->build($this->getRequest());
     return $this->resultFactory->create(ResultFactory::TYPE_LAYOUT);
 }
示例#17
0
 /**
  * @return void
  */
 public function execute()
 {
     $this->productBuilder->build($this->getRequest());
     $this->_view->loadLayout(false);
     $this->_view->renderLayout();
 }