本文整理汇总了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');
}
示例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);
}
示例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);
}
示例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());
}
示例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());
}
示例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);
}
示例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());
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}