Skip to content

Commit

Permalink
Merge pull request #666 from magento-dragons/MAGETWO-42501
Browse files Browse the repository at this point in the history
[DRAGONS] Removing group price
  • Loading branch information
dkvashninbay committed Oct 2, 2015
2 parents c440305 + 2e2230a commit 0925d89
Show file tree
Hide file tree
Showing 126 changed files with 329 additions and 4,768 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,13 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
*/
protected $_passTierPrice = 0;

/**
* @var int
*/
protected $_passGroupPrice = 0;

/**
* List of items websites
*
* @var array
*/
protected $_priceWebsite = [
ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE,
ImportAdvancedPricing::COL_GROUP_PRICE_WEBSITE,
];

/**
Expand All @@ -69,7 +63,6 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
*/
protected $_priceCustomerGroup = [
ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP,
ImportAdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP,
];

/**
Expand All @@ -79,9 +72,6 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
*/
protected $templateExportData = [
ImportAdvancedPricing::COL_SKU => '',
ImportAdvancedPricing::COL_GROUP_PRICE_WEBSITE => '',
ImportAdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP => '',
ImportAdvancedPricing::COL_GROUP_PRICE => '',
ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE => '',
ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP => '',
ImportAdvancedPricing::COL_TIER_PRICE_QTY => '',
Expand Down Expand Up @@ -246,14 +236,6 @@ public function filterAttributeCollection(\Magento\Eav\Model\Resource\Entity\Att
) {
$this->_passTierPrice = 1;
}
if ($attribute->getAttributeCode() == ImportAdvancedPricing::COL_GROUP_PRICE
&& in_array(
$attribute->getId(),
$this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP]
)
) {
$this->_passGroupPrice = 1;
}
}
$collection->removeItemByKey($attribute->getId());
}
Expand All @@ -277,16 +259,10 @@ protected function getExportData()
$rawData = $this->collectRawData();
$productIds = array_keys($rawData);
if (isset($productIds)) {
if (!$this->_passGroupPrice) {
$exportData = array_merge(
$exportData,
$this->getTierAndGroupPrices($productIds, ImportAdvancedPricing::TABLE_GROUPED_PRICE)
);
}
if (!$this->_passTierPrice) {
$exportData = array_merge(
$exportData,
$this->getTierAndGroupPrices($productIds, ImportAdvancedPricing::TABLE_TIER_PRICE)
$this->getTierPrices($productIds, ImportAdvancedPricing::TABLE_TIER_PRICE)
);
}
}
Expand Down Expand Up @@ -347,22 +323,12 @@ protected function correctExportData($exportData)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function getTierAndGroupPrices(array $listSku, $table)
protected function getTierPrices(array $listSku, $table)
{
if (isset($this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP])) {
$exportFilter = $this->_parameters[\Magento\ImportExport\Model\Export::FILTER_ELEMENT_GROUP];
}
if ($table == ImportAdvancedPricing::TABLE_GROUPED_PRICE) {
$selectFields = [
ImportAdvancedPricing::COL_SKU => 'cpe.sku',
ImportAdvancedPricing::COL_GROUP_PRICE_WEBSITE => 'ap.website_id',
ImportAdvancedPricing::COL_GROUP_PRICE_CUSTOMER_GROUP => 'ap.customer_group_id',
ImportAdvancedPricing::COL_GROUP_PRICE => 'ap.value'
];
if (isset($exportFilter) && !empty($exportFilter)) {
$price = $exportFilter['group_price'];
}
} elseif ($table == ImportAdvancedPricing::TABLE_TIER_PRICE) {
if ($table == ImportAdvancedPricing::TABLE_TIER_PRICE) {
$selectFields = [
ImportAdvancedPricing::COL_SKU => 'cpe.sku',
ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE => 'ap.website_id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,8 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract

const COL_TIER_PRICE = 'tier_price';

const COL_GROUP_PRICE_WEBSITE = 'group_price_website';

const COL_GROUP_PRICE_CUSTOMER_GROUP = 'group_price_customer_group';

const COL_GROUP_PRICE = 'group_price';

const TABLE_TIER_PRICE = 'catalog_product_entity_tier_price';

const TABLE_GROUPED_PRICE = 'catalog_product_entity_group_price';

const DEFAULT_ALL_GROUPS_GROUPED_PRICE_VALUE = '0';

const ENTITY_TYPE_CODE = 'advanced_pricing';
Expand All @@ -50,7 +42,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract

const VALIDATOR_WEBSITE = 'validator_website';

const VALIDATOR_GROUP_PRICE = 'validator_group_price';
const VALIDATOR_TEAR_PRICE = 'validator_tear_price';

/**
* Validation failure message template definitions
Expand All @@ -65,9 +57,6 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
ValidatorInterface::ERROR_INVALID_TIER_PRICE_SITE => 'Tier Price data website is invalid',
ValidatorInterface::ERROR_INVALID_TIER_PRICE_GROUP => 'Tier Price customer group is invalid',
ValidatorInterface::ERROR_TIER_DATA_INCOMPLETE => 'Tier Price data is incomplete',
ValidatorInterface::ERROR_INVALID_GROUP_PRICE_SITE => 'Group Price data website is invalid',
ValidatorInterface::ERROR_INVALID_GROUP_PRICE_GROUP => 'Group Price customer group is invalid',
ValidatorInterface::ERROR_GROUP_PRICE_DATA_INCOMPLETE => 'Group Price data is incomplete',
ValidatorInterface::ERROR_INVALID_ATTRIBUTE_DECIMAL =>
'Value for \'%s\' attribute contains incorrect value, acceptable values are in decimal format',
];
Expand All @@ -90,9 +79,6 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
self::COL_TIER_PRICE_CUSTOMER_GROUP,
self::COL_TIER_PRICE_QTY,
self::COL_TIER_PRICE,
self::COL_GROUP_PRICE_WEBSITE,
self::COL_GROUP_PRICE_CUSTOMER_GROUP,
self::COL_GROUP_PRICE,
];

/**
Expand Down Expand Up @@ -179,7 +165,7 @@ class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\Abstract
* @param ImportProduct $importProduct
* @param AdvancedPricing\Validator $validator
* @param AdvancedPricing\Validator\Website $websiteValidator
* @param AdvancedPricing\Validator\GroupPrice $groupPriceValidator
* @param AdvancedPricing\Validator\TierPrice $tierPriceValidator
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
Expand All @@ -199,7 +185,7 @@ public function __construct(
ImportProduct $importProduct,
AdvancedPricing\Validator $validator,
AdvancedPricing\Validator\Website $websiteValidator,
AdvancedPricing\Validator\GroupPrice $groupPriceValidator
AdvancedPricing\Validator\TierPrice $tierPriceValidator
) {
$this->_localeDate = $localeDate;
$this->jsonHelper = $jsonHelper;
Expand All @@ -215,7 +201,7 @@ public function __construct(
$this->_validators[self::VALIDATOR_MAIN] = $validator->init($this);
$this->_oldSkus = $this->retrieveOldSkus();
$this->_validators[self::VALIDATOR_WEBSITE] = $websiteValidator;
$this->_validators[self::VALIDATOR_GROUP_PRICE] = $groupPriceValidator;
$this->_validators[self::VALIDATOR_TEAR_PRICE] = $tierPriceValidator;
$this->errorAggregator = $errorAggregator;
$this->_catalogProductEntity = $this->_resourceFactory->create()->getTable('catalog_product_entity');

Expand All @@ -228,7 +214,7 @@ public function __construct(
* Validator object getter.
*
* @param string $type
* @return AdvancedPricing\Validator|AdvancedPricing\Validator\Website|AdvancedPricing\Validator\GroupPrice
* @return AdvancedPricing\Validator|AdvancedPricing\Validator\Website
*/
protected function _getValidator($type)
{
Expand Down Expand Up @@ -333,8 +319,7 @@ public function deleteAdvancedPricing()
}
}
if ($listSku) {
$this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_GROUPED_PRICE);
$this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_TIER_PRICE);
$this->deleteProductTierPrices(array_unique($listSku), self::TABLE_TIER_PRICE);
$this->setUpdatedAt($listSku);
}
return $this;
Expand Down Expand Up @@ -367,7 +352,6 @@ protected function saveAndReplaceAdvancedPrices()
$listSku = [];
while ($bunch = $this->_dataSourceModel->getNextBunch()) {
$tierPrices = [];
$groupPrices = [];
foreach ($bunch as $rowNum => $rowData) {
if (!$this->validateRow($rowData, $rowNum)) {
$this->addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, $rowNum);
Expand All @@ -391,33 +375,19 @@ protected function saveAndReplaceAdvancedPrices()
'website_id' => $this->getWebsiteId($rowData[self::COL_TIER_PRICE_WEBSITE])
];
}
if (!empty($rowData[self::COL_GROUP_PRICE_WEBSITE])) {
$groupPrices[$rowSku][] = [
'all_groups' => self::DEFAULT_ALL_GROUPS_GROUPED_PRICE_VALUE,
'customer_group_id' => $this->getCustomerGroupId(
$rowData[self::COL_GROUP_PRICE_CUSTOMER_GROUP]
),
'value' => $rowData[self::COL_GROUP_PRICE],
'website_id' => $this->getWebSiteId($rowData[self::COL_GROUP_PRICE_WEBSITE])
];
}
}
if (\Magento\ImportExport\Model\Import::BEHAVIOR_REPLACE == $behavior) {
if ($listSku) {
$this->processCountNewPrices($tierPrices, $groupPrices);
if ($this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_GROUPED_PRICE)
&& $this->deleteProductTierAndGroupPrices(array_unique($listSku), self::TABLE_TIER_PRICE)) {
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE)
->saveProductPrices($groupPrices, self::TABLE_GROUPED_PRICE);
$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) {
$this->processCountExistingPrices($tierPrices, self::TABLE_TIER_PRICE)
->processCountExistingPrices($groupPrices, self::TABLE_GROUPED_PRICE)
->processCountNewPrices($tierPrices, $groupPrices);
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE)
->saveProductPrices($groupPrices, self::TABLE_GROUPED_PRICE);
->processCountNewPrices($tierPrices);
$this->saveProductPrices($tierPrices, self::TABLE_TIER_PRICE);
if ($listSku) {
$this->setUpdatedAt($listSku);
}
Expand Down Expand Up @@ -457,13 +427,13 @@ protected function saveProductPrices(array $priceData, $table)
}

