Example #1
0
 protected function setUp()
 {
     $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     $this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\ConfigurableProduct\\Block\\Product\\View\\Type\\Configurable');
     $this->_block->setProduct($this->_product);
 }
Example #2
0
 /**
  * @magentoDataFixture Magento/Catalog/_files/row_fixture.php
  * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
  * @magentoAppArea frontend
  */
 public function testProductUpdate()
 {
     $this->markTestSkipped('Incomplete due to MAGETWO-21369');
     $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\CategoryFactory');
     $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Block\\Product\\ListProduct');
     $this->_processor->getIndexer()->setScheduled(false);
     $this->assertFalse($this->_processor->getIndexer()->isScheduled(), 'Indexer is in scheduled mode when turned to update on save mode');
     $this->_processor->reindexAll();
     $this->_product->load(1);
     $this->_product->setName('Updated Product');
     $this->_product->save();
     $category = $categoryFactory->create()->load(9);
     $layer = $listProduct->getLayer();
     $layer->setCurrentCategory($category);
     /** @var \Magento\Catalog\Model\Resource\Product\Collection $productCollection */
     $productCollection = $layer->getProductCollection();
     $this->assertTrue($productCollection->isEnabledFlat(), 'Product collection is not using flat resource when flat is on');
     $this->assertEquals(2, $productCollection->count(), 'Product collection items count must be exactly 2');
     foreach ($productCollection as $product) {
         /** @var $product \Magento\Catalog\Model\Product */
         if ($product->getId() == 1) {
             $this->assertEquals('Updated Product', $product->getName(), 'Product name from flat does not match with updated name');
         }
     }
 }
 protected function prepareProducts()
 {
     $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save();
     $this->productSecond = clone $this->product;
     $this->productSecond->setId(null)->setUrlKey('product-second')->save();
     $this->productThird = clone $this->product;
     $this->productThird->setId(null)->setUrlKey('product-third')->setData('test_attribute', 'NO_test_attribute_value')->save();
 }
 protected function setUp()
 {
     $this->productRepository = Bootstrap::getObjectManager()->create(ProductRepositoryInterface::class);
     $this->product = Bootstrap::getObjectManager()->create(Product::class);
     $this->product->load(1);
     $this->model = Bootstrap::getObjectManager()->create(Configurable::class);
     // prevent fatal errors by assigning proper "singleton" of type instance to the product
     $this->product->setTypeInstance($this->model);
 }
 protected function setUp()
 {
     $this->_product = Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     $this->_model = Bootstrap::getObjectManager()->create('Magento\\ConfigurableProduct\\Model\\Product\\VariationHandler');
     // prevent fatal errors by assigning proper "singleton" of type instance to the product
     $this->_product->setTypeInstance($this->_model);
     $this->stockRegistry = Bootstrap::getObjectManager()->get('Magento\\CatalogInventory\\Api\\StockRegistryInterface');
 }
 public function testGetAttributes()
 {
     // fixture required
     $this->_model->load(1);
     $attributes = $this->_model->getAttributes();
     $this->assertArrayHasKey('name', $attributes);
     $this->assertArrayHasKey('sku', $attributes);
     $this->assertInstanceOf('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', $attributes['sku']);
 }
 protected function setUp()
 {
     $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     // fixture
     $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\ConfigurableProduct\\Model\\Product\\VariationHandler');
     // prevent fatal errors by assigning proper "singleton" of type instance to the product
     $this->_product->setTypeInstance($this->_model);
 }
 /**
  * @magentoDataFixture Magento/CatalogRule/_files/attribute.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testReindexAfterRuleCreation()
 {
     $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save();
     $this->assertFalse($this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1));
     $this->saveRule();
     // apply all rules
     $this->indexBuilder->reindexFull();
     $this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1));
 }
Example #9
0
 protected function setUp()
 {
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->_block = $objectManager->create('Magento\\Catalog\\Block\\Product\\View');
     $this->_product = $objectManager->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     $objectManager->get('Magento\\Framework\\Registry')->unregister('product');
     $objectManager->get('Magento\\Framework\\Registry')->register('product', $this->_product);
 }
Example #10
0
 protected function setUp()
 {
     $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     /** @var $objectManager \Magento\TestFramework\ObjectManager */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $objectManager->get('Magento\\Framework\\Registry')->unregister('current_product');
     $objectManager->get('Magento\\Framework\\Registry')->register('current_product', $this->_product);
     $this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Catalog\\Block\\Product\\View\\Options');
 }
 /**
  * @return array
  */
 protected function prepareProducts($price)
 {
     $this->product->load(1);
     $productSecond = clone $this->product;
     $productSecond->setId(null)->setUrlKey(null)->setSku(uniqid($this->product->getSku() . '-'))->setName(uniqid($this->product->getName() . '-'))->setWebsiteIds([1]);
     $productSecond->save();
     $productSecond->setPrice($price)->save();
     $productThird = clone $this->product;
     $productThird->setId(null)->setUrlKey(null)->setSku(uniqid($this->product->getSku() . '-'))->setName(uniqid($this->product->getName() . '-'))->setWebsiteIds([1])->save();
     $productThird->setPrice($price)->save();
     return [$productSecond->getId(), $productThird->getId()];
 }
 /**
  * @magentoDataFixture Magento/Bundle/_files/product.php
  */
 public function testGetItems()
 {
     $this->product = $this->objectManager->get('Magento\\Catalog\\Model\\Product');
     $this->product->load(3);
     /**
      * @var \Magento\Bundle\Model\Product\OptionList $optionList
      */
     $optionList = $this->objectManager->create('\\Magento\\Bundle\\Model\\Product\\OptionList');
     $options = $optionList->getItems($this->product);
     $this->assertEquals(1, count($options));
     $this->assertEquals('Bundle Product Items', $options[0]->getTitle());
 }
