Skip to content

Commit af7e37a

Browse files
authored
Merge pull request #820 from sdinteractive/release/1.3.5
Release/1.3.5
2 parents 5109ac4 + 6e92536 commit af7e37a

File tree

12 files changed

+110
-35
lines changed

12 files changed

+110
-35
lines changed

app/code/Meta/BusinessExtension/Block/Adminhtml/Setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function getSelectedStoreId(): ?int
145145
try {
146146
$this->storeRepo->getById($requestStoreId);
147147
return $requestStoreId;
148-
} catch (NoSuchEntityException) {
148+
} catch (NoSuchEntityException $ex) {
149149
$this->fbeHelper->log("Store with requestStoreId $requestStoreId not found");
150150
}
151151
}

app/code/Meta/Catalog/Model/Category/CategoryUtility/CategoryUtilities.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
use Meta\BusinessExtension\Helper\FBEHelper;
3535
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
3636
use Meta\Catalog\Helper\Product\Identifier as ProductIdentifier;
37+
use Magento\Framework\EntityManager\MetadataPool;
38+
use Magento\Catalog\Api\Data\CategoryInterface;
3739

3840
/**
3941
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -93,6 +95,11 @@ class CategoryUtilities
9395
*/
9496
private ResourceConnection $resourceConnection;
9597

