19 class AdvancedPricing extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
61 ValidatorInterface::ERROR_INVALID_WEBSITE =>
'Invalid value in Website column (website does not exists?)',
62 ValidatorInterface::ERROR_SKU_IS_EMPTY =>
'SKU is empty',
63 ValidatorInterface::ERROR_SKU_NOT_FOUND_FOR_DELETE =>
'Product with specified SKU not found',
64 ValidatorInterface::ERROR_INVALID_TIER_PRICE_QTY =>
'Tier Price data price or quantity value is invalid',
65 ValidatorInterface::ERROR_INVALID_TIER_PRICE_SITE =>
'Tier Price data website is invalid',
66 ValidatorInterface::ERROR_INVALID_TIER_PRICE_GROUP =>
'Tier Price customer group is invalid',
67 ValidatorInterface::ERROR_INVALID_TIER_PRICE_TYPE =>
'Value for \'tier_price_value_type\' ' .
68 'attribute contains incorrect value, acceptable values are Fixed, Discount',
69 ValidatorInterface::ERROR_TIER_DATA_INCOMPLETE =>
'Tier Price data is incomplete',
70 ValidatorInterface::ERROR_INVALID_ATTRIBUTE_DECIMAL =>
71 'Value for \'%s\' attribute contains incorrect value, acceptable values are in decimal format',
166 private $productEntityLinkField;
199 \
Magento\CatalogImportExport\Model\
Import\Proxy\Product\ResourceModelFactory $resourceFactory,
201 \
Magento\Catalog\Helper\Data $catalogData,
202 \
Magento\CatalogImportExport\Model\
Import\Product\StoreResolver $storeResolver,
210 $this->_importExportData = $importExportData;
211 $this->_resourceHelper = $resourceHelper;
212 $this->_dataSourceModel = $importData;
213 $this->_connection =
$resource->getConnection(
'write');
214 $this->_resourceFactory = $resourceFactory;
216 $this->_catalogData = $catalogData;
217 $this->_storeResolver = $storeResolver;
218 $this->_importProduct = $importProduct;
220 $this->_catalogProductEntity = $this->_resourceFactory->create()->getTable(
'catalog_product_entity');
226 foreach (array_merge($this->errorMessageTemplates, $this->_messageTemplates) as $errorCode =>
$message) {
239 return $this->_validators[
$type];
249 return 'advanced_pricing';
262 if (isset($this->_validatedRows[$rowNum])) {
265 $this->_validatedRows[$rowNum] =
true;
268 if (!isset($rowData[self::COL_SKU])) {
269 $this->
addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, $rowNum);
274 if (!$this->
_getValidator(self::VALIDATOR_MAIN)->isValid($rowData)) {
279 if (isset($rowData[self::COL_SKU])) {
282 if (
false === $sku) {
283 $this->
addRowError(ValidatorInterface::ERROR_ROW_IS_ORPHAN, $rowNum);
325 $this->_cachedSkuToDelete =
null;
327 while ($bunch = $this->_dataSourceModel->getNextBunch()) {
328 foreach ($bunch as $rowNum => $rowData) {
332 $listSku[] = $rowSku;
368 $this->_cachedSkuToDelete =
null;
371 while ($bunch = $this->_dataSourceModel->getNextBunch()) {
373 foreach ($bunch as $rowNum => $rowData) {
375 $this->
addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, $rowNum);
384 $listSku[] = $rowSku;
385 if (!empty($rowData[self::COL_TIER_PRICE_WEBSITE])) {
389 $rowData[self::COL_TIER_PRICE_CUSTOMER_GROUP]
396 'website_id' => $this->
getWebSiteId($rowData[self::COL_TIER_PRICE_WEBSITE])
434 foreach ($priceData as $sku => $priceRows) {
435 if (isset($oldSkus[$sku])) {
437 foreach ($priceRows as
$row) {
445 $this->_connection->insertOnDuplicate(
$tableName, $priceIn, [
'value',
'percentage_value']);
461 $productEntityLinkField = $this->getProductEntityLinkField();
463 if (!$this->_cachedSkuToDelete) {
464 $this->_cachedSkuToDelete = $this->_connection->fetchCol(
465 $this->_connection->select()
466 ->from($this->_catalogProductEntity, $productEntityLinkField)
467 ->where(
'sku IN (?)', $listSku)
470 if ($this->_cachedSkuToDelete) {
472 $this->countItemsDeleted += $this->_connection->delete(
474 $this->_connection->quoteInto($productEntityLinkField .
' IN (?)', $this->_cachedSkuToDelete)
477 }
catch (\Exception $e) {
481 $this->
addRowError(ValidatorInterface::ERROR_SKU_IS_EMPTY, 0);
496 $updatedAt = $this->dateTime->gmtDate(
'Y-m-d H:i:s');
497 $this->_connection->update(
498 $this->_catalogProductEntity,
499 [\
Magento\Catalog\Model\Category::KEY_UPDATED_AT => $updatedAt],
500 $this->_connection->quoteInto(
'sku IN (?)', array_unique($listSku))
514 $this->_catalogData->isPriceGlobal() ? 0 : $this->_storeResolver->getWebsiteCodeToId(
$websiteCode);
526 $customerGroups = $this->
_getValidator(self::VALIDATOR_TEAR_PRICE)->getCustomerGroups();
527 return $customerGroup == self::VALUE_ALL_GROUPS ? 0 : $customerGroups[$customerGroup];
537 if ($this->_oldSkus ===
null) {
538 $this->_oldSkus = $this->_connection->fetchPairs(
539 $this->_connection->select()->from(
540 $this->_catalogProductEntity,
541 [
'sku', $this->getProductEntityLinkField()]
558 $existProductIds = array_intersect_key($oldSkus,
$prices);
559 if (!count($existProductIds)) {
564 $productEntityLinkField = $this->getProductEntityLinkField();
565 $existingPrices = $this->_connection->fetchAssoc(
566 $this->_connection->select()->from(
568 [
'value_id', $productEntityLinkField,
'all_groups',
'customer_group_id']
569 )->where($productEntityLinkField .
' IN (?)', $existProductIds)
571 foreach ($existingPrices as $existingPrice) {
572 foreach (
$prices as $sku => $skuPrices) {
573 if (isset($oldSkus[$sku]) && $existingPrice[$productEntityLinkField] == $oldSkus[$sku]) {
592 if ($existingPrice[
'all_groups'] ==
$price[
'all_groups']
593 && $existingPrice[
'customer_group_id'] ==
$price[
'customer_group_id']
595 $this->countItemsUpdated++;
609 $this->countItemsCreated += count($productPrices);
622 private function getProductEntityLinkField()
624 if (!$this->productEntityLinkField) {
626 ->getMetadata(\
Magento\Catalog\Api\Data\ProductInterface::class)
629 return $this->productEntityLinkField;
const COL_TIER_PRICE_TYPE
elseif(isset( $params[ 'redirect_parent']))
saveProductPrices(array $priceData, $table)
saveAndReplaceAdvancedPrices()
const COL_TIER_PRICE_WEBSITE
getCustomerGroupId($customerGroup)
incrementCounterUpdated($prices, $existingPrice)
deleteProductTierPrices(array $listSku, $table)
const COL_TIER_PRICE_PERCENTAGE_VALUE
const VALIDATOR_TEAR_PRICE
const DEFAULT_ALL_GROUPS_GROUPED_PRICE_VALUE
const TIER_PRICE_TYPE_FIXED
processCountExistingPrices($prices, $table)
const TIER_PRICE_TYPE_PERCENT
addRowError( $errorCode, $errorRowNum, $colName=null, $errorMessage=null, $errorLevel=ProcessingError::ERROR_LEVEL_CRITICAL, $errorDescription=null)
processCountNewPrices(array $tierPrices)
__construct(\Magento\Framework\Json\Helper\Data $jsonHelper, \Magento\ImportExport\Helper\Data $importExportData, \Magento\ImportExport\Model\ResourceModel\Import\Data $importData, \Magento\Eav\Model\Config $config, \Magento\Framework\App\ResourceConnection $resource, \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\Stdlib\StringUtils $string, ProcessingErrorAggregatorInterface $errorAggregator, \Magento\Framework\Stdlib\DateTime\DateTime $dateTime, \Magento\CatalogImportExport\Model\Import\Proxy\Product\ResourceModelFactory $resourceFactory, \Magento\Catalog\Model\Product $productModel, \Magento\Catalog\Helper\Data $catalogData, \Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver, ImportProduct $importProduct, AdvancedPricing\Validator $validator, AdvancedPricing\Validator\Website $websiteValidator, AdvancedPricing\Validator\TierPrice $tierPriceValidator)
validateRow(array $rowData, $rowNum)
const COL_TIER_PRICE_CUSTOMER_GROUP
setUpdatedAt(array $listSku)
if(!isset($_GET['website_code'])) $websiteCode
getWebSiteId($websiteCode)