Example #13
0
 protected function setUp()
 {
     if (!self::$_isStubClass) {
         $this->getMockForAbstractClass('Magento\\Catalog\\Block\\Product\\AbstractProduct', [], self::STUB_CLASS, false);
         self::$_isStubClass = true;
     }
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\State')->setAreaCode('frontend');
     \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\DesignInterface')->setDefaultDesignTheme();
     $this->_block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock(self::STUB_CLASS);
     $this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->_product->load(1);
     $this->_product->addData(['image' => '/m/a/magento_image.jpg', 'small_image' => '/m/a/magento_image.jpg', 'thumbnail' => '/m/a/magento_image.jpg']);
     $this->_block->setProduct($this->_product);
 }
Example #14
0
 /**
  * @magentoDbIsolation disabled
  * @magentoAppIsolation enabled
  * @magentoDataFixture Magento/Catalog/_files/price_row_fixture.php
  */
 public function testProductsUpdate()
 {
     $this->_product->load(1);
     $this->_processor->reindexList([$this->_product->getId()]);
     $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory');
     $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Block\\Product\\ListProduct');
     $category = $categoryFactory->create()->load(9);
     $layer = $listProduct->getLayer();
     $layer->setCurrentCategory($category);
     $productCollection = $layer->getProductCollection();
     $this->assertEquals(1, $productCollection->count());
     /** @var $product \Magento\Catalog\Model\Product */
     foreach ($productCollection as $product) {
         $this->assertEquals($this->_product->getId(), $product->getId());
         $this->assertEquals($this->_product->getPrice(), $product->getPrice());
     }
 }
Example #15
0
 public function testSaveProductRelationsNoChildren()
 {
     $childrenIds = $this->_product->getTypeInstance()->getChildrenIds(1);
     $this->assertNotEmpty(reset($childrenIds));
     $this->_product->setAssociatedProductIds([]);
     $this->_model->save($this->_product);
     $this->_product->load(1);
     $this->assertEquals([[]], $this->_product->getTypeInstance()->getChildrenIds(1));
 }
Example #16
0
 /**
  * @magentoDbIsolation enabled
  * @magentoAppIsolation enabled
  * @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  */
 public function testProductsUpdate()
 {
     $this->markTestSkipped('Should be fixed in MAGETWO-25641');
     $this->_product->load(1);
     $this->_processor->reindexList(array($this->_product->getId()));
     $categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory');
     $listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Block\\Product\\ListProduct');
     $category = $categoryFactory->create()->load(2);
     $layer = $listProduct->getLayer();
     $layer->setCurrentCategory($category);
     $productCollection = $layer->getProductCollection();
     $this->assertCount(1, $productCollection);
     /** @var $product \Magento\Catalog\Model\Product */
     foreach ($productCollection as $product) {
         $this->assertEquals($this->_product->getName(), $product->getName());
         $this->assertEquals($this->_product->getShortDescription(), $product->getShortDescription());
     }
 }
