57 ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE,
66 ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP,
75 ImportAdvancedPricing::COL_SKU =>
'',
76 ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE =>
'',
77 ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP =>
'',
78 ImportAdvancedPricing::COL_TIER_PRICE_QTY =>
'',
79 ImportAdvancedPricing::COL_TIER_PRICE =>
'',
80 ImportAdvancedPricing::COL_TIER_PRICE_TYPE =>
'' 86 private $websiteCodesMap = [];
110 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
114 \Psr\Log\LoggerInterface
$logger,
124 \
Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
126 \
Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver,
129 $this->_storeResolver = $storeResolver;
145 $attributeColFactory,
158 $productTypes = $this->_exportConfig->getEntityTypes(CatalogProduct::ENTITY);
159 foreach (
$productTypes as $productTypeName => $productTypeConfig) {
160 if (!(
$model = $this->_typeFactory->create($productTypeConfig[
'model']))) {
161 throw new \Magento\Framework\Exception\LocalizedException(
162 __(
'Entity type model \'%1\' is not found', $productTypeConfig[
'model'])
165 if (!
$model instanceof \
Magento\CatalogImportExport\Model\
Export\Product\Type\AbstractType) {
166 throw new \Magento\Framework\Exception\LocalizedException(
168 'Entity type model must be an instance of' 169 .
' \Magento\CatalogImportExport\Model\Export\Product\Type\AbstractType' 173 if (
$model->isSuitable()) {
174 $this->_productTypeModels[$productTypeName] =
$model;
175 $this->_disabledAttrs = array_merge($this->_disabledAttrs,
$model->getDisabledAttrs());
176 $this->_indexValueAttributes = array_merge(
177 $this->_indexValueAttributes,
178 $model->getIndexValueAttributes()
182 if (!$this->_productTypeModels) {
183 throw new \Magento\Framework\Exception\LocalizedException(
184 __(
'There are no product types available for export')
187 $this->_disabledAttrs = array_unique($this->_disabledAttrs);
207 $entityCollection->setOrder(
'has_options',
'asc');
211 if ($entityCollection->count() == 0) {
215 foreach ($exportData as $dataRow) {
216 $writer->writeRow($dataRow);
218 if ($entityCollection->getCurPage() >= $entityCollection->getLastPageNumber()) {
222 return $writer->getContents();
238 if (
$attribute->getAttributeCode() == ImportAdvancedPricing::COL_TIER_PRICE
244 $this->_passTierPrice = 1;
264 if ($this->_passTierPrice) {
271 if (!empty($productsByStores)) {
273 $productLinkIds = [];
275 foreach ($productsByStores as
$product) {
276 $productLinkIds[array_pop(
$product)[$linkField]] =
true;
278 $productLinkIds = array_keys($productLinkIds);
279 $tierPricesData = $this->fetchTierPrices($productLinkIds);
280 $exportData = $this->prepareExportData(
284 if (!empty($exportData)) {
288 }
catch (\Throwable $e) {
289 $this->_logger->critical($e);
307 foreach (array_keys($exportRow) as $keyTemplate) {
309 if (in_array($keyTemplate, $this->_priceWebsite)) {
312 $tierPriceData[$keyTemplate]
314 }
elseif (in_array($keyTemplate, $this->_priceCustomerGroup)) {
318 $tierPriceData[$keyTemplate],
321 unset($exportRow[ImportAdvancedPricing::VALUE_ALL_GROUPS]);
323 === ImportAdvancedPricing::COL_TIER_PRICE
327 $exportRow[$keyTemplate]
328 =
$tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
329 ?
$tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
331 $exportRow[ImportAdvancedPricing::COL_TIER_PRICE_TYPE]
351 private function prepareExportData(
353 array $tierPricesData
356 $productLinkIdToSkuMap = [];
363 $linkedTierPricesData = [];
366 $linkedTierPricesData[] = array_merge(
368 [ImportAdvancedPricing::COL_SKU => $sku]
373 $customExportData = [];
374 foreach ($linkedTierPricesData as
$row) {
375 $customExportData[] = $this->createExportRow(
$row);
378 return $customExportData;
392 $customExportData = [];
393 foreach ($exportData as $key =>
$row) {
395 foreach ($exportRow as $keyTemplate => $valueTemplate) {
396 if (isset(
$row[$keyTemplate])) {
397 if (in_array($keyTemplate, $this->_priceWebsite)) {
401 }
elseif (in_array($keyTemplate, $this->_priceCustomerGroup)) {
404 isset(
$row[ImportAdvancedPricing::VALUE_ALL_GROUPS])
405 ?
$row[ImportAdvancedPricing::VALUE_ALL_GROUPS]
408 unset($exportRow[ImportAdvancedPricing::VALUE_ALL_GROUPS]);
409 }
elseif ($keyTemplate === ImportAdvancedPricing::COL_TIER_PRICE) {
410 $exportRow[$keyTemplate] =
$row[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
411 ?
$row[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
412 :
$row[ImportAdvancedPricing::COL_TIER_PRICE];
413 $exportRow[ImportAdvancedPricing::COL_TIER_PRICE_TYPE]
414 = $this->tierPriceTypeValue(
$row[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]);
416 $exportRow[$keyTemplate] =
$row[$keyTemplate];
421 $customExportData[$key] = $exportRow;
425 return $customExportData;
436 return $tierPriceData[ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE]
437 ? ImportAdvancedPricing::TIER_PRICE_TYPE_PERCENT
438 : ImportAdvancedPricing::TIER_PRICE_TYPE_FIXED;
451 private function fetchTierPrices(array
$productIds): array
454 throw new \InvalidArgumentException(
455 'Can only load tier prices for specific products' 459 $pricesTable = ImportAdvancedPricing::TABLE_TIER_PRICE;
460 $exportFilter =
null;
461 $priceFromFilter =
null;
462 $priceToFilter =
null;
468 ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE =>
'ap.website_id',
469 ImportAdvancedPricing::VALUE_ALL_GROUPS =>
'ap.all_groups',
470 ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP =>
'ap.customer_group_id',
471 ImportAdvancedPricing::COL_TIER_PRICE_QTY =>
'ap.qty',
472 ImportAdvancedPricing::COL_TIER_PRICE =>
'ap.value',
473 ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE =>
'ap.percentage_value',
474 'product_link_id' =>
'ap.' .$productEntityLinkField,
476 if ($exportFilter && array_key_exists(
'tier_price', $exportFilter)) {
477 if (!empty($exportFilter[
'tier_price'][0])) {
478 $priceFromFilter = $exportFilter[
'tier_price'][0];
480 if (!empty($exportFilter[
'tier_price'][1])) {
481 $priceToFilter = $exportFilter[
'tier_price'][1];
485 $select = $this->_connection->select()
487 [
'ap' => $this->_resource->getTableName($pricesTable)],
491 'ap.'.$productEntityLinkField.
' IN (?)',
495 if ($priceFromFilter !==
null) {
496 $select->where(
'ap.value >= ?', $priceFromFilter);
498 if ($priceToFilter !==
null) {
499 $select->where(
'ap.value <= ?', $priceToFilter);
501 if ($priceFromFilter || $priceToFilter) {
502 $select->orWhere(
'ap.percentage_value IS NOT NULL');
505 return $this->_connection->fetchAll(
$select);
524 if (
$table == ImportAdvancedPricing::TABLE_TIER_PRICE) {
526 ImportAdvancedPricing::COL_SKU =>
'cpe.sku',
527 ImportAdvancedPricing::COL_TIER_PRICE_WEBSITE =>
'ap.website_id',
528 ImportAdvancedPricing::VALUE_ALL_GROUPS =>
'ap.all_groups',
529 ImportAdvancedPricing::COL_TIER_PRICE_CUSTOMER_GROUP =>
'ap.customer_group_id',
530 ImportAdvancedPricing::COL_TIER_PRICE_QTY =>
'ap.qty',
531 ImportAdvancedPricing::COL_TIER_PRICE =>
'ap.value',
532 ImportAdvancedPricing::COL_TIER_PRICE_PERCENTAGE_VALUE =>
'ap.percentage_value',
534 if (isset($exportFilter) && !empty($exportFilter)) {
535 $price = $exportFilter[
'tier_price'];
539 if (isset($exportFilter) && !empty($exportFilter)) {
541 if (isset($date[0]) && !empty($date[0])) {
542 $updatedAtFrom = $this->_localeDate->date($date[0],
null,
false)->format(
'Y-m-d H:i:s');
544 if (isset($date[1]) && !empty($date[1])) {
545 $updatedAtTo = $this->_localeDate->date($date[1],
null,
false)->format(
'Y-m-d H:i:s');
550 $select = $this->_connection->select()
552 [
'cpe' => $this->_resource->getTableName(
'catalog_product_entity')],
556 [
'ap' => $this->_resource->getTableName(
$table)],
557 'ap.' . $productEntityLinkField .
' = cpe.' . $productEntityLinkField,
560 ->where(
'cpe.entity_id IN (?)', $listSku);
569 $select->orWhere(
'ap.percentage_value IS NOT NULL');
571 if (isset($updatedAtFrom) && !empty($updatedAtFrom)) {
572 $select->where(
'cpe.updated_at >= ?', $updatedAtFrom);
574 if (isset($updatedAtTo) && !empty($updatedAtTo)) {
575 $select->where(
'cpe.updated_at <= ?', $updatedAtTo);
577 $exportData = $this->_connection->fetchAll(
$select);
578 }
catch (\Exception $e) {
594 if (!array_key_exists(
$websiteId, $this->websiteCodesMap)) {
596 ? ImportAdvancedPricing::VALUE_ALL_WEBSITES
597 : $this->_storeManager->getWebsite(
$websiteId)->getCode();
600 $currencyCode = $this->_storeManager->getWebsite(
$websiteId)
601 ->getBaseCurrencyCode();
628 if ($allGroups !== 0) {
629 return ImportAdvancedPricing::VALUE_ALL_GROUPS;
631 return $this->_groupRepository->getById(
$groupId)->getCode();
641 if (!$this->_entityTypeCode) {
642 $this->_entityTypeCode = CatalogProduct::ENTITY;
__construct(\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Eav\Model\Config $config, \Magento\Framework\App\ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Psr\Log\LoggerInterface $logger, \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory, \Magento\ImportExport\Model\Export\ConfigInterface $exportConfig, \Magento\Catalog\Model\ResourceModel\ProductFactory $productFactory, \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory $attrSetColFactory, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryColFactory, \Magento\CatalogInventory\Model\ResourceModel\Stock\ItemFactory $itemFactory, \Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory $optionColFactory, \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $attributeColFactory, \Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory, \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider, \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer, \Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver, \Magento\Customer\Api\GroupRepositoryInterface $groupRepository)
if($msrpShowOnGesture && $price['price']->getValue()< $product->getMsrp()) if($isSaleable) $tierPriceData
getTierPrices(array $listSku, $table)
_prepareEntityCollection(\Magento\Eav\Model\Entity\Collection\AbstractCollection $collection)
const ENTITY_ADVANCED_PRICING
_getWebsiteCode(int $websiteId)
elseif(isset( $params[ 'redirect_parent']))
const FILTER_ELEMENT_SKIP
paginateCollection($page, $pageSize)
getProductEntityLinkField()
_getEntityCollection($resetCollection=false)
correctExportData($exportData)
const FILTER_ELEMENT_GROUP
filterAttributeCollection(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection)
_getCustomerGroupById(int $groupId, int $allGroups=0)