19 private $table =
'catalog_product_entity_decimal';
24 private $attributeResource;
29 private $attributeRepository;
34 private $productIdLocator;
41 private $metadataPool;
48 private $attributeCode;
62 private $itemsPerOperation = 500;
75 \
Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository,
80 $this->attributeResource = $attributeResource;
82 $this->attributeCode = $attributeCode;
83 $this->productIdLocator = $productIdLocator;
84 $this->metadataPool = $metadataPool;
93 public function get(array
$skus)
95 $ids = $this->retrieveAffectedIds(
$skus);
96 $select = $this->attributeResource->getConnection()
98 ->from($this->attributeResource->getTable($this->table));
99 return $this->attributeResource->getConnection()->fetchAll(
100 $select->where($this->getEntityLinkField() .
' IN (?)', $ids)
101 ->where(
'attribute_id = ?', $this->getAttributeId())
115 return $price[
'attribute_id'] = $this->getAttributeId();
117 $connection = $this->attributeResource->getConnection();
120 foreach (array_chunk(
$prices, $this->itemsPerOperation) as $pricesBunch) {
121 $this->attributeResource->getConnection()->insertOnDuplicate(
122 $this->attributeResource->getTable($this->table),
130 throw new \Magento\Framework\Exception\CouldNotSaveException(
131 __(
'Could not save Prices.'),
146 $ids = $this->retrieveAffectedIds(
$skus);
147 $connection = $this->attributeResource->getConnection();
150 foreach (array_chunk($ids, $this->itemsPerOperation) as $idsBunch) {
151 $this->attributeResource->getConnection()->delete(
152 $this->attributeResource->getTable($this->table),
154 'attribute_id = ?' => $this->getAttributeId(),
162 throw new \Magento\Framework\Exception\CouldNotDeleteException(
163 __(
'Could not delete Prices'),
178 foreach ($this->productIdLocator->retrieveProductIdsBySkus(
$skus) as $sku => $ids) {
179 if (
false !== array_key_exists(
$id, $ids)) {
192 private function getAttributeId()
194 if (!$this->attributeId) {
195 $this->attributeId = $this->attributeRepository->get($this->attributeCode)->getAttributeId();
198 return $this->attributeId;
207 private function retrieveAffectedIds(array
$skus)
211 foreach ($this->productIdLocator->retrieveProductIdsBySkus(
$skus) as
$productIds) {
212 $affectedIds = array_merge($affectedIds, array_keys(
$productIds));
215 return array_unique($affectedIds);
225 return $this->metadataPool->getMetadata(\
Magento\Catalog\Api\Data\ProductInterface::class)
retrieveSkuById($id, $skus)
foreach($websiteCodes as $websiteCode) $skus
__construct(\Magento\Catalog\Model\ResourceModel\Attribute $attributeResource, \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository, \Magento\Catalog\Model\ProductIdLocatorInterface $productIdLocator, \Magento\Framework\EntityManager\MetadataPool $metadataPool, $attributeCode='')