Skip to content

Commit

Permalink
Merge pull request #5107 from magento-tsg-csl3/2.4-develop-pr2
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr2)
  • Loading branch information
zakdma authored Dec 13, 2019
2 parents 5067755 + 31daa38 commit e8c2526
Show file tree
Hide file tree
Showing 12 changed files with 563 additions and 183 deletions.
51 changes: 30 additions & 21 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,13 @@ protected function _saveProducts()
continue;
}

$storeId = !empty($rowData[self::COL_STORE])
? $this->getStoreIdByCode($rowData[self::COL_STORE])
: Store::DEFAULT_STORE_ID;
$rowExistingImages = $existingImages[$storeId][$rowSku] ?? [];
$rowStoreMediaGalleryValues = $rowExistingImages;
$rowExistingImages += $existingImages[Store::DEFAULT_STORE_ID][$rowSku] ?? [];

if (self::SCOPE_STORE == $rowScope) {
// set necessary data from SCOPE_DEFAULT row
$rowData[self::COL_TYPE] = $this->skuProcessor->getNewSku($rowSku)['type_id'];
Expand Down Expand Up @@ -1672,19 +1679,16 @@ protected function _saveProducts()

// 5. Media gallery phase
list($rowImages, $rowLabels) = $this->getImagesFromRow($rowData);
$storeId = !empty($rowData[self::COL_STORE])
? $this->getStoreIdByCode($rowData[self::COL_STORE])
: Store::DEFAULT_STORE_ID;
$imageHiddenStates = $this->getImagesHiddenStates($rowData);
foreach (array_keys($imageHiddenStates) as $image) {
if (array_key_exists($rowSku, $existingImages)
&& array_key_exists($image, $existingImages[$rowSku])
) {
$rowImages[self::COL_MEDIA_IMAGE][] = $image;
//Mark image as uploaded if it exists
if (array_key_exists($image, $rowExistingImages)) {
$uploadedImages[$image] = $image;
}

if (empty($rowImages)) {
//Add image to hide to images list if it does not exist
if (empty($rowImages[self::COL_MEDIA_IMAGE])
|| !in_array($image, $rowImages[self::COL_MEDIA_IMAGE])
) {
$rowImages[self::COL_MEDIA_IMAGE][] = $image;
}
}
Expand Down Expand Up @@ -1725,24 +1729,29 @@ protected function _saveProducts()
continue;
}

if (isset($existingImages[$rowSku][$uploadedFile])) {
$currentFileData = $existingImages[$rowSku][$uploadedFile];
if (isset($rowExistingImages[$uploadedFile])) {
$currentFileData = $rowExistingImages[$uploadedFile];
$currentFileData['store_id'] = $storeId;
$storeMediaGalleryValueExists = isset($rowStoreMediaGalleryValues[$uploadedFile]);
if (array_key_exists($uploadedFile, $imageHiddenStates)
&& $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile]
) {
$imagesForChangeVisibility[] = [
'disabled' => $imageHiddenStates[$uploadedFile],
'imageData' => $currentFileData,
'exists' => $storeMediaGalleryValueExists
];
$storeMediaGalleryValueExists = true;
}

if (isset($rowLabels[$column][$columnImageKey])
&& $rowLabels[$column][$columnImageKey] !=
$currentFileData['label']
) {
$labelsForUpdate[] = [
'label' => $rowLabels[$column][$columnImageKey],
'imageData' => $currentFileData
];
}

if (array_key_exists($uploadedFile, $imageHiddenStates)
&& $currentFileData['disabled'] != $imageHiddenStates[$uploadedFile]
) {
$imagesForChangeVisibility[] = [
'disabled' => $imageHiddenStates[$uploadedFile],
'imageData' => $currentFileData
'imageData' => $currentFileData,
'exists' => $storeMediaGalleryValueExists
];
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
use Magento\Store\Model\Store;

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

if ($imageData[$field] === null) {
if (!$exists) {
$insertData[] = [
$field => $datum[$field],
$this->getProductEntityLinkField() => $imageData[$this->getProductEntityLinkField()],
'value_id' => $imageData['value_id'],
'store_id' => Store::DEFAULT_STORE_ID,
'store_id' => $imageData['store_id'],
'position' => $imageData['position'],
];
} else {
$this->connection->update(
Expand All @@ -196,7 +197,7 @@ private function updateMediaGalleryField(array $data, $field)
[
$this->getProductEntityLinkField() . ' = ?' => $imageData[$this->getProductEntityLinkField()],
'value_id = ?' => $imageData['value_id'],
'store_id = ?' => Store::DEFAULT_STORE_ID,
'store_id = ?' => $imageData['store_id'],
]
);
}
Expand Down Expand Up @@ -240,14 +241,15 @@ public function getExistingImages(array $bunch)
)->joinLeft(
['mgv' => $this->mediaGalleryValueTableName],
sprintf(
'(mg.value_id = mgv.value_id AND mgv.%s = mgvte.%s AND mgv.store_id = %d)',
'(mgv.%s = mgvte.%s AND mg.value_id = mgv.value_id)',
$this->getProductEntityLinkField(),
$this->getProductEntityLinkField(),
Store::DEFAULT_STORE_ID
$this->getProductEntityLinkField()
),
[
'store_id' => 'mgv.store_id',
'label' => 'mgv.label',
'disabled' => 'mgv.disabled',
'position' => 'mgv.position',
]
)->joinInner(
['pe' => $this->productEntityTableName],
Expand All @@ -259,7 +261,9 @@ public function getExistingImages(array $bunch)
);

foreach ($this->connection->fetchAll($select) as $image) {
$result[$image['sku']][$image['value']] = $image;
$storeId = $image['store_id'];
unset($image['store_id']);
$result[$storeId][$image['sku']][$image['value']] = $image;
}

return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,68 @@
*/
namespace Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol;

use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Backend\App\Action;
use Magento\Backend\Model\View\Result\Redirect;
use Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol as CurrencysymbolController;
use Magento\CurrencySymbol\Model\System\CurrencysymbolFactory;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Filter\FilterManager;

/**
* Class Save
* Controller to save currency symbol
*/
class Save extends \Magento\CurrencySymbol\Controller\Adminhtml\System\Currencysymbol implements HttpPostActionInterface
class Save extends CurrencysymbolController implements HttpPostActionInterface
{
/**
* @var FilterManager
*/
private $filterManager;

/**
* @var CurrencysymbolFactory
*/
private $currencySymbolFactory;

/**
* @param Action\Context $context
* @param FilterManager $filterManager
* @param CurrencysymbolFactory $currencySymbolFactory
*/
public function __construct(
Action\Context $context,
FilterManager $filterManager,
CurrencysymbolFactory $currencySymbolFactory
) {
parent::__construct($context);
$this->filterManager = $filterManager;
$this->currencySymbolFactory = $currencySymbolFactory;
}

/**
* Save custom Currency symbol
*
* @return void
* @return ResultInterface
*/
public function execute()
{
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
$symbolsDataArray = $this->getRequest()->getParam('custom_currency_symbol', null);
if (is_array($symbolsDataArray)) {
foreach ($symbolsDataArray as &$symbolsData) {
/** @var $filterManager \Magento\Framework\Filter\FilterManager */
$filterManager = $this->_objectManager->get(\Magento\Framework\Filter\FilterManager::class);
$symbolsData = $filterManager->stripTags($symbolsData);
$symbolsData = $this->filterManager->stripTags($symbolsData);
}
}

try {
$this->_objectManager->create(\Magento\CurrencySymbol\Model\System\Currencysymbol::class)
->setCurrencySymbolsData($symbolsDataArray);
$currencySymbol = $this->currencySymbolFactory->create();
$currencySymbol->setCurrencySymbolsData($symbolsDataArray);
$this->messageManager->addSuccessMessage(__('You applied the custom currency symbols.'));
} catch (\Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
}

$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($this->getUrl('*')));
return $resultRedirect->setPath('*');
}
}
Loading

0 comments on commit e8c2526

Please sign in to comment.