-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-5912: graphQl-812: test Add Variation From Another Configurabl…
…e Product To Cart #866
- Loading branch information
Showing
5 changed files
with
328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...sts/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_attribute_2.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\Eav\Api\AttributeRepositoryInterface; | ||
|
||
$eavConfig = Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class); | ||
$attribute2 = $eavConfig->getAttribute('catalog_product', 'test_configurable_2'); | ||
|
||
$eavConfig->clear(); | ||
|
||
/** @var $installer \Magento\Catalog\Setup\CategorySetup */ | ||
$installer = Bootstrap::getObjectManager()->create(\Magento\Catalog\Setup\CategorySetup::class); | ||
|
||
if (!$attribute2->getId()) { | ||
|
||
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */ | ||
$attribute2 = Bootstrap::getObjectManager()->create( | ||
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class | ||
); | ||
|
||
/** @var AttributeRepositoryInterface $attributeRepository */ | ||
$attributeRepository = Bootstrap::getObjectManager()->create(AttributeRepositoryInterface::class); | ||
|
||
$attribute2->setData( | ||
[ | ||
'attribute_code' => 'test_configurable_2', | ||
'entity_type_id' => $installer->getEntityTypeId('catalog_product'), | ||
'is_global' => 1, | ||
'is_user_defined' => 1, | ||
'frontend_input' => 'select', | ||
'is_unique' => 0, | ||
'is_required' => 0, | ||
'is_searchable' => 0, | ||
'is_visible_in_advanced_search' => 0, | ||
'is_comparable' => 0, | ||
'is_filterable' => 0, | ||
'is_filterable_in_search' => 0, | ||
'is_used_for_promo_rules' => 0, | ||
'is_html_allowed_on_front' => 1, | ||
'is_visible_on_front' => 0, | ||
'used_in_product_listing' => 0, | ||
'used_for_sort_by' => 0, | ||
'frontend_label' => ['Test Configurable 2'], | ||
'backend_type' => 'int', | ||
'option' => [ | ||
'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']], | ||
'order' => ['option_0' => 1, 'option_1' => 2], | ||
], | ||
] | ||
); | ||
|
||
$attributeRepository->save($attribute2); | ||
|
||
/* Assign attribute to attribute set */ | ||
$installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute2->getId()); | ||
} | ||
|
||
$eavConfig->clear(); |
28 changes: 28 additions & 0 deletions
28
...ration/testsuite/Magento/ConfigurableProduct/_files/configurable_attribute_2_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
/** @var \Magento\Framework\Registry $registry */ | ||
$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
$productCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() | ||
->get(\Magento\Catalog\Model\ResourceModel\Product\Collection::class); | ||
foreach ($productCollection as $product) { | ||
$product->delete(); | ||
} | ||
|
||
$eavConfig = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class); | ||
$attribute = $eavConfig->getAttribute('catalog_product', 'test_configurable_2'); | ||
if ($attribute instanceof \Magento\Eav\Model\Entity\Attribute\AbstractAttribute | ||
&& $attribute->getId() | ||
) { | ||
$attribute->delete(); | ||
} | ||
$eavConfig->clear(); | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); |
162 changes: 162 additions & 0 deletions
162
...gento/ConfigurableProduct/_files/configurable_products_with_different_super_attribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
use Magento\Catalog\Api\ProductRepositoryInterface; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Attribute\Source\Status; | ||
use Magento\Catalog\Model\Product\Type; | ||
use Magento\Catalog\Model\Product\Visibility; | ||
use Magento\Catalog\Setup\CategorySetup; | ||
use Magento\ConfigurableProduct\Helper\Product\Options\Factory; | ||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable; | ||
use Magento\Eav\Api\Data\AttributeOptionInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
require __DIR__ . '/configurable_attribute.php'; | ||
require __DIR__ . '/configurable_attribute_2.php'; | ||
|
||
/** @var ProductRepositoryInterface $productRepository */ | ||
$productRepository = Bootstrap::getObjectManager() | ||
->get(ProductRepositoryInterface::class); | ||
|
||
/** @var $installer CategorySetup */ | ||
$installer = Bootstrap::getObjectManager()->create(CategorySetup::class); | ||
|
||
/* Create simple products per each option value*/ | ||
/** @var AttributeOptionInterface[] $options */ | ||
$options = $attribute->getOptions(); | ||
|
||
$attributeValues = []; | ||
$attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default'); | ||
$associatedProductIds = []; | ||
$productIds = [10, 20]; | ||
array_shift($options); //remove the first option which is empty | ||
|
||
foreach ($options as $option) { | ||
/** @var $product Product */ | ||
$product = Bootstrap::getObjectManager()->create(Product::class); | ||
$productId = array_shift($productIds); | ||
$product->setTypeId(Type::TYPE_SIMPLE) | ||
->setId($productId) | ||
->setAttributeSetId($attributeSetId) | ||
->setWebsiteIds([1]) | ||
->setName('Configurable Option' . $option->getLabel()) | ||
->setSku('simple_' . $productId) | ||
->setPrice($productId) | ||
->setTestConfigurable($option->getValue()) | ||
->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]); | ||
$product = $productRepository->save($product); | ||
|
||
$attributeValues[] = [ | ||
'label' => 'test', | ||
'attribute_id' => $attribute->getId(), | ||
'value_index' => $option->getValue(), | ||
]; | ||
$associatedProductIds[] = $product->getId(); | ||
} | ||
|
||
/** @var $product Product */ | ||
$product = Bootstrap::getObjectManager()->create(Product::class); | ||
/** @var Factory $optionsFactory */ | ||
$optionsFactory = Bootstrap::getObjectManager()->create(Factory::class); | ||
$configurableAttributesData = [ | ||
[ | ||
'attribute_id' => $attribute->getId(), | ||
'code' => $attribute->getAttributeCode(), | ||
'label' => $attribute->getStoreLabel(), | ||
'position' => '0', | ||
'values' => $attributeValues, | ||
], | ||
]; | ||
$configurableOptions = $optionsFactory->create($configurableAttributesData); | ||
$extensionConfigurableAttributes = $product->getExtensionAttributes(); | ||
$extensionConfigurableAttributes->setConfigurableProductOptions($configurableOptions); | ||
$extensionConfigurableAttributes->setConfigurableProductLinks($associatedProductIds); | ||
$product->setExtensionAttributes($extensionConfigurableAttributes); | ||
|
||
$product->setTypeId(Configurable::TYPE_CODE) | ||
->setId(1) | ||
->setAttributeSetId($attributeSetId) | ||
->setWebsiteIds([1]) | ||
->setName('Configurable Product') | ||
->setSku('configurable') | ||
->setVisibility(Visibility::VISIBILITY_BOTH) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]); | ||
$productRepository->cleanCache(); | ||
$productRepository->save($product); | ||
|
||
/* Create simple products per each option value*/ | ||
/** @var AttributeOptionInterface[] $options */ | ||
$options = $attribute2->getOptions(); | ||
|
||
$attributeValues = []; | ||
$attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default'); | ||
$associatedProductIds = []; | ||
$productIds = [30, 40]; | ||
array_shift($options); //remove the first option which is empty | ||
|
||
foreach ($options as $option) { | ||
/** @var $product Product */ | ||
$product = Bootstrap::getObjectManager()->create(Product::class); | ||
$productId = array_shift($productIds); | ||
$product->setTypeId(Type::TYPE_SIMPLE) | ||
->setId($productId) | ||
->setAttributeSetId($attributeSetId) | ||
->setWebsiteIds([1]) | ||
->setName('Configurable Option' . $option->getLabel()) | ||
->setSku('simple_' . $productId) | ||
->setPrice($productId) | ||
->setTestConfigurable2($option->getValue()) | ||
->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]); | ||
$product = $productRepository->save($product); | ||
|
||
$attributeValues[] = [ | ||
'label' => 'test', | ||
'attribute_id' => $attribute2->getId(), | ||
'value_index' => $option->getValue(), | ||
]; | ||
$associatedProductIds[] = $product->getId(); | ||
} | ||
|
||
/** @var $product Product */ | ||
$product = Bootstrap::getObjectManager()->create(Product::class); | ||
|
||
/** @var Factory $optionsFactory */ | ||
$optionsFactory = Bootstrap::getObjectManager()->create(Factory::class); | ||
|
||
$configurableAttributesData = [ | ||
[ | ||
'attribute_id' => $attribute2->getId(), | ||
'code' => $attribute2->getAttributeCode(), | ||
'label' => $attribute2->getStoreLabel(), | ||
'position' => '1', | ||
'values' => $attributeValues, | ||
], | ||
]; | ||
|
||
$configurableOptions = $optionsFactory->create($configurableAttributesData); | ||
|
||
$extensionConfigurableAttributes = $product->getExtensionAttributes(); | ||
$extensionConfigurableAttributes->setConfigurableProductOptions($configurableOptions); | ||
$extensionConfigurableAttributes->setConfigurableProductLinks($associatedProductIds); | ||
|
||
$product->setExtensionAttributes($extensionConfigurableAttributes); | ||
|
||
$product->setTypeId(Configurable::TYPE_CODE) | ||
->setId(11) | ||
->setAttributeSetId($attributeSetId) | ||
->setWebsiteIds([1]) | ||
->setName('Configurable Product 12345') | ||
->setSku('configurable_12345') | ||
->setVisibility(Visibility::VISIBILITY_BOTH) | ||
->setStatus(Status::STATUS_ENABLED) | ||
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]); | ||
$productRepository->cleanCache(); | ||
$productRepository->save($product); |
14 changes: 14 additions & 0 deletions
14
...figurableProduct/_files/configurable_products_with_different_super_attribute_rollback.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
require __DIR__ . '/configurable_products_rollback.php'; | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', true); | ||
|
||
require __DIR__ . '/configurable_attribute_2_rollback.php'; | ||
|
||
$registry->unregister('isSecureArea'); | ||
$registry->register('isSecureArea', false); |