Skip to content

Commit 27416ae

Browse files
[EngCom] Public Pull Requests - 2.2-develop
- merged latest code from mainline branch
2 parents e8fdcda + 743e963 commit 27416ae

File tree

7 files changed

+201
-5
lines changed

7 files changed

+201
-5
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco
9191
]
9292
),
9393
[]
94-
)->joinInner(
94+
)->joinLeft(
9595
['attribute_option' => $this->attributeResource->getTable('eav_attribute_option')],
9696
'attribute_option.option_id = entity_value.value',
9797
[]

app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public function testGetSelect()
112112
{
113113
$this->select->expects($this->exactly(1))->method('from')->willReturnSelf();
114114
$this->select->expects($this->exactly(1))->method('columns')->willReturnSelf();
115-
$this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf();
116-
$this->select->expects($this->exactly(3))->method('joinLeft')->willReturnSelf();
115+
$this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf();
116+
$this->select->expects($this->exactly(4))->method('joinLeft')->willReturnSelf();
117117
$this->select->expects($this->exactly(1))->method('order')->willReturnSelf();
118118
$this->select->expects($this->exactly(2))->method('where')->willReturnSelf();
119119

@@ -156,8 +156,8 @@ public function testGetSelectWithBackendModel()
156156
{
157157
$this->select->expects($this->exactly(1))->method('from')->willReturnSelf();
158158
$this->select->expects($this->exactly(0))->method('columns')->willReturnSelf();
159-
$this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf();
160-
$this->select->expects($this->exactly(1))->method('joinLeft')->willReturnSelf();
159+
$this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf();
160+
$this->select->expects($this->exactly(2))->method('joinLeft')->willReturnSelf();
161161
$this->select->expects($this->exactly(1))->method('order')->willReturnSelf();
162162
$this->select->expects($this->exactly(2))->method('where')->willReturnSelf();
163163

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ public function testGetConfigurableAttributes()
157157
}
158158
}
159159

160+
/**
161+
* @magentoAppIsolation enabled
162+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable_custom.php
163+
*/
164+
public function testGetConfigurableAttributesWithSourceModel()
165+
{
166+
$collection = $this->model->getConfigurableAttributes($this->product);
167+
/** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute $configurableAttribute */
168+
$configurableAttribute = $collection->getFirstItem();
169+
$attribute = $this->_getAttributeByCode('test_configurable_with_sm');
170+
$this->assertSameSize($attribute->getSource()->getAllOptions(), $configurableAttribute->getOptions());
171+
}
172+
160173
/**
161174
* @magentoAppIsolation enabled
162175
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
9+
$eavSetup = $objectManager->create(\Magento\Eav\Setup\EavSetup::class);
10+
$eavSetup->addAttribute(
11+
\Magento\Catalog\Model\Product::ENTITY,
12+
'test_configurable_with_sm',
13+
[
14+
'group' => 'General',
15+
'type' => 'varchar',
16+
'backend' => '',
17+
'frontend' => '',
18+
'label' => 'Test configurable with source model',
19+
'input' => 'select',
20+
'source' => \Magento\Catalog\Model\Category\Attribute\Source\Mode::class,
21+
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
22+
'visible' => true,
23+
'required' => false,
24+
'user_defined' => true,
25+
'default' => '',
26+
'searchable' => false,
27+
'filterable' => false,
28+
'comparable' => false,
29+
'visible_on_front' => false,
30+
'used_in_product_listing' => true,
31+
'unique' => false,
32+
'apply_to' => ''
33+
]
34+
);
35+
36+
$eavConfig = $objectManager->get(\Magento\Eav\Model\Config::class);
37+
$eavConfig->clear();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
9+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
10+
$registry->unregister('isSecureArea');
11+
$registry->register('isSecureArea', true);
12+
13+
$eavConfig = $objectManager->get(\Magento\Eav\Model\Config::class);
14+
$attribute = $eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'test_configurable_with_sm');
15+
if ($attribute instanceof \Magento\Eav\Model\Entity\Attribute\AbstractAttribute && $attribute->getId()) {
16+
$attribute->delete();
17+
}
18+
$eavConfig->clear();
19+
20+
$registry->unregister('isSecureArea');
21+
$registry->register('isSecureArea', false);
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/configurable_attribute_with_source_model.php';
8+
9+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
10+
11+
$installer = $objectManager->create(\Magento\Catalog\Setup\CategorySetup::class);
12+
13+
$eavConfig = $objectManager->get(\Magento\Eav\Model\Config::class);
14+
$attribute = $eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'test_configurable_with_sm');
15+
$options = $attribute->getOptions();
16+
17+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
18+
$attributeValues = [];
19+
$associatedProductIds = [];
20+
$attributeSetId = $installer->getAttributeSetId(\Magento\Catalog\Model\Product::ENTITY, 'Default');
21+
22+
foreach ($options as $key => $option) {
23+
$productId = $key + 10;
24+
25+
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
26+
$product->setTypeId(Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
27+
->setId($productId)
28+
->setAttributeSetId($attributeSetId)
29+
->setWebsiteIds([1])
30+
->setName('Configurable Option ' . $option->getLabel())
31+
->setSku('simple_' . $productId)
32+
->setPrice($productId)
33+
->setTestConfigurableWithSm($option->getValue())
34+
->setVisibility(Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE)
35+
->setStatus(Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
36+
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]);
37+
$product = $productRepository->save($product);
38+
39+
$stockItem = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Item::class);
40+
$stockItem->load($productId, 'product_id');
41+
if (!$stockItem->getProductId()) {
42+
$stockItem->setProductId($productId);
43+
}
44+
$stockItem->setUseConfigManageStock(1);
45+
$stockItem->setQty(1000);
46+
$stockItem->setIsQtyDecimal(0);
47+
$stockItem->setIsInStock(1);
48+
$stockItem->save();
49+
50+
$attributeValues[] = [
51+
'label' => 'test',
52+
'attribute_id' => $attribute->getId(),
53+
'value_index' => $option->getValue(),
54+
];
55+
$associatedProductIds[] = $product->getId();
56+
}
57+
58+
$optionsFactory = $objectManager->create(\Magento\ConfigurableProduct\Helper\Product\Options\Factory::class);
59+
$configurableAttributesData = [
60+
[
61+
'attribute_id' => $attribute->getId(),
62+
'code' => $attribute->getAttributeCode(),
63+
'label' => $attribute->getStoreLabel(),
64+
'position' => '0',
65+
'values' => $attributeValues,
66+
],
67+
];
68+
$configurableOptions = $optionsFactory->create($configurableAttributesData);
69+
70+
$product = $objectManager->create(\Magento\Catalog\Model\Product::class);
71+
$extensionConfigurableAttributes = $product->getExtensionAttributes();
72+
$extensionConfigurableAttributes->setConfigurableProductOptions($configurableOptions);
73+
$extensionConfigurableAttributes->setConfigurableProductLinks($associatedProductIds);
74+
$product->setExtensionAttributes($extensionConfigurableAttributes);
75+
76+
$product->setTypeId(\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE)
77+
->setId(1)
78+
->setAttributeSetId($attributeSetId)
79+
->setWebsiteIds([1])
80+
->setName('Configurable Product')
81+
->setSku('configurable')
82+
->setVisibility(Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
83+
->setStatus(Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
84+
->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]);
85+
$productRepository->save($product);
86+
87+
$categoryLinkManagement = $objectManager->create(\Magento\Catalog\Api\CategoryLinkManagementInterface::class);
88+
$categoryLinkManagement->assignProductToCategories(
89+
$product->getSku(),
90+
[2]
91+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
8+
9+
/** @var \Magento\Framework\Registry $registry */
10+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
11+
$registry->unregister('isSecureArea');
12+
$registry->register('isSecureArea', true);
13+
14+
$productRepository = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
15+
foreach (['simple_10', 'simple_11', 'simple_12', 'configurable'] as $sku) {
16+
try {
17+
$product = $productRepository->get($sku, true);
18+
19+
$stockStatus = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Status::class);
20+
$stockStatus->load($product->getEntityId(), 'product_id');
21+
$stockStatus->delete();
22+
23+
if ($product->getId()) {
24+
$productRepository->delete($product);
25+
}
26+
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
27+
//Product already removed
28+
}
29+
}
30+
31+
$registry->unregister('isSecureArea');
32+
$registry->register('isSecureArea', false);
33+
34+
require __DIR__ . '/configurable_attribute_with_source_model_rollback.php';

0 commit comments

Comments
 (0)