Example #17
0
 /**
  * {@inheritdoc}
  */
 public function load($modelId, $field = null)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'load');
     if (!$pluginInfo) {
         return parent::load($modelId, $field);
     } else {
         return $this->___callPlugins('load', func_get_args(), $pluginInfo);
     }
 }
 public function testStatusAfterLoad()
 {
     $this->resource->expects($this->once())->method('load')->with($this->model, 1, null);
     $this->eventManagerMock->expects($this->exactly(4))->method('dispatch');
     $this->model->load(1);
     $this->assertEquals(Status::STATUS_ENABLED, $this->model->getData(\Magento\Catalog\Model\Product::STATUS));
     $this->assertFalse($this->model->hasDataChanges());
     $this->model->setStatus(Status::STATUS_DISABLED);
     $this->assertTrue($this->model->hasDataChanges());
 }
 public function testGetAvailableInCategories()
 {
     $this->assertEquals([], $this->_model->getAvailableInCategories());
     $this->_model->load($this->productRepository->get('simple-4')->getId());
     // fixture
     $actualCategoryIds = $this->_model->getAvailableInCategories();
     sort($actualCategoryIds);
     // not depend on the order of items
     $this->assertEquals([10, 11, 12, 13], $actualCategoryIds);
     //Check not visible product
     $this->_model->load($this->productRepository->get('simple-3')->getId());
     $this->assertEmpty($this->_model->getAvailableInCategories());
 }
Example #20
0
 /**
  * @param int|null $productId
  * @param int|null $storeId
  * @throws \Ess\M2ePro\Model\Exception
  * @return \Ess\M2ePro\Model\Magento\Product | \Ess\M2ePro\Model\Magento\Product\Cache
  */
 public function loadProduct($productId = NULL, $storeId = NULL)
 {
     $productId = is_null($productId) ? $this->_productId : $productId;
     $storeId = is_null($storeId) ? $this->_storeId : $storeId;
     if ($productId <= 0) {
         throw new \Ess\M2ePro\Model\Exception('The Product ID is not set.');
     }
     $this->_productModel = $this->productFactory->create()->setStoreId($storeId);
     $this->_productModel->load($productId);
     $this->setProductId($productId);
     $this->setStoreId($storeId);
     return $this;
 }
 public function testGetAvailableInCategories()
 {
     $this->assertEquals([], $this->_model->getAvailableInCategories());
     $this->_model->load(4);
     // fixture
     $actualCategoryIds = $this->_model->getAvailableInCategories();
     sort($actualCategoryIds);
     // not depend on the order of items
     $this->assertEquals([2, 10, 11, 12], $actualCategoryIds);
     //Check not visible product
     $this->_model->load(3);
     $this->assertEmpty($this->_model->getAvailableInCategories());
 }
Example #22
0
 /**
  * Get Product from request
  *
  * @return Product
  */
 protected function _getProduct()
 {
     if (!$this->_product) {
         $this->_product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
         $productId = (int) $this->getRequest()->getParam('product', 0);
         if (!$productId && $this->_getUrlRewrite()->getId()) {
             $productId = $this->_getUrlRewrite()->getProductId();
         }
         if ($productId) {
             $this->_product->load($productId);
         }
     }
     return $this->_product;
 }
Example #23
0
 /**
  * Get Product from request
  *
  * @return Product
  */
 private function _getProduct()
 {
     if (!$this->_product) {
         $this->_product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product');
         $productId = (int) $this->getRequest()->getParam('product', 0);
         if (!$productId && $this->_getUrlRewrite()->getId() && $this->_getUrlRewrite()->getEntityType() === self::ENTITY_TYPE_PRODUCT) {
             $productId = $this->_getUrlRewrite()->getEntityId();
         }
         if ($productId) {
             $this->_product->load($productId);
         }
     }
     return $this->_product;
 }
