當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::setTypeInstance方法代碼示例

本文整理匯總了PHP中Magento\Catalog\Model\Product::setTypeInstance方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::setTypeInstance方法的具體用法?PHP Product::setTypeInstance怎麽用?PHP Product::setTypeInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::setTypeInstance方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 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');
 }
開發者ID:Doability,項目名稱:magento2dev,代碼行數:9,代碼來源:VariationHandlerTest.php

示例2: setUp

 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\\Type\\Configurable');
     // prevent fatal errors by assigning proper "singleton" of type instance to the product
     $this->_product->setTypeInstance($this->_model);
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:9,代碼來源:ConfigurableTest.php

示例3: setUp

 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);
 }
開發者ID:BlackIkeEagle,項目名稱:magento2-continuousphp,代碼行數:9,代碼來源:ConfigurableTest.php

示例4: testGetSetTypeInstance

 public function testGetSetTypeInstance()
 {
     // model getter
     $typeInstance = $this->_model->getTypeInstance();
     $this->assertInstanceOf('Magento\\Bundle\\Model\\Product\\Type', $typeInstance);
     $this->assertSame($typeInstance, $this->_model->getTypeInstance());
     // singleton getter
     $otherProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $otherProduct->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
     $this->assertSame($typeInstance, $otherProduct->getTypeInstance());
     // model setter
     $customTypeInstance = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Bundle\\Model\\Product\\Type');
     $this->_model->setTypeInstance($customTypeInstance);
     $this->assertSame($customTypeInstance, $this->_model->getTypeInstance());
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:15,代碼來源:ProductTest.php

示例5: testGetSetTypeInstance

 public function testGetSetTypeInstance()
 {
     // model getter
     $typeInstance = $this->_model->getTypeInstance();
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Product\\Type\\AbstractType', $typeInstance);
     $this->assertSame($typeInstance, $this->_model->getTypeInstance());
     // singleton
     /** @var $otherProduct \Magento\Catalog\Model\Product */
     $otherProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $this->assertSame($typeInstance, $otherProduct->getTypeInstance());
     // model setter
     $simpleTypeInstance = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product\\Type\\Simple');
     $this->_model->setTypeInstance($simpleTypeInstance);
     $this->assertSame($simpleTypeInstance, $this->_model->getTypeInstance());
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:15,代碼來源:ProductGettersTest.php

示例6: testGetProductLinks

 /**
  *  Test for getProductLinks()
  */
 public function testGetProductLinks()
 {
     $linkTypes = ['related' => 1, 'upsell' => 4, 'crosssell' => 5, 'associated' => 3];
     $this->linkTypeProviderMock->expects($this->once())->method('getLinkTypes')->willReturn($linkTypes);
     $inputRelatedLink = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $inputRelatedLink->setProductSku("Simple Product 1");
     $inputRelatedLink->setLinkType("related");
     $inputRelatedLink->setData("sku", "Simple Product 2");
     $inputRelatedLink->setData("type", "simple");
     $inputRelatedLink->setPosition(0);
     $outputRelatedLink = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $outputRelatedLink->setProductSku("Simple Product 1");
     $outputRelatedLink->setLinkType("related");
     $outputRelatedLink->setLinkedProductSku("Simple Product 2");
     $outputRelatedLink->setLinkedProductType("simple");
     $outputRelatedLink->setPosition(0);
     $this->entityCollectionProviderMock->expects($this->at(0))->method('getCollection')->with($this->model, 'related')->willReturn([$inputRelatedLink]);
     $this->entityCollectionProviderMock->expects($this->at(1))->method('getCollection')->with($this->model, 'upsell')->willReturn([]);
     $this->entityCollectionProviderMock->expects($this->at(2))->method('getCollection')->with($this->model, 'crosssell')->willReturn([]);
     $this->entityCollectionProviderMock->expects($this->at(3))->method('getCollection')->with($this->model, 'associated')->willReturn([]);
     $expectedOutput = [$outputRelatedLink];
     $typeInstanceMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Simple', ["getSku"], [], '', false);
     $typeInstanceMock->expects($this->atLeastOnce())->method('getSku')->willReturn("Simple Product 1");
     $this->model->setTypeInstance($typeInstanceMock);
     $productLink1 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $this->productLinkFactory->expects($this->at(0))->method('create')->willReturn($productLink1);
     $links = $this->model->getProductLinks();
     $this->assertEquals($links, $expectedOutput);
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:32,代碼來源:ProductTest.php

示例7: testGetIsSalableHasDataIsSaleable

 public function testGetIsSalableHasDataIsSaleable()
 {
     $typeInstanceMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Type\\Simple', [], [], '', false);
     $this->model->setTypeInstance($typeInstanceMock);
     $this->model->setData('is_saleable', true);
     $this->model->setData('is_salable', false);
     self::assertTrue($this->model->getIsSalable());
 }
開發者ID:hientruong90,項目名稱:magento2_installer,代碼行數:8,代碼來源:ProductTest.php

示例8: processProduct

 /**
  * Process given product and change its type if needed
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 public function processProduct(Product $product)
 {
     if (in_array($product->getTypeId(), $this->compatibleTypes)) {
         $product->setTypeInstance(null);
         $productTypeId = $this->weightResolver->resolveProductHasWeight($product) ? Type::TYPE_SIMPLE : Type::TYPE_VIRTUAL;
         $product->setTypeId($productTypeId);
     }
 }
開發者ID:pradeep-wagento,項目名稱:magento2,代碼行數:14,代碼來源:TypeTransitionManager.php

示例9: processProduct

 /**
  * Process given product and change its type if needed
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return void
  */
 public function processProduct(Product $product)
 {
     if (in_array($product->getTypeId(), $this->compatibleTypes)) {
         $product->setTypeInstance(null);
         $productTypeId = $product->hasIsVirtual() ? \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL : \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE;
         $product->setTypeId($productTypeId);
     }
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:14,代碼來源:TypeTransitionManager.php

示例10: testGetProductLinks

 /**
  *  Test for getProductLinks() with associated product links
  */
 public function testGetProductLinks()
 {
     $this->markTestIncomplete('Skipped due to https://jira.corp.x.com/browse/MAGETWO-36926');
     $linkTypes = ['related' => 1, 'upsell' => 4, 'crosssell' => 5, 'associated' => 3];
     $this->linkTypeProviderMock->expects($this->once())->method('getLinkTypes')->willReturn($linkTypes);
     $inputRelatedLink = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $inputRelatedLink->setProductSku("Simple Product 1");
     $inputRelatedLink->setLinkType("related");
     $inputRelatedLink->setData("sku", "Simple Product 2");
     $inputRelatedLink->setData("type", "simple");
     $inputRelatedLink->setPosition(0);
     $customData = ["attribute_code" => "qty", "value" => 1];
     $inputGroupLink = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $inputGroupLink->setProductSku("Simple Product 1");
     $inputGroupLink->setLinkType("associated");
     $inputGroupLink->setData("sku", "Simple Product 2");
     $inputGroupLink->setData("type", "simple");
     $inputGroupLink->setPosition(0);
     $inputGroupLink["custom_attributes"] = [$customData];
     $outputRelatedLink = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $outputRelatedLink->setProductSku("Simple Product 1");
     $outputRelatedLink->setLinkType("related");
     $outputRelatedLink->setLinkedProductSku("Simple Product 2");
     $outputRelatedLink->setLinkedProductType("simple");
     $outputRelatedLink->setPosition(0);
     $groupExtension = $this->objectManagerHelper->getObject('Magento\\Catalog\\Api\\Data\\ProductLinkExtension');
     $reflectionOfExtension = new \ReflectionClass('Magento\\Catalog\\Api\\Data\\ProductLinkExtension');
     $method = $reflectionOfExtension->getMethod('setData');
     $method->setAccessible(true);
     $method->invokeArgs($groupExtension, array('qty', 1));
     $outputGroupLink = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $outputGroupLink->setProductSku("Simple Product 1");
     $outputGroupLink->setLinkType("associated");
     $outputGroupLink->setLinkedProductSku("Simple Product 2");
     $outputGroupLink->setLinkedProductType("simple");
     $outputGroupLink->setPosition(0);
     $outputGroupLink->setExtensionAttributes($groupExtension);
     $this->entityCollectionProviderMock->expects($this->at(0))->method('getCollection')->with($this->model, 'related')->willReturn([$inputRelatedLink]);
     $this->entityCollectionProviderMock->expects($this->at(1))->method('getCollection')->with($this->model, 'upsell')->willReturn([]);
     $this->entityCollectionProviderMock->expects($this->at(2))->method('getCollection')->with($this->model, 'crosssell')->willReturn([]);
     $this->entityCollectionProviderMock->expects($this->at(3))->method('getCollection')->with($this->model, 'associated')->willReturn([$inputGroupLink]);
     $expectedOutput = [$outputRelatedLink, $outputGroupLink];
     $typeInstanceMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Simple', ["getSku"], [], '', false);
     $typeInstanceMock->expects($this->atLeastOnce())->method('getSku')->willReturn("Simple Product 1");
     $this->model->setTypeInstance($typeInstanceMock);
     $productLink1 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $productLink2 = $this->objectManagerHelper->getObject('Magento\\Catalog\\Model\\ProductLink\\Link');
     $this->productLinkFactory->expects($this->at(0))->method('create')->willReturn($productLink1);
     $this->productLinkFactory->expects($this->at(1))->method('create')->willReturn($productLink2);
     $extension = $this->objectManagerHelper->getObject('Magento\\Catalog\\Api\\Data\\ProductLinkExtension');
     $productLink2->setExtensionAttributes($extension);
     $links = $this->model->getProductLinks();
     // Match the links
     $matches = 0;
     foreach ($links as $link) {
         foreach ($expectedOutput as $expected) {
             if ($expected->getData() == $link->getData()) {
                 $matches++;
             }
         }
     }
     $this->assertEquals($matches, 2);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:66,代碼來源:ProductTest.php

示例11: setTypeInstance

 /**
  * {@inheritdoc}
  */
 public function setTypeInstance($instance)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'setTypeInstance');
     if (!$pluginInfo) {
         return parent::setTypeInstance($instance);
     } else {
         return $this->___callPlugins('setTypeInstance', func_get_args(), $pluginInfo);
     }
 }
開發者ID:dragonsword007008,項目名稱:magento2,代碼行數:12,代碼來源:Interceptor.php


注:本文中的Magento\Catalog\Model\Product::setTypeInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。