Skip to content

Commit 52c4963

Browse files
authored
Merge pull request #396 from magento-south/BUGS
[South] Bug fixes - MAGETWO-56941 [Github] Allowed countries for customer address in admin using storeview configuration #2946 - MAGETWO-54816 Styles drop down in WYSIWYG editor does not work - MAGETWO-58220 Unable to "Add Products Manually" for Configurable product - MAGETWO-58393 An error occurs while saving configurable product
2 parents 7800e37 + 551658f commit 52c4963

File tree

29 files changed

+1448
-46
lines changed

29 files changed

+1448
-46
lines changed

app/code/Magento/Backend/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
<resource>Magento_Config::config_general</resource>
199199
<group id="country" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
200200
<label>Country Options</label>
201-
<field id="allow" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
201+
<field id="allow" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
202202
<label>Allow Countries</label>
203203
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
204204
<can_be_empty>1</can_be_empty>

app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,14 @@ protected function fillSimpleProductData(
148148
\Magento\Catalog\Model\Product $parentProduct,
149149
$postData
150150
) {
151+
$typeId = isset($postData['weight']) && !empty($postData['weight'])
152+
? ProductType::TYPE_SIMPLE
153+
: ProductType::TYPE_VIRTUAL;
154+
151155
$product->setStoreId(
152156
\Magento\Store\Model\Store::DEFAULT_STORE_ID
153157
)->setTypeId(
154-
$postData['weight'] ? ProductType::TYPE_SIMPLE : ProductType::TYPE_VIRTUAL
158+
$typeId
155159
)->setAttributeSetId(
156160
$parentProduct->getNewVariationsAttributeSetId()
157161
);

app/code/Magento/ConfigurableProduct/Test/Unit/Model/Product/VariationHandlerTest.php

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\ConfigurableProduct\Test\Unit\Model\Product;
1010

11+
use Magento\Catalog\Model\Product\Type;
1112
use Magento\ConfigurableProduct\Model\Product\VariationHandler;
1213

1314
/**
@@ -162,23 +163,30 @@ public function testPrepareAttributeSet()
162163

163164
/**
164165
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
166+
* @dataProvider dataProviderTestGenerateSimpleProducts
167+
* @param int|string|null $weight
168+
* @param string $typeId
165169
*/
166-
public function testGenerateSimpleProducts()
170+
public function testGenerateSimpleProducts($weight, $typeId)
167171
{
168172
$productsData = [
169-
6 =>
170-
[
171-
'image' => 'image.jpg',
172-
'name' => 'config-red',
173-
'configurable_attribute' => '{"new_attr":"6"}',
174-
'sku' => 'config-red',
175-
'quantity_and_stock_status' =>
176-
[
177-
'qty' => '',
178-
],
179-
'weight' => '333',
180-
]
173+
[
174+
'image' => 'image.jpg',
175+
'name' => 'config-red',
176+
'configurable_attribute' => '{"new_attr":"6"}',
177+
'sku' => 'config-red',
178+
'quantity_and_stock_status' =>
179+
[
180+
'qty' => '',
181+
],
182+
]
181183
];
184+
185+
// Do not add 'weight' attribute if it's value is null!
186+
if ($weight !== null) {
187+
$productsData[0]['weight'] = $weight;
188+
}
189+
182190
$stockData = [
183191
'manage_stock' => '0',
184192
'use_config_enable_qty_increments' => '1',
@@ -218,7 +226,7 @@ public function testGenerateSimpleProducts()
218226
)
219227
->disableOriginalConstructor()
220228
->getMock();
221-
$productTypeMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type::class)
229+
$productTypeMock = $this->getMockBuilder(Type::class)
222230
->setMethods(['getSetAttributes'])
223231
->disableOriginalConstructor()
224232
->getMock();
@@ -236,7 +244,7 @@ public function testGenerateSimpleProducts()
236244
->willReturn('new_attr_set_id');
237245
$this->productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
238246
$newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
239-
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
247+
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with($typeId)->willReturnSelf();
240248
$newSimpleProductMock->expects($this->once())
241249
->method('setAttributeSetId')
242250
->with('new_attr_set_id')
@@ -265,6 +273,27 @@ public function testGenerateSimpleProducts()
265273
$this->assertEquals(['product_id'], $this->model->generateSimpleProducts($parentProductMock, $productsData));
266274
}
267275

