Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.2-develop' into ENGCOM-2271-ma…
Browse files Browse the repository at this point in the history
…gento-magento2-15366
  • Loading branch information
p-bystritsky committed Oct 17, 2018
2 parents 072498e + c19d876 commit f42be8a
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ public function execute()
$data['backend_model'] = $this->productHelper->getAttributeBackendModelByInputType(
$data['frontend_input']
);

if ($model->getIsUserDefined() === null) {
$data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
}
}

$data += ['is_filterable' => 0, 'is_filterable_in_search' => 0];

if ($model->getIsUserDefined() === null || $model->getIsUserDefined() != 0) {
$data['backend_type'] = $model->getBackendTypeByInput($data['frontend_input']);
}

$defaultValueField = $model->getDefaultValueByInput($data['frontend_input']);
if ($defaultValueField) {
$data['default_value'] = $this->getRequest()->getParam($defaultValueField);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ protected function _updateTemporaryTableByStoreValues(
if (!empty($changedIds)) {
$select->where($this->_connection->quoteInto('et.entity_id IN (?)', $changedIds));
}

/*
* According to \Magento\Framework\DB\SelectRendererInterface select rendering may be updated
* so we need to trigger select renderer for correct update
*/
$select->assemble();
$sql = $select->crossUpdateFromSelect(['et' => $temporaryFlatTableName]);
$this->_connection->query($sql);
}
Expand All @@ -355,6 +361,7 @@ protected function _updateTemporaryTableByStoreValues(
if (!empty($changedIds)) {
$select->where($this->_connection->quoteInto('et.entity_id IN (?)', $changedIds));
}
$select->assemble();
$sql = $select->crossUpdateFromSelect(['et' => $temporaryFlatTableName]);
$this->_connection->query($sql);
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/ResourceModel/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ public function changeParent(
$childrenCount = $this->getChildrenCount($category->getId()) + 1;
$table = $this->getEntityTable();
$connection = $this->getConnection();
$levelFiled = $connection->quoteIdentifier('level');
$levelField = $connection->quoteIdentifier('level');
$pathField = $connection->quoteIdentifier('path');

/**
Expand Down Expand Up @@ -960,7 +960,7 @@ public function changeParent(
$newPath . '/'
) . ')'
),
'level' => new \Zend_Db_Expr($levelFiled . ' + ' . $levelDisposition)
'level' => new \Zend_Db_Expr($levelField . ' + ' . $levelDisposition)
],
[$pathField . ' LIKE ?' => $category->getPath() . '/%']
);
Expand Down
38 changes: 24 additions & 14 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
* @param \Magento\Framework\App\ResourceConnection $resource
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory
* @param \Magento\ImportExport\Model\Export\ConfigInterface $exportConfig
* @param \Magento\Catalog\Model\ResourceModel\ProductFactory $productFactory
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attrSetColFactory
Expand All @@ -361,9 +361,10 @@ class Product extends \Magento\ImportExport\Model\Export\Entity\AbstractEntity
* @param \Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory $optionColFactory
* @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory
* @param Product\Type\Factory $_typeFactory
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
* @param ProductEntity\LinkTypeProvider $linkTypeProvider
* @param RowCustomizerInterface $rowCustomizer
* @param array $dateAttrCodes
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand Down Expand Up @@ -517,10 +518,13 @@ protected function getMediaGallery(array $productIds)
if (empty($productIds)) {
return [];
}

$productEntityJoinField = $this->getProductEntityLinkField();

$select = $this->_connection->select()->from(
['mgvte' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value_to_entity')],
[
"mgvte.{$this->getProductEntityLinkField()}",
"mgvte.$productEntityJoinField",
'mgvte.value_id'
]
)->joinLeft(
Expand All @@ -532,22 +536,22 @@ protected function getMediaGallery(array $productIds)
]
)->joinLeft(
['mgv' => $this->_resourceModel->getTableName('catalog_product_entity_media_gallery_value')],
'(mg.value_id = mgv.value_id)',
"(mg.value_id = mgv.value_id) and (mgvte.$productEntityJoinField = mgv.$productEntityJoinField)",
[
'mgv.label',
'mgv.position',
'mgv.disabled',
'mgv.store_id'
]
)->where(
"mgvte.{$this->getProductEntityLinkField()} IN (?)",
"mgvte.$productEntityJoinField IN (?)",
$productIds
);

$rowMediaGallery = [];
$stmt = $this->_connection->query($select);
while ($mediaRow = $stmt->fetch()) {
$rowMediaGallery[$mediaRow[$this->getProductEntityLinkField()]][] = [
$rowMediaGallery[$mediaRow[$productEntityJoinField]][] = [
'_media_attribute_id' => $mediaRow['attribute_id'],
'_media_image' => $mediaRow['filename'],
'_media_label' => $mediaRow['label'],
Expand Down Expand Up @@ -689,6 +693,8 @@ protected function updateDataWithCategoryColumns(&$dataRow, &$rowCategories, $pr
}

/**
* Get header columns
*
* {@inheritdoc}
*/
public function _getHeaderColumns()
Expand Down Expand Up @@ -748,6 +754,8 @@ protected function _getExportMainAttrCodes()
}

/**
* Get entity collection
*
* {@inheritdoc}
*/
protected function _getEntityCollection($resetCollection = false)
Expand Down Expand Up @@ -818,9 +826,8 @@ protected function paginateCollection($page, $pageSize)
}

/**
* Export process
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function export()
{
Expand Down Expand Up @@ -854,7 +861,11 @@ public function export()
}

/**
* {@inheritdoc}
* Apply filter to collection and add not skipped attributes to select.
*
* @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection
* @return \Magento\Eav\Model\Entity\Collection\AbstractCollection
*
* @since 100.2.0
*/
protected function _prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
Expand Down Expand Up @@ -916,11 +927,10 @@ protected function getExportData()
}

