Skip to content

Commit

Permalink
ENGCOM-4281: Fix/issue 18761 #21189
Browse files Browse the repository at this point in the history
  • Loading branch information
sidolov authored Mar 15, 2019
2 parents 223f67f + 03b6d94 commit 769604a
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
* @param AdvancedPricing\Validator\Website $websiteValidator
* @param AdvancedPricing\Validator\TierPrice $tierPriceValidator
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @throws \Exception
*/
public function __construct(
\Magento\Framework\Json\Helper\Data $jsonHelper,
Expand Down Expand Up @@ -255,6 +256,7 @@ public function getEntityTypeCode()
* @param array $rowData
* @param int $rowNum
* @return bool
* @throws \Zend_Validate_Exception
*/
public function validateRow(array $rowData, $rowNum)
{
Expand Down Expand Up @@ -308,6 +310,7 @@ protected function _importData()
* Save advanced pricing
*
* @return $this
* @throws \Exception
*/
public function saveAdvancedPricing()
{
Expand All @@ -319,6 +322,7 @@ public function saveAdvancedPricing()
* Deletes Advanced price data from raw data.
*
* @return $this
* @throws \Exception
*/
public function deleteAdvancedPricing()
{
Expand Down Expand Up @@ -347,6 +351,7 @@ public function deleteAdvancedPricing()
* Replace advanced pricing
*
* @return $this
* @throws \Exception
*/
public function replaceAdvancedPricing()
{
Expand All @@ -360,6 +365,7 @@ public function replaceAdvancedPricing()
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @throws \Exception
*/
protected function saveAndReplaceAdvancedPrices()
{
Expand All @@ -368,8 +374,8 @@ protected function saveAndReplaceAdvancedPrices()
$this->_cachedSkuToDelete = null;
}
$listSku = [];
$tierPrices = [];
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
$tierPrices = [];
foreach ($bunch as $rowNum => $rowData) {
if (!$this->validateRow($rowData, $rowNum)) {
$this->addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, $rowNum);
Expand Down Expand Up @@ -397,15 +403,8 @@ protected function saveAndReplaceAdvancedPrices()
];
}
}
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
if ($listSku) {
$this->processCountNewPrices($tierPrices);
if ($this->deleteProductTierPrices(array_unique($listSku), self::TABLE_TIER_PRICE)) {
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE);
$this->setUpdatedAt($listSku);
}
}
} elseif (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {

if (\Magento\ImportExport\Model\Import::BEHAVIOR_APPEND == $behavior) {
$this->processCountExistingPrices($tierPrices, self::TABLE_TIER_PRICE)
->processCountNewPrices($tierPrices);

Expand All @@ -415,6 +414,17 @@ protected function saveAndReplaceAdvancedPrices()
}
}
}

if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
if ($listSku) {
$this->processCountNewPrices($tierPrices);
if ($this->deleteProductTierPrices(array_unique($listSku), self::TABLE_TIER_PRICE)) {
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE);
$this->setUpdatedAt($listSku);
}
}
}

return $this;
}

Expand All @@ -424,6 +434,7 @@ protected function saveAndReplaceAdvancedPrices()
* @param array $priceData
* @param string $table
* @return $this
* @throws \Exception
*/
protected function saveProductPrices(array $priceData, $table)
{
Expand Down Expand Up @@ -455,6 +466,7 @@ protected function saveProductPrices(array $priceData, $table)
* @param array $listSku
* @param string $table
* @return boolean
* @throws \Exception
*/
protected function deleteProductTierPrices(array $listSku, $table)
{
Expand Down Expand Up @@ -532,6 +544,7 @@ protected function getCustomerGroupId($customerGroup)
* Retrieve product skus
*
* @return array
* @throws \Exception
*/
protected function retrieveOldSkus()
{
Expand All @@ -552,6 +565,7 @@ protected function retrieveOldSkus()
* @param array $prices
* @param string $table
* @return $this
* @throws \Exception
*/
protected function processCountExistingPrices($prices, $table)
{
Expand Down

0 comments on commit 769604a

Please sign in to comment.