276+
/**
277+
* @return array
278+
*/
279+
public function dataProviderTestGenerateSimpleProducts()
280+
{
281+
return [
282+
[
283+
'weight' => 333,
284+
'type_id' => Type::TYPE_SIMPLE,
285+
],
286+
[
287+
'weight' => '',
288+
'type_id' => Type::TYPE_VIRTUAL,
289+
],
290+
[
291+
'weight' => null,
292+
'type_id' => Type::TYPE_VIRTUAL,
293+
],
294+
];
295+
}
296+
268297
public function testProcessMediaGalleryWithImagesAndGallery()
269298
{
270299
$this->product->expects($this->atLeastOnce())->method('getMediaGallery')->with('images')->willReturn([]);

app/code/Magento/Customer/Model/Customer/DataProvider.php

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77

88
use Magento\Customer\Api\AddressMetadataInterface;
99
use Magento\Customer\Api\CustomerMetadataInterface;
10+
use Magento\Customer\Api\Data\AddressInterface;
11+
use Magento\Customer\Api\Data\CustomerInterface;
1012
use Magento\Customer\Model\Attribute;
1113
use Magento\Customer\Model\FileProcessor;
1214
use Magento\Customer\Model\FileProcessorFactory;
15+
use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryWithWebsites;
1316
use Magento\Eav\Api\Data\AttributeInterface;
1417
use Magento\Eav\Model\Config;
1518
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
@@ -55,6 +58,16 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
5558
*/
5659
protected $loadedData;
5760

61+
/**
62+
* @var CountryWithWebsites
63+
*/
64+
private $countryWithWebsiteSource;
65+
66+
/**
67+
* @var \Magento\Customer\Model\Config\Share
68+
*/
69+
private $shareConfig;
70+
5871
/**
5972
* EAV attribute properties to fetch from meta storage
6073
* @var array
@@ -117,6 +130,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
117130
* @param FileProcessorFactory $fileProcessorFactory
118131
* @param array $meta
119132
* @param array $data
133+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
120134
*/
121135
public function __construct(
122136
$name,
@@ -234,6 +248,7 @@ private function overrideFileUploaderData($entity, array &$entityData)
234248
* @param Attribute $attribute
235249
* @param array $customerData
236250
* @return array
251+
* @SuppressWarnings(PHPMD.NPathComplexity)
237252
*/
238253
private function getFileUploaderData(
239254
Type $entityType,
@@ -292,6 +307,7 @@ protected function getAttributesMeta(Type $entityType)
292307
$this->processFrontendInput($attribute, $meta);
293308

294309
$code = $attribute->getAttributeCode();
310+
295311
// use getDataUsingMethod, since some getters are defined and apply additional processing of returning value
296312
foreach ($this->metaProperties as $metaName => $origName) {
297313
$value = $attribute->getDataUsingMethod($origName);
@@ -304,7 +320,12 @@ protected function getAttributesMeta(Type $entityType)
304320
}
305321

306322
if ($attribute->usesSource()) {
307-
$meta[$code]['arguments']['data']['config']['options'] = $attribute->getSource()->getAllOptions();
323+
if ($code == AddressInterface::COUNTRY_ID) {
324+
$meta[$code]['arguments']['data']['config']['options'] = $this->getCountryWithWebsiteSource()
325+
->getAllOptions();
326+
} else {
327+
$meta[$code]['arguments']['data']['config']['options'] = $attribute->getSource()->getAllOptions();
328+
}
308329
}
309330

310331
$rules = $this->eavValidationRules->build($attribute, $meta[$code]['arguments']['data']['config']);
@@ -315,9 +336,61 @@ protected function getAttributesMeta(Type $entityType)
315336

316337
$this->overrideFileUploaderMetadata($entityType, $attribute, $meta[$code]['arguments']['data']['config']);
317338
}
339+
340+
$this->processWebsiteMeta($meta);
318341
return $meta;
319342
}
320343

344+
/**
345+
* Retrieve Country With Websites Source
346+
*
347+
* @deprecated
348+
* @return CountryWithWebsites
349+
*/
350+
private function getCountryWithWebsiteSource()
351+
{
352+
if (!$this->countryWithWebsiteSource) {
353+
$this->countryWithWebsiteSource = ObjectManager::getInstance()->get(CountryWithWebsites::class);
354+
}
355+
356+
return $this->countryWithWebsiteSource;
357+
}
358+
359+
/**
360+
* Retrieve Customer Config Share
361+
*
362+
* @deprecated
363+
* @return \Magento\Customer\Model\Config\Share
364+
*/
365+
private function getShareConfig()
366+
{
367+
if (!$this->shareConfig) {
368+
$this->shareConfig = ObjectManager::getInstance()->get(\Magento\Customer\Model\Config\Share::class);
369+
}
370+
371+
return $this->shareConfig;
372+
}
373+
374+
/**
375+
* Add global scope parameter and filter options to website meta
376+
*
377+
* @param array $meta
378+
* @return void
379+
*/
380+
private function processWebsiteMeta(&$meta)
381+
{
382+
if (isset($meta[CustomerInterface::WEBSITE_ID]) && $this->getShareConfig()->isGlobalScope()) {
383+
$meta[CustomerInterface::WEBSITE_ID]['arguments']['data']['config']['isGlobalScope'] = 1;
384+
}
385+
386+
if (isset($meta[AddressInterface::COUNTRY_ID]) && !$this->getShareConfig()->isGlobalScope()) {
387+
$meta[AddressInterface::COUNTRY_ID]['arguments']['data']['config']['filterBy'] = [
388+
'target' => '${ $.provider }:data.customer.website_id',
389+
'field' => 'website_ids'
390+
];
391+
}
392+
}
393+
321394
/**
322395
* Override file uploader UI component metadata
323396
*
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Customer\Model\Plugin;
8+
9+
use Magento\Customer\Model\Config\Share;
10+
use Magento\Store\Api\Data\WebsiteInterface;
11+
use Magento\Store\Model\ScopeInterface;
12+
use Magento\Store\Model\StoreManagerInterface;
13+
14+
/**
15+
* Class AllowedCountries
16+
*/
17+
class AllowedCountries
18+
{
19+
/**
20+
* @var \Magento\Customer\Model\Config\Share
21+
*/
22+
private $shareConfig;
23+
24+
/**
25+
* @var StoreManagerInterface
26+
*/
27+
private $storeManager;
28+
29+
/**
30+
* @param Share $share
31+
* @param StoreManagerInterface $storeManager
32+
*/
33+
public function __construct(
34+
Share $share,
35+
StoreManagerInterface $storeManager
36+
) {
37+
$this->shareConfig = $share;
38+
$this->storeManager = $storeManager;
39+
}
40+
41+
/**
42+
* Retrieve all allowed countries or specific by scope depends on customer share setting
43+
*
44+
* @param \Magento\Directory\Model\AllowedCountries $subject
45+
* @param string | null $filter
46+
* @param string $scope
47+
* @return array
48+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
49+
*/
50+
public function beforeGetAllowedCountries(
51+
\Magento\Directory\Model\AllowedCountries $subject,
52+
$scope = ScopeInterface::SCOPE_WEBSITE,
53+
$scopeCode = null
54+
) {
55+
if ($this->shareConfig->isGlobalScope()) {
56+
//Check if we have shared accounts - than merge all website allowed countries
57+
$scopeCode = array_map(function (WebsiteInterface $website) {
58+
return $website->getId();
59+
}, $this->storeManager->getWebsites());
60+
$scope = ScopeInterface::SCOPE_WEBSITES;
61+
}
62+
63+
return [$scope, $scopeCode];
64+
}
65+
}

app/code/Magento/Customer/Model/ResourceModel/Address/Attribute/Source/Country.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,27 @@
1111
*/
1212
namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source;
1313

14+
use Magento\Checkout\Model\Session;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Store\Api\StoreResolverInterface;
17+
use Magento\Store\Model\StoreManagerInterface;
18+
19+
/**
20+
* Class Country.
21+
* @package Magento\Customer\Model\ResourceModel\Address\Attribute\Source
22+
*/
1423
class Country extends \Magento\Eav\Model\Entity\Attribute\Source\Table
1524
{
1625
/**
1726
* @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory
1827
*/
1928
protected $_countriesFactory;
2029

30+
/**
31+
* @var StoreResolverInterface
32+
*/
33+
private $storeResolver;
34+
2135
/**
2236
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
2337
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
@@ -41,7 +55,7 @@ public function getAllOptions()
4155
{
4256
if (!$this->_options) {
4357
$this->_options = $this->_createCountriesCollection()->loadByStore(
44-
$this->getAttribute()->getStoreId()
58+
$this->getStoreResolver()->getCurrentStoreId()
4559
)->toOptionArray();
4660
}
4761
return $this->_options;
@@ -54,4 +68,18 @@ protected function _createCountriesCollection()
5468
{
5569
return $this->_countriesFactory->create();
5670
}
71+
72+
/**
73+
* Retrieve Store Resolver
74+
* @deprecated
75+
* @return StoreResolverInterface
76+
*/
77+
private function getStoreResolver()
78+
{
79+
if (!$this->storeResolver) {
80+
$this->storeResolver = ObjectManager::getInstance()->get(StoreResolverInterface::class);
81+
}
82+
83+
return $this->storeResolver;
84+
}
5785
}

0 commit comments

Comments
 (0)