当前位置: 首页>>代码示例>>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;未经允许,请勿转载。