Skip to content

Commit e8c2526

Browse files
authored
Merge pull request #5107 from magento-tsg-csl3/2.4-develop-pr2
[TSG-CSL3] For 2.4 (pr2)
2 parents 5067755 + 31daa38 commit e8c2526

File tree

12 files changed

+563
-183
lines changed

12 files changed

+563
-183
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,13 @@ protected function _saveProducts()
15691569
continue;
15701570
}
15711571

1572+
$storeId = !empty($rowData[self::COL_STORE])
1573+
? $this->getStoreIdByCode($rowData[self::COL_STORE])
1574+
: Store::DEFAULT_STORE_ID;
1575+
$rowExistingImages = $existingImages[$storeId][$rowSku] ?? [];
1576+
$rowStoreMediaGalleryValues = $rowExistingImages;
1577+
$rowExistingImages += $existingImages[Store::DEFAULT_STORE_ID][$rowSku] ?? [];
1578+
15721579
if (self::SCOPE_STORE == $rowScope) {
15731580
// set necessary data from SCOPE_DEFAULT row
15741581
$rowData[self::COL_TYPE] = $this->skuProcessor->getNewSku($rowSku)['type_id'];
@@ -1672,19 +1679,16 @@ protected function _saveProducts()
16721679

16731680
// 5. Media gallery phase
16741681
list($rowImages, $rowLabels) = $this->getImagesFromRow($rowData);
1675-
$storeId = !empty($rowData[self::COL_STORE])
1676-
? $this->getStoreIdByCode($rowData[self::COL_STORE])
1677-
: Store::DEFAULT_STORE_ID;
16781682
$imageHiddenStates = $this->getImagesHiddenStates($rowData);
16791683
foreach (array_keys($imageHiddenStates) as $image) {
1680-
if (array_key_exists($rowSku, $existingImages)
1681-
&& array_key_exists($image, $existingImages[$rowSku])
1682-
) {
1683-
$rowImages[self::COL_MEDIA_IMAGE][] = $image;
1684+
//Mark image as uploaded if it exists
1685+
if (array_key_exists($image, $rowExistingImages)) {
16841686
$uploadedImages[$image] = $image;
16851687
}
1686-
1687-
if (empty($rowImages)) {
1688+
//Add image to hide to images list if it does not exist
1689+
if (empty($rowImages[self::COL_MEDIA_IMAGE])
1690+
|| !in_array($image, $rowImages[self::COL_MEDIA_IMAGE])
1691+
) {
16881692
$rowImages[self::COL_MEDIA_IMAGE][] = $image;
16891693
}
16901694
}
@@ -1725,24 +1729,29 @@ protected function _saveProducts()
17251729
continue;
17261730
}
17271731

1728-
if (isset($existingImages[$rowSku][$uploadedFile])) {
1729-
$currentFileData = $existingImages[$rowSku][$uploadedFile];
1732+
if (isset($rowExistingImages[$uploadedFile])) {
1733+
$currentFileData = $rowExistingImages[$uploadedFile];
1734+
$currentFileData['store_id'] = $storeId;
1735+
$storeMediaGalleryValueExists = isset($rowStoreMediaGalleryValues[$uploadedFile]);
1736+
if (array_key_exists($uploadedFile, $imageHiddenStates)
1737+
&& $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile]
1738+
) {
1739+
$imagesForChangeVisibility[] = [
1740+
'disabled' => $imageHiddenStates[$uploadedFile],
1741+
'imageData' => $currentFileData,
1742+
'exists' => $storeMediaGalleryValueExists
1743+
];
1744+
$storeMediaGalleryValueExists = true;
1745+
}
1746+
17301747
if (isset($rowLabels[$column][$columnImageKey])
17311748
&& $rowLabels[$column][$columnImageKey] !=
17321749
$currentFileData['label']
17331750
) {
17341751
$labelsForUpdate[] = [
17351752
'label' => $rowLabels[$column][$columnImageKey],
1736-
'imageData' => $currentFileData
1737-
];
1738-
}
1739-
1740-
if (array_key_exists($uploadedFile, $imageHiddenStates)
1741-
&& $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile]
1742-
) {
1743-
$imagesForChangeVisibility[] = [
1744-
'disabled' => $imageHiddenStates[$uploadedFile],
1745-
'imageData' => $currentFileData
1753+
'imageData' => $currentFileData,
1754+
'exists' => $storeMediaGalleryValueExists
17461755
];
17471756
}
17481757
} else {

app/code/Magento/CatalogImportExport/Model/Import/Product/MediaGalleryProcessor.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Magento\Framework\App\ResourceConnection;
1313
use Magento\Framework\EntityManager\MetadataPool;
1414
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
15-
use Magento\Store\Model\Store;
1615

1716
/**
1817
* Process and saves images during import.
@@ -179,13 +178,15 @@ private function updateMediaGalleryField(array $data, $field)
179178
$insertData = [];
180179
foreach ($data as $datum) {
181180
$imageData = $datum['imageData'];
181+
$exists = $datum['exists'] ?? true;
182182

183-
if ($imageData[$field] === null) {
183+
if (!$exists) {
184184
$insertData[] = [
185185
$field => $datum[$field],
186186
$this->getProductEntityLinkField() => $imageData[$this->getProductEntityLinkField()],
187187
'value_id' => $imageData['value_id'],
188-
'store_id' => Store::DEFAULT_STORE_ID,
188+
'store_id' => $imageData['store_id'],
189+
'position' => $imageData['position'],
189190
];
190191
} else {
191192
$this->connection->update(
@@ -196,7 +197,7 @@ private function updateMediaGalleryField(array $data, $field)
196197
[
197198
$this->getProductEntityLinkField() . ' = ?' => $imageData[$this->getProductEntityLinkField()],
198199
'value_id = ?' => $imageData['value_id'],
199-
'store_id = ?' => Store::DEFAULT_STORE_ID,
200+
'store_id = ?' => $imageData['store_id'],
200201
]
201202
);
202203
}
@@ -240,14 +241,15 @@ public function getExistingImages(array $bunch)
240241
)->joinLeft(
241242
['mgv' => $this->mediaGalleryValueTableName],
242243
sprintf(
243-
'(mg.value_id = mgv.value_id AND mgv.%s = mgvte.%s AND mgv.store_id = %d)',
244+
'(mgv.%s = mgvte.%s AND mg.value_id = mgv.value_id)',
244245
$this->getProductEntityLinkField(),
245-
$this->getProductEntityLinkField(),
246-
Store::DEFAULT_STORE_ID
246+
$this->getProductEntityLinkField()
247247
),
248248
[
249+
'store_id' => 'mgv.store_id',
249250
'label' => 'mgv.label',
250251
'disabled' => 'mgv.disabled',
252+
'position' => 'mgv.position',
251253
]
252254
)->joinInner(
253255
['pe' => $this->productEntityTableName],
@@ -259,7 +261,9 @@ public function getExistingImages(array $bunch)
259261
);
260262

261263
foreach ($this->connection->fetchAll($select) as $image) {
262-
$result[$image['sku']][$image['value']] = $image;
264+
$storeId = $image['store_id'];
265+
unset($image['store_id']);
266+
$result[$storeId][$image['sku']][$image['value']] = $image;
263267
}
264268

265269
return $result;

app/code/Magento/CurrencySymbol/Controller/Adminhtml/System/Currencysymbol/Save.php

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,68 @@
55
*/
66
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol;
77

8-
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
8+
use Magento\Backend\App\Action;
9+
use Magento\Backend\Model\View\Result\Redirect;
10+
use Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol as CurrencysymbolController;
11+
use Magento\CurrencySymbol\Model\System\CurrencysymbolFactory;
12+
use Magento\Framework\App\Action\HttpPostActionInterface;
13+
use Magento\Framework\Controller\ResultInterface;
14+
use Magento\Framework\Filter\FilterManager;
915

1016
/**
11-
* Class Save
17+
* Controller to save currency symbol
1218
*/
13-
class Save extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol implements HttpPostActionInterface
19+
class Save extends CurrencysymbolController implements HttpPostActionInterface
1420
{
21+
/**
22+
* @var FilterManager
23+
*/
24+
private $filterManager;
25+
26+
/**
27+
* @var CurrencysymbolFactory
28+
*/
29+
private $currencySymbolFactory;
30+
31+
/**
32+
* @param Action\Context $context
33+
* @param FilterManager $filterManager
34+
* @param CurrencysymbolFactory $currencySymbolFactory
35+
*/
36+
public function __construct(
37+
Action\Context $context,
38+
FilterManager $filterManager,
39+
CurrencysymbolFactory $currencySymbolFactory
40+
) {
41+
parent::__construct($context);
42+
$this->filterManager = $filterManager;
43+
$this->currencySymbolFactory = $currencySymbolFactory;
44+
}
45+
1546
/**
1647
* Save custom Currency symbol
1748
*
18-
* @return void
49+
* @return ResultInterface
1950
*/
2051
public function execute()
2152
{
53+
/** @var Redirect $resultRedirect */
54+
$resultRedirect = $this->resultRedirectFactory->create();
2255
$symbolsDataArray = $this->getRequest()->getParam('custom_currency_symbol', null);
2356
if (is_array($symbolsDataArray)) {
2457
foreach ($symbolsDataArray as &$symbolsData) {
25-
/** @var $filterManager \Magento\Framework\Filter\FilterManager */
26-
$filterManager = $this->_objectManager->get(\Magento\Framework\Filter\FilterManager::class);
27-
$symbolsData = $filterManager->stripTags($symbolsData);
58+
$symbolsData = $this->filterManager->stripTags($symbolsData);
2859
}
2960
}
3061

3162
try {
32-
$this->_objectManager->create(\Magento\CurrencySymbol\Model\System\Currencysymbol::class)
33-
->setCurrencySymbolsData($symbolsDataArray);
63+
$currencySymbol = $this->currencySymbolFactory->create();
64+
$currencySymbol->setCurrencySymbolsData($symbolsDataArray);
3465
$this->messageManager->addSuccessMessage(__('You applied the custom currency symbols.'));
3566
} catch (\Exception $e) {
3667
$this->messageManager->addErrorMessage($e->getMessage());
3768
}
3869

39-
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*')));
70+
return $resultRedirect->setPath('*');
4071
}
4172
}

0 commit comments

Comments
 (0)