/**
* Load products' data from the collection
* and filter it (if needed).
* Load products' data from the collection and filter it (if needed).
*
* @return array Keys are product IDs, values arrays with keys as store IDs
* and values as store-specific versions of Product entity.
* @return array Keys are product IDs, values arrays with keys as store ID
* and values as store-specific versions of Product entity.
*/
protected function loadCollection(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@
<settings>
<scopeLabel>[GLOBAL]</scopeLabel>
<validation>
<rule name="validate-number" xsi:type="boolean">true</rule>
<rule name="validate-greater-than-zero" xsi:type="boolean">true</rule>
</validation>
<label translate="true">Maximum Qty Allowed in Shopping Cart</label>
<dataScope>max_sale_qty</dataScope>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ define([

/** @inheritdoc */
initialize: function () {
var stepsValue;

this._super();
$(window).hashchange(_.bind(stepNavigator.handleHash, stepNavigator));

if (!window.location.hash) {
stepNavigator.setHash(stepNavigator.steps().sort(stepNavigator.sortItems)[0].code);
stepsValue = stepNavigator.steps();

if (stepsValue.length) {
stepNavigator.setHash(stepsValue.sort(stepNavigator.sortItems)[0].code);
}
}

stepNavigator.handleHash();
Expand Down
3 changes: 0 additions & 3 deletions app/code/Magento/Customer/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ public function updateData(AddressInterface $address)
// Need to explicitly set this due to discrepancy in the keys between model and data object
$this->setIsDefaultBilling($address->isDefaultBilling());
$this->setIsDefaultShipping($address->isDefaultShipping());
if (!$this->getAttributeSetId()) {
$this->setAttributeSetId(AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS);
}
$customAttributes = $address->getCustomAttributes();
if ($customAttributes !== null) {
foreach ($customAttributes as $attribute) {
Expand Down
17 changes: 10 additions & 7 deletions app/code/Magento/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,6 @@ public function updateData($customer)
$this->setId($customerId);
}

// Need to use attribute set or future updates can cause data loss
if (!$this->getAttributeSetId()) {
$this->setAttributeSetId(
CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
);
}

return $this;
}

Expand Down Expand Up @@ -960,6 +953,16 @@ public function getSharedWebsiteIds()
return $ids;
}

/**
* Retrieve attribute set id for customer.
*
* @return int
*/
public function getAttributeSetId()
{
return parent::getAttributeSetId() ?: CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER;
}

/**
* Set store to customer
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,6 @@ public function save(\Magento\Customer\Api\Data\CustomerInterface $customer, $pa
$customerModel->setStoreId($this->storeManager->getStore()->getId());
}

// Need to use attribute set or future updates can cause data loss
if (!$customerModel->getAttributeSetId()) {
$customerModel->setAttributeSetId(
\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER
);
}
$this->populateCustomerWithSecureData($customerModel, $passwordHash);

// If customer email was changed, reset RpToken info
Expand Down
2 changes: 0 additions & 2 deletions app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ public function testUpdateData()
}
$expectedResult[$attribute->getAttributeCode()] = $attribute->getValue();
$expectedResult['attribute_set_id'] =
\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER;
$this->assertEquals($this->_model->getData(), $expectedResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,6 @@ public function testSave()
$customerModel->expects($this->once())
->method('setId')
->with($customerId);
$customerModel->expects($this->once())
->method('getAttributeSetId')
->willReturn(null);
$customerModel->expects($this->once())
->method('setAttributeSetId')
->with(\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
$customerAttributesMetaData->expects($this->atLeastOnce())
->method('getId')
->willReturn($customerId);
Expand Down Expand Up @@ -616,12 +610,6 @@ public function testSaveWithPasswordHash()
$customerModel->expects($this->once())
->method('setId')
->with($customerId);
$customerModel->expects($this->once())
->method('getAttributeSetId')
->willReturn(null);
$customerModel->expects($this->once())
->method('setAttributeSetId')
->with(\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
$customerModel->expects($this->atLeastOnce())
->method('getId')
->willReturn($customerId);
Expand Down
22 changes: 22 additions & 0 deletions app/code/Magento/Directory/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
if (version_compare($context->getVersion(), '2.0.2', '<')) {
$this->addCountryRegions($setup, 'IN', $this->getDataForIndia());
}
if (version_compare($context->getVersion(), '2.0.3', '<')) {
$this->addCountryRegions($setup, 'AU', $this->getDataForAustralia());
}
}

/**
Expand Down Expand Up @@ -127,6 +130,25 @@ private function getDataForIndia()
];
}

/**
* Australian states data.
*
* @return array
*/
private function getDataForAustralia()
{
return [
'ACT' => 'Australian Capital Territory',
'NSW' => 'New South Wales',
'VIC' => 'Victoria',
'QLD' => 'Queensland',
'SA' => 'South Australia',
'TAS' => 'Tasmania',
'WA' => 'Western Australia',
'NT' => 'Northern Territory'
];
}

/**
* Add country regions data to appropriate tables.
*
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Directory/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Directory" setup_version="2.0.2">
<module name="Magento_Directory" setup_version="2.0.3">
<sequence>
<module name="Magento_Store"/>
</sequence>
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/Eav/Model/Entity/Attribute/Source/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use Magento\Framework\Escaper;

/**
* Eav attribute default source when values are coming from another table
*
* @api
* @since 100.0.2
*/
Expand Down Expand Up @@ -136,12 +138,14 @@ public function getSpecificOptions($ids, $withEmpty = true)
}

/**
* Add an empty option to the array
*
* @param array $options
* @return array
*/
private function addEmptyOption(array $options)
{
array_unshift($options, ['label' => $this->getAttribute()->getIsRequired() ? '' : ' ', 'value' => '']);
array_unshift($options, ['label' => ' ', 'value' => '']);
return $options;
}

Expand Down
Loading

0 comments on commit f42be8a

Please sign in to comment.