/**
* Deletes tier prices and group prices.
* Deletes tier prices prices.
*
* @param array $listSku
* @param string $tableName
* @return bool
*/
protected function deleteProductTierAndGroupPrices(array $listSku, $tableName)
protected function deleteProductTierPrices(array $listSku, $tableName)
{
if ($tableName && $listSku) {
if (!$this->_cachedSkuToDelete) {
Expand Down Expand Up @@ -530,7 +500,7 @@ protected function getWebSiteId($websiteCode)
*/
protected function getCustomerGroupId($customerGroup)
{
$customerGroups = $this->_getValidator(self::VALIDATOR_GROUP_PRICE)->getCustomerGroups();
$customerGroups = $this->_getValidator(self::VALIDATOR_TEAR_PRICE)->getCustomerGroups();
return $customerGroup == self::VALUE_ALL_GROUPS ? 0 : $customerGroups[$customerGroup];
}

Expand Down Expand Up @@ -598,17 +568,13 @@ protected function incrementCounterUpdated($prices, $existingPrice)
* Count new prices
*
* @param array $tierPrices
* @param array $groupPrices
* @return $this
*/
protected function processCountNewPrices(array $tierPrices, array $groupPrices)
protected function processCountNewPrices(array $tierPrices)
{
foreach ($tierPrices as $productPrices) {
$this->countItemsCreated += count($productPrices);
}
foreach ($groupPrices as $productPrices) {
$this->countItemsCreated += count($productPrices);
}
$this->countItemsCreated -= $this->countItemsUpdated;

return $this;
Expand Down
Loading

0 comments on commit 0925d89

Please sign in to comment.