Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit aa24c9d

Browse files
committed
Merge branch 'MAGETWO-75517' into MPI-PR-2.2.1
2 parents a872f40 + 48cdd0a commit aa24c9d

File tree

4 files changed

+211
-4
lines changed

4 files changed

+211
-4
lines changed

dev/tests/integration/testsuite/Magento/Paypal/Controller/ExpressTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public function testStartActionCustomerToQuote()
142142
* Test return action with configurable product.
143143
*
144144
* @magentoDataFixture Magento/Paypal/_files/quote_express_configurable.php
145+
* @magentoDbIsolation enabled
146+
* @magentoAppIsolation enabled
145147
*/
146148
public function testReturnAction()
147149
{
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\TestFramework\Helper\Bootstrap;
8+
use Magento\Eav\Api\AttributeRepositoryInterface;
9+
10+
$eavConfig = Bootstrap::getObjectManager()->get(\Magento\Eav\Model\Config::class);
11+
$attribute = $eavConfig->getAttribute('catalog_product', 'test_configurable');
12+
13+
$eavConfig->clear();
14+
15+
/** @var $installer \Magento\Catalog\Setup\CategorySetup */
16+
$installer = Bootstrap::getObjectManager()->create(\Magento\Catalog\Setup\CategorySetup::class);
17+
18+
if (!$attribute->getId()) {
19+
20+
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
21+
$attribute = Bootstrap::getObjectManager()->create(
22+
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
23+
);
24+
25+
/** @var AttributeRepositoryInterface $attributeRepository */
26+
$attributeRepository = Bootstrap::getObjectManager()->create(AttributeRepositoryInterface::class);
27+
28+
$attribute->setData(
29+
[
30+
'attribute_code' => 'test_configurable',
31+
'entity_type_id' => $installer->getEntityTypeId('catalog_product'),
32+
'is_global' => 1,
33+
'is_user_defined' => 1,
34+
'frontend_input' => 'select',
35+
'is_unique' => 0,
36+
'is_required' => 0,
37+
'is_searchable' => 0,
38+
'is_visible_in_advanced_search' => 0,
39+
'is_comparable' => 0,
40+
'is_filterable' => 0,
41+
'is_filterable_in_search' => 0,
42+
'is_used_for_promo_rules' => 0,
43+
'is_html_allowed_on_front' => 1,
44+
'is_visible_on_front' => 0,
45+
'used_in_product_listing' => 0,
46+
'used_for_sort_by' => 0,
47+
'frontend_label' => ['Test Configurable'],
48+
'backend_type' => 'int',
49+
'option' => [
50+
'value' => ['option_0' => ['Option 1'], 'option_1' => ['Option 2']],
51+
'order' => ['option_0' => 1, 'option_1' => 2],
52+
],
53+
]
54+
);
55+
56+
$attributeRepository->save($attribute);
57+
58+
/* Assign attribute to attribute set */
59+
$installer->addAttributeToGroup('catalog_product', 'Default', 'General', $attribute->getId());
60+
}
61+
62+
$eavConfig->clear();
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
use Magento\Catalog\Api\ProductRepositoryInterface;
8+
use Magento\Catalog\Model\Product;
9+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
10+
use Magento\Catalog\Model\Product\Type;
11+
use Magento\Catalog\Model\Product\Visibility;
12+
use Magento\Catalog\Setup\CategorySetup;
13+
use Magento\ConfigurableProduct\Helper\Product\Options\Factory;
14+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
15+
use Magento\Eav\Api\Data\AttributeOptionInterface;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
18+
Bootstrap::getInstance()->reinitialize();
19+
20+
require __DIR__ . '/configurable_attribute.php';
21+
22+
/** @var ProductRepositoryInterface $productRepository */
23+
$productRepository = Bootstrap::getObjectManager()
24+
->create(ProductRepositoryInterface::class);
25+
26+
/** @var $installer CategorySetup */
27+
$installer = Bootstrap::getObjectManager()->create(CategorySetup::class);
28+
29+
/* Create simple products per each option value*/
30+
/** @var AttributeOptionInterface[] $options */
31+
$options = $attribute->getOptions();
32+
33+
$attributeValues = [];
34+
$attributeSetId = $installer->getAttributeSetId('catalog_product', 'Default');
35+
$associatedProductIds = [];
36+
$productIds = [101, 201];
37+
array_shift($options); //remove the first option which is empty
38+
39+
foreach ($options as $option) {
40+
/** @var $product Product */
41+
$product = Bootstrap::getObjectManager()->create(Product::class);
42+
$productId = array_shift($productIds);
43+
$product->setTypeId(Type::TYPE_SIMPLE)
44+
->setId($productId)
45+
->setAttributeSetId($attributeSetId)
46+
->setWebsiteIds([1])
47+
->setName('Configurable Option' . $option->getLabel())
48+
->setSku('simple_' . $productId)
49+
->setPrice($productId)
50+
->setTestConfigurable($option->getValue())
51+
->setVisibility(Visibility::VISIBILITY_NOT_VISIBLE)
52+
->setStatus(Status::STATUS_ENABLED)
53+
->setStockData([
54+
'use_config_manage_stock' => 1,
55+
'qty' => 100,
56+
'is_qty_decimal' => 0,
57+
'is_in_stock' => 1
58+
]);
59+
60+
$product = $productRepository->save($product);
61+
62+
/** @var \Magento\CatalogInventory\Model\Stock\Item $stockItem */
63+
$stockItem = Bootstrap::getObjectManager()->create(\Magento\CatalogInventory\Model\Stock\Item::class);
64+
$stockItem->load($productId, 'product_id');
65+
66+
if (!$stockItem->getProductId()) {
67+
$stockItem->setProductId($productId);
68+
}
69+
$stockItem->setUseConfigManageStock(1);
70+
$stockItem->setQty(1000);
71+
$stockItem->setIsQtyDecimal(0);
72+
$stockItem->setIsInStock(1);
73+
$stockItem->save();
74+
75+
$attributeValues[] = [
76+
'label' => 'test',
77+
'attribute_id' => $attribute->getId(),
78+
'value_index' => $option->getValue(),
79+
];
80+
$associatedProductIds[] = $product->getId();
81+
}
82+
83+
/** @var $product Product */
84+
$product = Bootstrap::getObjectManager()->create(Product::class);
85+
86+
/** @var Factory $optionsFactory */
87+
$optionsFactory = Bootstrap::getObjectManager()->create(Factory::class);
88+
89+
$configurableAttributesData = [
90+
[
91+
'attribute_id' => $attribute->getId(),
92+
'code' => $attribute->getAttributeCode(),
93+
'label' => $attribute->getStoreLabel(),
94+
'position' => '0',
95+
'values' => $attributeValues,
96+
],
97+
];
98+
99+
$configurableOptions = $optionsFactory->create($configurableAttributesData);
100+
101+
$extensionConfigurableAttributes = $product->getExtensionAttributes();
102+
$extensionConfigurableAttributes->setConfigurableProductOptions($configurableOptions);
103+
$extensionConfigurableAttributes->setConfigurableProductLinks($associatedProductIds);
104+
105+
$product->setExtensionAttributes($extensionConfigurableAttributes);
106+
107+
// Remove any previously created product with the same id.
108+
/** @var \Magento\Framework\Registry $registry */
109+
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
110+
$registry->unregister('isSecureArea');
111+
$registry->register('isSecureArea', true);
112+
113+
try {
114+
$productToDelete = $productRepository->getById(1);
115+
$productRepository->delete($productToDelete);
116+
117+
/** @var \Magento\Quote\Model\ResourceModel\Quote\Item $itemResource */
118+
$itemResource = Bootstrap::getObjectManager()->get(\Magento\Quote\Model\ResourceModel\Quote\Item::class);
119+
$itemResource->getConnection()->delete(
120+
$itemResource->getMainTable(),
121+
'product_id = ' . $productToDelete->getId()
122+
);
123+
} catch (\Exception $e) {
124+
// Nothing to remove
125+
}
126+
127+
$registry->unregister('isSecureArea');
128+
$registry->register('isSecureArea', false);
129+
130+
$product->setTypeId(Configurable::TYPE_CODE)
131+
->setId(100)
132+
->setAttributeSetId($attributeSetId)
133+
->setWebsiteIds([1])
134+
->setName('Configurable Product')
135+
->setSku('configurable_express')
136+
->setVisibility(Visibility::VISIBILITY_BOTH)
137+
->setStatus(Status::STATUS_ENABLED)
138+
->setStockData([
139+
'use_config_manage_stock' => 1,
140+
'is_in_stock' => 1
141+
]);
142+
143+
$productRepository->save($product);

dev/tests/integration/testsuite/Magento/Paypal/_files/quote_express_configurable.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@
1111
use Magento\Quote\Model\Quote\Address\Rate;
1212
use Magento\TestFramework\Helper\Bootstrap;
1313

14-
require __DIR__ . '/../../../Magento/ConfigurableProduct/_files/product_configurable.php';
14+
require __DIR__ . '/product_configurable.php';
1515

1616
/** @var $objectManager \Magento\TestFramework\ObjectManager */
1717
$objectManager = Bootstrap::getObjectManager();
1818

1919
/** @var $product \Magento\Catalog\Model\Product */
2020
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
2121
$productRepository = $objectManager->create(ProductRepositoryInterface::class);
22-
$product = $productRepository->get('configurable');
22+
$product = $productRepository->get('configurable_express');
2323

2424
/** @var $options Collection */
2525
$options = $objectManager->create(Collection::class);
2626
$option = $options->setAttributeFilter($attribute->getId())->getFirstItem();
2727

2828
$requestInfo = new \Magento\Framework\DataObject(
2929
[
30-
'product' => 2,
31-
'selected_configurable_option' => 2,
30+
'product' => 1,
31+
'selected_configurable_option' => 1,
3232
'qty' => 1,
3333
'super_attribute' => [
3434
$attribute->getId() => $option->getId()

0 commit comments

Comments
 (0)