98+
/**
99+
* @var MetadataPool
100+
*/
101+
private MetadataPool $metadataPool;
102+
96103
/**
97104
* Constructor
98105
* @param ProductCollectionFactory $productCollectionFactory
@@ -104,6 +111,7 @@ class CategoryUtilities
104111
* @param CategoryImageService $imageService
105112
* @param EavConfig $eavConfig
106113
* @param ResourceConnection $resourceConnection
114+
* @param MetadataPool $metadataPool
107115
*/
108116
public function __construct(
109117
ProductCollectionFactory $productCollectionFactory,
@@ -114,7 +122,8 @@ public function __construct(
114122
ProductIdentifier $productIdentifier,
115123
CategoryImageService $imageService,
116124
EavConfig $eavConfig,
117-
ResourceConnection $resourceConnection
125+
ResourceConnection $resourceConnection,
126+
MetadataPool $metadataPool
118127
) {
119128
$this->categoryCollection = $categoryCollection;
120129
$this->categoryRepository = $categoryRepository;
@@ -125,6 +134,7 @@ public function __construct(
125134
$this->imageService = $imageService;
126135
$this->eavConfig = $eavConfig;
127136
$this->resourceConnection = $resourceConnection;
137+
$this->metadataPool = $metadataPool;
128138
}
129139
/**
130140
* Fetch products for product category
@@ -382,13 +392,16 @@ public function saveFBProductSetID(Category $category, string $setId, $storeId):
382392
$categoryEntityVarcharTable = $this->resourceConnection->getTableName(
383393
'catalog_category_entity_varchar'
384394
);
395+
396+
$categoryLinkField = $this->metadataPool->getMetadata(CategoryInterface::class)->getLinkField();
397+
385398
if ($category->getData(SystemConfig::META_PRODUCT_SET_ID) == null) {
386399
$this->resourceConnection->getConnection()->insert(
387400
$categoryEntityVarcharTable,
388401
[
389402
'attribute_id' => $productSetAttributeId,
390403
'store_id' => $storeId,
391-
'entity_id' => $category->getId(),
404+
$categoryLinkField => $category->getId(),
392405
'value' => $setId
393406
]
394407
);
@@ -398,13 +411,13 @@ public function saveFBProductSetID(Category $category, string $setId, $storeId):
398411
[
399412
'attribute_id' => $productSetAttributeId,
400413
'store_id' => $storeId,
401-
'entity_id' => $category->getId(),
414+
$categoryLinkField => $category->getId(),
402415
'value' => $setId
403416
],
404417
[
405418
'attribute_id = ?' => $productSetAttributeId,
406419
'store_id = ?' => $storeId,
407-
'entity_id = ?' => $category->getId(),
420+
sprintf('%s = ?', $categoryLinkField) => $category->getId()
408421
]
409422
);
410423
}

app/code/Meta/Catalog/Model/Product/Feed/Builder.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ private function getCondition(Product $product)
477477
private function getBrand(Product $product)
478478
{
479479
$brand = isset($this->attrMap[self::ATTR_BRAND])
480-
? $product->getData($this->attrMap[self::ATTR_BRAND])
480+
? $this->additionalAttributes->getCorrectText($product, $this->attrMap[self::ATTR_BRAND])
481481
: $this->additionalAttributes->getCorrectText($product, self::ATTR_BRAND);
482482
if (!$brand || $brand == '') {
483483
$brand = $this->additionalAttributes->getCorrectText($product, self::ATTR_BRAND);
@@ -613,7 +613,7 @@ private function getAgeGroup(Product $product)
613613
{
614614
$ageGroup = '';
615615
if (isset($this->attrMap[self::ATTR_AGE_GROUP])) {
616-
$ageGroup = $product->getData($this->attrMap[self::ATTR_AGE_GROUP]);
616+
$ageGroup = $this->additionalAttributes->getCorrectText($product, $this->attrMap[self::ATTR_AGE_GROUP]);
617617
}
618618
if (empty($ageGroup)) {
619619
$ageGroup = $this->additionalAttributes->getCorrectText($product, self::ATTR_AGE_GROUP);
@@ -632,7 +632,7 @@ private function getAgeGroup(Product $product)
632632
private function getGender(Product $product)
633633
{
634634
$gender = isset($this->attrMap[self::ATTR_GENDER])
635-
? $product->getData($this->attrMap[self::ATTR_GENDER])
635+
? $this->additionalAttributes->getCorrectText($product, $this->attrMap[self::ATTR_GENDER])
636636
: $this->additionalAttributes->getCorrectText($product, self::ATTR_GENDER);
637637
if (!$gender || $gender == '') {
638638
$gender = $this->additionalAttributes->getCorrectText($product, self::ATTR_GENDER);
@@ -674,7 +674,7 @@ private function getGender(Product $product)
674674
private function getMaterial(Product $product)
675675
{
676676
$material = isset($this->attrMap[self::ATTR_MATERIAL])
677-
? $product->getData($this->attrMap[self::ATTR_MATERIAL])
677+
? $this->additionalAttributes->getCorrectText($product, $this->attrMap[self::ATTR_MATERIAL])
678678
: $this->additionalAttributes->getCorrectText($product, self::ATTR_MATERIAL);
679679
if (!$material && $material == '') {
680680
$material = $this->additionalAttributes->getCorrectText($product, self::ATTR_MATERIAL);
@@ -694,7 +694,7 @@ private function getMaterial(Product $product)
694694
private function getPattern(Product $product)
695695
{
696696
$pattern = isset($this->attrMap[self::ATTR_PATTERN])
697-
? $product->getData($this->attrMap[self::ATTR_PATTERN])
697+
? $this->additionalAttributes->getCorrectText($product, $this->attrMap[self::ATTR_PATTERN])
698698
: $this->additionalAttributes->getCorrectText($product, self::ATTR_PATTERN);
699699
if (!$pattern && $pattern == '') {
700700
$pattern = $this->additionalAttributes->getCorrectText($product, self::ATTR_PATTERN);

app/code/Meta/Catalog/Model/Product/Feed/Builder/AdditionalAttributes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ public function getCorrectText(Product $product, string $attribute)
137137

138138
if (is_string($attribute_data)) {
139139
$text = $product->getAttributeText($attribute);
140+
if (is_array($text)) {
141+
return implode(',', $text);
142+
}
140143
return $text ?: $attribute_data;
141144
}
142145
return $attribute_data;

app/code/Meta/Catalog/Model/Product/Feed/Builder/Tools.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,11 @@ public function getProductPrice(Product $product)
204204
*/
205205
public function getProductSalePrice(Product $product)
206206
{
207-
if ($product->getSpecialPrice() > 0 && $product->getPrice() > $product->getSpecialPrice()) {
207+
$finalPrice = $product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue();
208+
if ($finalPrice > 0 && $product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue() > $finalPrice) {
208209
$price = $this->systemConfig->isPriceInclTax()
209-
? $this->catalogHelper->getTaxPrice($product, $product->getSpecialPrice(), true)
210-
: $product->getSpecialPrice();
210+
?$this->catalogHelper->getTaxPrice($product, $finalPrice, true)
211+
: $finalPrice;
211212
return $this->formatPrice($price, $product->getStoreId());
212213
}
213214
return '';

app/code/Meta/Catalog/Setup/Patch/Data/AddCategoryAttributes.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
use Magento\Eav\Setup\EavSetup;
1111
use Magento\Framework\Setup\ModuleDataSetupInterface;
1212
use Meta\Catalog\Setup\MetaCatalogAttributes;
13+
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
1314

14-
class AddCategoryAttributes implements DataPatchInterface
15+
class AddCategoryAttributes implements DataPatchInterface, PatchRevertableInterface
1516
{
1617
/**
1718
* @var ModuleDataSetupInterface
@@ -97,6 +98,8 @@ public function revert(): void
9798
foreach (array_keys($categoryAttributes) as $attributeCode) {
9899
$eavSetup->removeAttribute(Category::ENTITY, $attributeCode);
99100
}
101+
//delete the patch entry from patch_list table
102+
$this->moduleDataSetup->deleteTableRow('patch_list', 'patch_name', __CLASS__);
100103

101104
$this->moduleDataSetup->getConnection()->endSetup();
102105
}

app/code/Meta/Catalog/Setup/Patch/Data/AddCategoryProductSetIdAttribute.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
use Magento\Eav\Setup\EavSetupFactory;
1010
use Magento\Framework\Setup\ModuleDataSetupInterface;
1111
use Meta\Catalog\Setup\MetaCatalogAttributes;
12+
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
1213

13-
class AddCategoryProductSetIdAttribute implements DataPatchInterface
14+
class AddCategoryProductSetIdAttribute implements DataPatchInterface, PatchRevertableInterface
1415
{
1516
/**
1617
* @var ModuleDataSetupInterface
@@ -96,7 +97,8 @@ public function revert(): void
9697
foreach (array_keys($categoryAttributes) as $attributeCode) {
9798
$eavSetup->removeAttribute(Category::ENTITY, $attributeCode);
9899
}
99-
100+
//delete the patch entry from patch_list table
101+
$this->moduleDataSetup->deleteTableRow('patch_list', 'patch_name', __CLASS__);
100102
$this->moduleDataSetup->getConnection()->endSetup();
101103
}
102104
}

app/code/Meta/Catalog/Setup/Patch/Data/AddProductAttributes.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public function revert(): void
109109
foreach (array_keys($productAttributes) as $attributeCode) {
110110
$eavSetup->removeAttribute(Product::ENTITY, $attributeCode);
111111
}
112-
112+
//delete the patch entry from patch_list table
113+
$this->moduleDataSetup->deleteTableRow('patch_list', 'patch_name', __CLASS__);
113114
$this->moduleDataSetup->getConnection()->endSetup();
114115
}
115116
}

app/code/Meta/Catalog/Setup/Patch/Data/UpdateMetaCatalogSourceAttribute.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use Magento\Framework\Setup\Patch\DataPatchInterface;
66
use Magento\Framework\Setup\ModuleDataSetupInterface;
7+
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
78

8-
class UpdateMetaCatalogSourceAttribute implements DataPatchInterface
9+
class UpdateMetaCatalogSourceAttribute implements DataPatchInterface, PatchRevertableInterface
910
{
1011
/**
1112
* @var ModuleDataSetupInterface
@@ -86,6 +87,9 @@ public function revert(): void
8687

8788
$this->revertAttributeUpdate();
8889

90+
//delete the patch entry from patch_list table
91+
$this->moduleDataSetup->deleteTableRow('patch_list', 'patch_name', __CLASS__);
92+
8993
$this->moduleDataSetup->getConnection()->endSetup();
9094
}
9195

app/code/Meta/Conversion/Block/Pixel/ViewContent.php

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use Magento\Catalog\Block\Product\View;
2525
use Magento\Catalog\Helper\Data as CatalogHelper;
2626
use Magento\Catalog\Model\Product;
27+
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
28+
use Magento\GroupedProduct\Model\Product\Type\Grouped;
2729
use Meta\BusinessExtension\Helper\FBEHelper;
2830
use Meta\Conversion\Helper\MagentoDataHelper;
2931
use Meta\BusinessExtension\Model\System\Config as SystemConfig;
@@ -88,18 +90,51 @@ public function __construct(
8890
}
8991

9092
/**
91-
* Return content ids
92-
*
93-
* @return string
93+
* Returns content data including content_ids
94+
* @return array[]
9495
*/
95-
public function getContentIDs()
96+
public function getContentData(): array
9697
{
98+
$contents = [];
9799
$contentIds = [];
100+
foreach ($this->getProducts() as $product) {
101+
$contentId = $this->getContentId($product);
102+
$contents[] = ['id' => $contentId, 'quantity' => 1];
103+
$contentIds[] = $contentId;
104+
}
105+
106+
return ['contents' => $contents, 'content_ids' => $contentIds];
107+
}
108+
109+
/**
110+
* Return array of products
111+
* If current product is configurable or grouped, array would contain child products as well
112+
*
113+
* @return array
114+
*/
115+
private function getProducts(): array
116+
{
117+
$products = [];
98118
$product = $this->getCurrentProduct();
99119
if ($product && $product->getId()) {
100-
$contentIds[] = $this->getContentId($product);
120+
$products[] = $product;
121+
}
122+
123+
if ($product->getTypeId() == Grouped::TYPE_CODE) {
124+
foreach ($product->getTypeInstance()->getAssociatedProducts($product) as $childProduct) {
125+
/** @var Product $childProduct */
126+
$products[] = $childProduct;
127+
}
101128
}
102-
return $this->arrayToCommaSeparatedStringValues($contentIds);
129+
130+
if ($product->getTypeId() == Configurable::TYPE_CODE) {
131+
foreach ($product->getTypeInstance()->getUsedProducts($product) as $childProduct) {
132+
/** @var Product $childProduct */
133+
$products[] = $childProduct;
134+
}
135+
}
136+
137+
return $products;
103138
}
104139

105140
/**

0 commit comments

Comments
 (0)