Example #24
0
 /**
  * @covers \Magento\Catalog\Model\Product::isSalable
  * @covers \Magento\Catalog\Model\Product::isSaleable
  * @covers \Magento\Catalog\Model\Product::isAvailable
  * @covers \Magento\Catalog\Model\Product::isInStock
  */
 public function testIsSalable()
 {
     $this->_model->load(1);
     // fixture
     $this->assertTrue((bool) $this->_model->isSalable());
     $this->assertTrue((bool) $this->_model->isSaleable());
     $this->assertTrue((bool) $this->_model->isAvailable());
     $this->assertTrue($this->_model->isInStock());
     $this->_model->setStatus(0);
     $this->assertFalse((bool) $this->_model->isSalable());
     $this->assertFalse((bool) $this->_model->isSaleable());
     $this->assertFalse((bool) $this->_model->isAvailable());
     $this->assertFalse($this->_model->isInStock());
 }
 /**
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  * @magentoAppIsolation enabled
  */
 public function testGetOptions()
 {
     $this->_model->load(1);
     $options = $this->_model->getOptions();
     $this->assertEquals(4, count($options));
 }
 /**
  * @magentoDataFixture Magento/CatalogRule/_files/attribute.php
  * @magentoDataFixture Magento/CatalogRule/_files/rule_by_attribute.php
  * @magentoDataFixture Magento/Catalog/_files/product_simple.php
  * @magentoAppArea adminhtml
  */
 public function testReindexAfterSuitableProductSaving()
 {
     $this->product->load(1)->setData('test_attribute', 'test_attribute_value')->save();
     $this->assertEquals(9.800000000000001, $this->resourceRule->getRulePrice(new \DateTime(), 1, 1, 1));
 }
Example #27
0
 /**
  * @return \Magento\Framework\View\Result\PageFactory
  */
 public function execute()
 {
     $pId = $this->getRequest()->getParam('pid');
     //productId
     $sdcnt = $this->getRequest()->getParam('sdcnt');
     //shoppree discount
     /* 
      $resultPage = $this->resultPageFactory->create();
      $resultPage->getConfig()->getTitle()->prepend(__('Shoppree Offers'));
      return $resultPage; 
     
      $layout = $this->_view->getLayout();
      $block = $layout->createBlock('Shoppree\Offers\Block\OfferBlock');
      echo $block->getCurrentStoreName();
      echo '<br>';
      echo $block->getProductName('1');
     */
     $layout = $this->_view->getLayout();
     $block = $layout->createBlock('Shoppree\\Offers\\Block\\OfferBlock');
     try {
         if (!empty($pId)) {
             $params = array();
             $params['qty'] = '1';
             //product quantity
             /*get product id*/
             //$pId = '1';//productId
             $_product = $this->product->load($pId);
             if ($_product) {
                 $quote = $this->cart->getQuote();
                 //Create object of quote
                 $_product->setPrice('0.00');
                 //$_product->setFinalPrice('0.00');
                 $this->cart->addProduct($_product, $params);
                 $this->cart->setItemsQty();
                 //$quote->setGrandTotal($this->cart->getQuote()->getGrandTotal() - 50.00);
                 //$this->cart->setQuote($quote);
                 $this->cart->saveQuote();
                 $this->_checkoutSession->setCartWasUpdated(false);
                 $this->cart->save();
                 $this->_checkoutSession->unsShoppreeDiscount();
                 $this->messageManager->addSuccess(__('Add to cart successfully.'));
             }
         } else {
             if (!empty($sdcnt)) {
                 /*sets shoppree discount*/
                 $this->_checkoutSession->setShoppreeDiscount($sdcnt);
                 /*$this->getResponse()->setRedirect('/magento-prototype/checkout/cart');*/
             }
         }
         //$this->messageManager->addSuccess(__('Add to cart successfully.').'--'.$this->_checkoutSession->getQuote()->getSubtotal().'--'.$this->_checkoutSession->getQuote()->getGrandTotal().'--'.$this->cart->getQuote()->getGrandTotal().'--'.$this->cart->getQuote()->getSubtotal());
         //$this->messageManager->addSuccess(__('Add to cart successfully.').$block->getGrandTotal().'--'.$this->cart->getQuote()->getGrandTotal());
         /*
          $this->messageManager->addSuccess(__('Add to cart successfully.').$this->cart->getItemsCount().'--'.$this->cart->getItemsQty()); 
             		 $this->getResponse()->setRedirect('/magento-prototype/checkout/cart');
         */
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addException($e, __('%1', $e->getMessage()));
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('error.'));
     }
 }