Skip to content

Commit

Permalink
Merge pull request #396 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
slavvka authored Sep 19, 2016
2 parents 7800e37 + 551658f commit 52c4963
Show file tree
Hide file tree
Showing 29 changed files with 1,448 additions and 46 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Backend/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<resource>Magento_Config::config_general</resource>
<group id="country" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Country Options</label>
<field id="allow" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<field id="allow" translate="label" type="multiselect" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="0" canRestore="1">
<label>Allow Countries</label>
<source_model>Magento\Directory\Model\Config\Source\Country</source_model>
<can_be_empty>1</can_be_empty>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ protected function fillSimpleProductData(
\Magento\Catalog\Model\Product $parentProduct,
$postData
) {
$typeId = isset($postData['weight']) && !empty($postData['weight'])
? ProductType::TYPE_SIMPLE
: ProductType::TYPE_VIRTUAL;

$product->setStoreId(
\Magento\Store\Model\Store::DEFAULT_STORE_ID
)->setTypeId(
$postData['weight'] ? ProductType::TYPE_SIMPLE : ProductType::TYPE_VIRTUAL
$typeId
)->setAttributeSetId(
$parentProduct->getNewVariationsAttributeSetId()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

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

use Magento\Catalog\Model\Product\Type;
use Magento\ConfigurableProduct\Model\Product\VariationHandler;

/**
Expand Down Expand Up @@ -162,23 +163,30 @@ public function testPrepareAttributeSet()

/**
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @dataProvider dataProviderTestGenerateSimpleProducts
* @param int|string|null $weight
* @param string $typeId
*/
public function testGenerateSimpleProducts()
public function testGenerateSimpleProducts($weight, $typeId)
{
$productsData = [
6 =>
[
'image' => 'image.jpg',
'name' => 'config-red',
'configurable_attribute' => '{"new_attr":"6"}',
'sku' => 'config-red',
'quantity_and_stock_status' =>
[
'qty' => '',
],
'weight' => '333',
]
[
'image' => 'image.jpg',
'name' => 'config-red',
'configurable_attribute' => '{"new_attr":"6"}',
'sku' => 'config-red',
'quantity_and_stock_status' =>
[
'qty' => '',
],
]
];

// Do not add 'weight' attribute if it's value is null!
if ($weight !== null) {
$productsData[0]['weight'] = $weight;
}

$stockData = [
'manage_stock' => '0',
'use_config_enable_qty_increments' => '1',
Expand Down Expand Up @@ -218,7 +226,7 @@ public function testGenerateSimpleProducts()
)
->disableOriginalConstructor()
->getMock();
$productTypeMock = $this->getMockBuilder(\Magento\Catalog\Model\Product\Type::class)
$productTypeMock = $this->getMockBuilder(Type::class)
->setMethods(['getSetAttributes'])
->disableOriginalConstructor()
->getMock();
Expand All @@ -236,7 +244,7 @@ public function testGenerateSimpleProducts()
->willReturn('new_attr_set_id');
$this->productFactoryMock->expects($this->once())->method('create')->willReturn($newSimpleProductMock);
$newSimpleProductMock->expects($this->once())->method('setStoreId')->with(0)->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with('simple')->willReturnSelf();
$newSimpleProductMock->expects($this->once())->method('setTypeId')->with($typeId)->willReturnSelf();
$newSimpleProductMock->expects($this->once())
->method('setAttributeSetId')
->with('new_attr_set_id')
Expand Down Expand Up @@ -265,6 +273,27 @@ public function testGenerateSimpleProducts()
$this->assertEquals(['product_id'], $this->model->generateSimpleProducts($parentProductMock, $productsData));
}

/**
* @return array
*/
public function dataProviderTestGenerateSimpleProducts()
{
return [
[
'weight' => 333,
'type_id' => Type::TYPE_SIMPLE,
],
[
'weight' => '',
'type_id' => Type::TYPE_VIRTUAL,
],
[
'weight' => null,
'type_id' => Type::TYPE_VIRTUAL,
],
];
}

public function testProcessMediaGalleryWithImagesAndGallery()
{
$this->product->expects($this->atLeastOnce())->method('getMediaGallery')->with('images')->willReturn([]);
Expand Down
75 changes: 74 additions & 1 deletion app/code/Magento/Customer/Model/Customer/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\Data\AddressInterface;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Model\Attribute;
use Magento\Customer\Model\FileProcessor;
use Magento\Customer\Model\FileProcessorFactory;
use Magento\Customer\Model\ResourceModel\Address\Attribute\Source\CountryWithWebsites;
use Magento\Eav\Api\Data\AttributeInterface;
use Magento\Eav\Model\Config;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
Expand Down Expand Up @@ -55,6 +58,16 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
*/
protected $loadedData;

/**
* @var CountryWithWebsites
*/
private $countryWithWebsiteSource;

/**
* @var \Magento\Customer\Model\Config\Share
*/
private $shareConfig;

/**
* EAV attribute properties to fetch from meta storage
* @var array
Expand Down Expand Up @@ -117,6 +130,7 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
* @param FileProcessorFactory $fileProcessorFactory
* @param array $meta
* @param array $data
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
$name,
Expand Down Expand Up @@ -234,6 +248,7 @@ private function overrideFileUploaderData($entity, array &$entityData)
* @param Attribute $attribute
* @param array $customerData
* @return array
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
private function getFileUploaderData(
Type $entityType,
Expand Down Expand Up @@ -292,6 +307,7 @@ protected function getAttributesMeta(Type $entityType)
$this->processFrontendInput($attribute, $meta);

$code = $attribute->getAttributeCode();

// use getDataUsingMethod, since some getters are defined and apply additional processing of returning value
foreach ($this->metaProperties as $metaName => $origName) {
$value = $attribute->getDataUsingMethod($origName);
Expand All @@ -304,7 +320,12 @@ protected function getAttributesMeta(Type $entityType)
}

if ($attribute->usesSource()) {
$meta[$code]['arguments']['data']['config']['options'] = $attribute->getSource()->getAllOptions();
if ($code == AddressInterface::COUNTRY_ID) {
$meta[$code]['arguments']['data']['config']['options'] = $this->getCountryWithWebsiteSource()
->getAllOptions();
} else {
$meta[$code]['arguments']['data']['config']['options'] = $attribute->getSource()->getAllOptions();
}
}

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

$this->overrideFileUploaderMetadata($entityType, $attribute, $meta[$code]['arguments']['data']['config']);
}

$this->processWebsiteMeta($meta);
return $meta;
}

/**
* Retrieve Country With Websites Source
*
* @deprecated
* @return CountryWithWebsites
*/
private function getCountryWithWebsiteSource()
{
if (!$this->countryWithWebsiteSource) {
$this->countryWithWebsiteSource = ObjectManager::getInstance()->get(CountryWithWebsites::class);
}

return $this->countryWithWebsiteSource;
}

/**
* Retrieve Customer Config Share
*
* @deprecated
* @return \Magento\Customer\Model\Config\Share
*/
private function getShareConfig()
{
if (!$this->shareConfig) {
$this->shareConfig = ObjectManager::getInstance()->get(\Magento\Customer\Model\Config\Share::class);
}

return $this->shareConfig;
}

/**
* Add global scope parameter and filter options to website meta
*
* @param array $meta
* @return void
*/
private function processWebsiteMeta(&$meta)
{
if (isset($meta[CustomerInterface::WEBSITE_ID]) && $this->getShareConfig()->isGlobalScope()) {
$meta[CustomerInterface::WEBSITE_ID]['arguments']['data']['config']['isGlobalScope'] = 1;
}

if (isset($meta[AddressInterface::COUNTRY_ID]) && !$this->getShareConfig()->isGlobalScope()) {
$meta[AddressInterface::COUNTRY_ID]['arguments']['data']['config']['filterBy'] = [
'target' => '${ $.provider }:data.customer.website_id',
'field' => 'website_ids'
];
}
}

/**
* Override file uploader UI component metadata
*
Expand Down
65 changes: 65 additions & 0 deletions app/code/Magento/Customer/Model/Plugin/AllowedCountries.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Customer\Model\Plugin;

use Magento\Customer\Model\Config\Share;
use Magento\Store\Api\Data\WebsiteInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class AllowedCountries
*/
class AllowedCountries
{
/**
* @var \Magento\Customer\Model\Config\Share
*/
private $shareConfig;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param Share $share
* @param StoreManagerInterface $storeManager
*/
public function __construct(
Share $share,
StoreManagerInterface $storeManager
) {
$this->shareConfig = $share;
$this->storeManager = $storeManager;
}

/**
* Retrieve all allowed countries or specific by scope depends on customer share setting
*
* @param \Magento\Directory\Model\AllowedCountries $subject
* @param string | null $filter
* @param string $scope
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeGetAllowedCountries(
\Magento\Directory\Model\AllowedCountries $subject,
$scope = ScopeInterface::SCOPE_WEBSITE,
$scopeCode = null
) {
if ($this->shareConfig->isGlobalScope()) {
//Check if we have shared accounts - than merge all website allowed countries
$scopeCode = array_map(function (WebsiteInterface $website) {
return $website->getId();
}, $this->storeManager->getWebsites());
$scope = ScopeInterface::SCOPE_WEBSITES;
}

return [$scope, $scopeCode];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@
*/
namespace Magento\Customer\Model\ResourceModel\Address\Attribute\Source;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class Country.
* @package Magento\Customer\Model\ResourceModel\Address\Attribute\Source
*/
class Country extends \Magento\Eav\Model\Entity\Attribute\Source\Table
{
/**
* @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory
*/
protected $_countriesFactory;

/**
* @var StoreResolverInterface
*/
private $storeResolver;

/**
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\CollectionFactory $attrOptionCollectionFactory
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory $attrOptionFactory
Expand All @@ -41,7 +55,7 @@ public function getAllOptions()
{
if (!$this->_options) {
$this->_options = $this->_createCountriesCollection()->loadByStore(
$this->getAttribute()->getStoreId()
$this->getStoreResolver()->getCurrentStoreId()
)->toOptionArray();
}
return $this->_options;
Expand All @@ -54,4 +68,18 @@ protected function _createCountriesCollection()
{
return $this->_countriesFactory->create();
}

/**
* Retrieve Store Resolver
* @deprecated
* @return StoreResolverInterface
*/
private function getStoreResolver()
{
if (!$this->storeResolver) {
$this->storeResolver = ObjectManager::getInstance()->get(StoreResolverInterface::class);
}

return $this->storeResolver;
}
}
Loading

0 comments on commit 52c4963

Please sign in to comment.