本文整理汇总了PHP中Magento\Catalog\Model\Product::setTypeId方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::setTypeId方法的具体用法?PHP Product::setTypeId怎么用?PHP Product::setTypeId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Model\Product
的用法示例。
在下文中一共展示了Product::setTypeId方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetPriceModel
public function testGetPriceModel()
{
$this->_model->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE);
$type = $this->_model->getPriceModel();
$this->assertInstanceOf('Magento\\Bundle\\Model\\Product\\Price', $type);
$this->assertSame($type, $this->_model->getPriceModel());
}
示例2: testGetTypeId
public function testGetTypeId()
{
$productType = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Type\\Virtual')->disableOriginalConstructor()->getMockForAbstractClass();
$this->productTypeInstanceMock->expects($this->exactly(2))->method('factory')->will($this->returnValue($productType));
$this->model->getTypeInstance();
$this->model->setTypeId('typeId');
$this->model->getTypeInstance();
}
示例3: 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);
}
}
示例4: aroundProcessProduct
/**
* Change product type to configurable if needed
*
* @param \Magento\Catalog\Model\Product\TypeTransitionManager $subject
* @param Closure $proceed
* @param \Magento\Catalog\Model\Product $product
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundProcessProduct(\Magento\Catalog\Model\Product\TypeTransitionManager $subject, Closure $proceed, \Magento\Catalog\Model\Product $product)
{
$attributes = $this->request->getParam('attributes');
if (!empty($attributes)) {
$product->setTypeId(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE);
return;
}
$proceed($product);
}
示例5: testValidateUniqueInputAttributeValue
/**
* @magentoDbIsolation enabled
* @magentoDataFixture Magento/Catalog/_files/products_with_unique_input_attribute.php
*/
public function testValidateUniqueInputAttributeValue()
{
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute')->loadByCode(\Magento\Catalog\Model\Product::ENTITY, 'unique_input_attribute');
$this->_model->setTypeId('simple')->setAttributeSetId(4)->setName('Simple Product with non-unique value')->setSku('some product SKU')->setPrice(10)->setMetaTitle('meta title')->setData($attribute->getAttributeCode(), 'unique value')->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setCollectExceptionMessages(true);
$validationResult = $this->_model->validate();
$this->assertCount(1, $validationResult);
$this->assertContains('The value of attribute "' . $attribute->getDefaultFrontendLabel() . '" must be unique', $validationResult);
}
示例6: testValidate
public function testValidate()
{
$this->_model->setTypeId('simple')->setAttributeSetId(4)->setName('Simple Product')->setSku(uniqid('', true) . uniqid('', true) . uniqid('', true))->setPrice(10)->setMetaTitle('meta title')->setMetaKeyword('meta keyword')->setMetaDescription('meta description')->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)->setCollectExceptionMessages(true);
$validationResult = $this->_model->validate();
$this->assertEquals('SKU length should be 64 characters maximum.', $validationResult['sku']);
unset($validationResult['sku']);
foreach ($validationResult as $error) {
$this->assertTrue($error);
}
}
示例7: aroundProcessProduct
/**
* Change product type to downloadable if needed
*
* @param \Magento\Catalog\Model\Product\TypeTransitionManager $subject
* @param Closure $proceed
* @param \Magento\Catalog\Model\Product $product
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundProcessProduct(\Magento\Catalog\Model\Product\TypeTransitionManager $subject, Closure $proceed, \Magento\Catalog\Model\Product $product)
{
$isTypeCompatible = in_array($product->getTypeId(), array(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL, \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE));
$hasDownloadableData = $this->request->getPost('downloadable');
if ($isTypeCompatible && $hasDownloadableData && $product->hasIsVirtual()) {
$product->setTypeId(\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE);
return;
}
$proceed($product);
}
示例8: aroundValidate
/**
* Validate product data
*
* @param Product\Validator $subject
* @param Closure $proceed
* @param Product $product
* @param RequestInterface $request
* @param \Magento\Framework\DataObject $response
* @return bool
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundValidate(\Magento\Catalog\Model\Product\Validator $subject, Closure $proceed, \Magento\Catalog\Model\Product $product, \Magento\Framework\App\RequestInterface $request, \Magento\Framework\DataObject $response)
{
if ($request->has('attributes')) {
$product->setTypeId(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE);
}
$result = $proceed($product, $request, $response);
$variationProducts = (array) $request->getPost('variations-matrix');
if ($variationProducts) {
$validationResult = $this->_validateProductVariations($product, $variationProducts, $request);
if (!empty($validationResult)) {
$response->setError(true)->setMessage(__('Some product variations fields are not valid.'))->setAttributes($validationResult);
}
}
return $result;
}
示例9: aroundProcessProduct
/**
* Change product type to downloadable if needed
*
* @param \Magento\Catalog\Model\Product\TypeTransitionManager $subject
* @param Closure $proceed
* @param \Magento\Catalog\Model\Product $product
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundProcessProduct(\Magento\Catalog\Model\Product\TypeTransitionManager $subject, Closure $proceed, \Magento\Catalog\Model\Product $product)
{
$isTypeCompatible = in_array($product->getTypeId(), [\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE, \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL, \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE]);
$downloadableData = $this->request->getPost('downloadable');
$hasDownloadableData = false;
if (isset($downloadableData)) {
foreach ($downloadableData as $data) {
foreach ($data as $rowData) {
if (empty($rowData['is_delete'])) {
$hasDownloadableData = true;
break;
}
}
}
}
if ($isTypeCompatible && $hasDownloadableData && $product->hasIsVirtual()) {
$product->setTypeId(\Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE);
return;
}
$proceed($product);
}
示例10: testGetTypeId
public function testGetTypeId()
{
$this->assertEmpty($this->_model->getTypeId());
$this->_model->setTypeId('simple');
$this->assertEquals('simple', $this->_model->getTypeId());
}
示例11: setTypeId
/**
* {@inheritdoc}
*/
public function setTypeId($typeId)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'setTypeId');
if (!$pluginInfo) {
return parent::setTypeId($typeId);
} else {
return $this->___callPlugins('setTypeId', func_get_args(), $pluginInfo);
}
}