Skip to content

Commit 7d22594

Browse files
authored
DCAT-733: Prices Indexing (part 3) (#284)
1 parent 7a50a33 commit 7d22594

File tree

85 files changed

+5443
-1556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5443
-1556
lines changed

BundleProductDataExporter/Model/Provider/Product/BundleProductOptions.php

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ private function formatBundleValuesRow(array $row) : array
162162
'sku' => $row['sku'],
163163
'label' => $row['label'],
164164
'qty' => $row['qty'],
165+
'priceType' => $row['price_type'] ? 'percent' : 'fixed',
166+
'price' => $row['price_value'],
165167
'sortOrder' => $row['sort_order'],
166168
'isDefault' => $row['default'],
167169
'qtyMutability' => (bool)$row['qty_mutability'],

BundleProductDataExporter/Model/Query/BundleProductOptionValuesQuery.php

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ public function getQuery(array $productIds, string $storeViewCode) : Select
114114
'id' => 'main_table.selection_id',
115115
'sort_order' => 'main_table.position',
116116
'default' => 'main_table.is_default',
117+
'price_type' => 'main_table.selection_price_type',
118+
'price_value' => 'main_table.selection_price_value',
117119
'attribute_id' => 'name_default.attribute_id',
118120
'qty' => 'main_table.selection_qty',
119121
'qty_mutability' => 'main_table.selection_can_change_qty',

BundleProductDataExporter/Test/Integration/BundleProductTest.php

+82-3
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ protected function setUp() : void
3838
* @param array $bundleProductOptionsDataProvider
3939
*
4040
* @magentoDataFixture Magento/Bundle/_files/product_1.php
41-
* @dataProvider getBundleProductOptionsDataProvider
41+
* @dataProvider getBundleFixedProductOptionsDataProvider
4242
*
4343
* @magentoDbIsolation disabled
4444
* @magentoAppIsolation enabled
4545
*
4646
* @return void
4747
*/
48-
public function testBundleProductOptions(array $bundleProductOptionsDataProvider) : void
48+
public function testBundleFixedProductOptions(array $bundleProductOptionsDataProvider) : void
4949
{
5050
$extractedProduct = $this->getExtractedProduct('bundle-product', 'default');
5151
$this->assertNotEmpty($extractedProduct, 'Feed data must not be empty');
@@ -56,12 +56,37 @@ public function testBundleProductOptions(array $bundleProductOptionsDataProvider
5656
}
5757
}
5858

59+
/**
60+
* Validate bundle product options data
61+
*
62+
* @param array $bundleProductOptionsDataProvider
63+
*
64+
* @return void
65+
* @throws \Zend_Db_Statement_Exception
66+
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_special_price.php
67+
* @dataProvider getBundleDynamicProductOptionsDataProvider
68+
*
69+
* @magentoDbIsolation disabled
70+
* @magentoAppIsolation enabled
71+
*
72+
*/
73+
public function testBundleDynamicProductOptions(array $bundleProductOptionsDataProvider) : void
74+
{
75+
$extractedProduct = $this->getExtractedProduct('dynamic_bundle_product_with_special_price', 'default');
76+
$this->assertNotEmpty($extractedProduct, 'Feed data must not be empty');
77+
78+
foreach ($bundleProductOptionsDataProvider as $key => $expectedData) {
79+
$diff = $this->arrayUtils->recursiveDiff($expectedData, $extractedProduct[$key]);
80+
self::assertEquals([], $diff, 'Actual feed data doesn\'t equal to expected data');
81+
}
82+
}
83+
5984
/**
6085
* Get bundle product options data provider
6186
*
6287
* @return array
6388
*/
64-
public function getBundleProductOptionsDataProvider() : array
89+
public function getBundleFixedProductOptionsDataProvider() : array
6590
{
6691
return [
6792
'bundleProduct' => [
@@ -86,6 +111,60 @@ public function getBundleProductOptionsDataProvider() : array
86111
'isDefault' => false,
87112
'qtyMutability' => true,
88113
'sku' => 'simple',
114+
'price' => 2.75,
115+
'priceType' => 'fixed'
116+
],
117+
],
118+
],
119+
],
120+
],
121+
],
122+
],
123+
];
124+
}
125+
126+
/**
127+
* Get bundle product options data provider
128+
*
129+
* @return array
130+
*/
131+
public function getBundleDynamicProductOptionsDataProvider() : array
132+
{
133+
return [
134+
'bundleProduct' => [
135+
'item' => [
136+
'feedData' => [
137+
'sku' => 'dynamic_bundle_product_with_special_price',
138+
'storeViewCode' => 'default',
139+
'name' => 'Bundle Product',
140+
'type' => 'bundle',
141+
'optionsV2' => [
142+
[
143+
'type' => 'bundle',
144+
'renderType' => 'select',
145+
'required' => true,
146+
'label' => 'Option 1',
147+
'sortOrder' => 0,
148+
'values' => [
149+
[
150+
'sortOrder' => 0,
151+
'label' => 'Simple Product With Price 10',
152+
'qty' => 1,
153+
'isDefault' => false,
154+
'qtyMutability' => false,
155+
'sku' => 'simple1000',
156+
'price' => 0,
157+
'priceType' => 'fixed'
158+
],
159+
[
160+
'sortOrder' => 0,
161+
'label' => 'Simple Product With Price 20',
162+
'qty' => 1,
163+
'isDefault' => false,
164+
'qtyMutability' => false,
165+
'sku' => 'simple1001',
166+
'price' => 0,
167+
'priceType' => 'fixed'
89168
],
90169
],
91170
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_DataExporter:etc/et_schema.xsd">
9+
<record name="ProductOptionValue">
10+
<field name="priceType" type="String" />
11+
</record>
12+
</config>

CatalogDataExporter/Model/CreatePriceReadTable.php

-64
This file was deleted.

CatalogDataExporter/Model/Indexer/MarkRemovedEntities.php

-61
This file was deleted.

CatalogDataExporter/Model/Provider/Product/CustomOptions.php

-71
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\CatalogDataExporter\Model\Query\CustomOptions as CustomOptionsQuery;
1111
use Magento\CatalogDataExporter\Model\Query\CustomOptionValues;
12-
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
1312
use Magento\Framework\App\ResourceConnection;
1413
use Magento\Framework\Exception\NoSuchEntityException;
1514

@@ -33,32 +32,19 @@ class CustomOptions
3332
*/
3433
private $customOptionValues;
3534

36-
/**
37-
* @var CollectionFactory
38-
*/
39-
private $customerGroups;
40-
41-
/**
42-
* @var string[]
43-
*/
44-
private $customerGroupsArray = [];
45-
4635
/**
4736
* @param CustomOptionsQuery $customOptions
4837
* @param CustomOptionValues $customOptionValues
4938
* @param ResourceConnection $resourceConnection
50-
* @param CollectionFactory $customerGroups
5139
*/
5240
public function __construct(
5341
CustomOptionsQuery $customOptions,
5442
CustomOptionValues $customOptionValues,
5543
ResourceConnection $resourceConnection,
56-
CollectionFactory $customerGroups
5744
) {
5845
$this->customOptions = $customOptions;
5946
$this->resourceConnection = $resourceConnection;
6047
$this->customOptionValues = $customOptionValues;
61-
$this->customerGroups = $customerGroups;
6248
}
6349

6450
/**
@@ -80,12 +66,9 @@ public function get(array $productIds, array $optionTypes, string $storeViewCode
8066
]);
8167
$productOptions = $connection->fetchAssoc($productOptionsSelect);
8268
$productOptions = $this->addValues($productOptions, $storeViewCode);
83-
$productOptionsPercentPrices = $this->getPercentFinalPrice($productIds, $storeViewCode);
84-
// $this->customerGroupsArray = $this->customerGroups->create()->toOptionArray();
8569

8670
foreach ($productOptions as $option) {
8771
if (in_array($option['type'], $optionTypes)) {
88-
$option = $this->setPricingData($option, $productOptionsPercentPrices, $storeViewCode);
8972
$filteredProductOptions[$option['entity_id']][] = $option;
9073
}
9174
}
@@ -125,58 +108,4 @@ private function addValues(array $productOptions, string $storeViewCode): array
125108

126109
return $productOptions;
127110
}
128-
129-
/**
130-
* Get the final product Price
131-
*
132-
* @param array $productIds
133-
* @param string $storeViewCode
134-
* @return array
135-
* @throws NoSuchEntityException
136-
*/
137-
public function getPercentFinalPrice(array $productIds, string $storeViewCode): array
138-
{
139-
$formattedPrices = [];
140-
$priceQuery = $this->customOptionValues->percentPriceQuery($productIds, $storeViewCode);
141-
$prices = $this->resourceConnection->getConnection()->fetchAll($priceQuery);
142-
foreach ($prices as $price) {
143-
$calculatedPrice = $price['price'] / 100 * $price['final_price'];
144-
$key = $price['entity_id'] . $storeViewCode . $price['option_id'];
145-
$formattedPrices[$key]['price'] = $calculatedPrice;
146-
}
147-
return $formattedPrices;
148-
}
149-
150-
/**
151-
* Fill out the price by type
152-
*
153-
* @param array $option
154-
* @param array $productOptionsPercentPrices
155-
* @param string $storeViewCode
156-
* @return array
157-
*/
158-
private function setPricingData(array $option, array $productOptionsPercentPrices, string $storeViewCode): array
159-
{
160-
if ($option['price_type'] === 'percent') {
161-
$key = $option['entity_id'] . $storeViewCode . $option['option_id'];
162-
if (isset($productOptionsPercentPrices[$key])) {
163-
$option['price'] = $productOptionsPercentPrices[$key]['price'];
164-
}
165-
} elseif ($option['price_type'] === 'fixed') {
166-
// TODO: should be handled by ProductOverride feed
167-
// $prices = [];
168-
// if (isset($option['price'])) {
169-
// foreach ($this->customerGroupsArray as $customerGroup) {
170-
// $prices[] = [
171-
// 'regularPrice' => $option['price'],
172-
// 'finalPrice' => $option['price'],
173-
// 'scope' => $customerGroup['label'],
174-
// ];
175-
// }
176-
// $option['price'] = $prices;
177-
//}
178-
}
179-
180-
return $option;
181-
}
182111
}

0 commit comments

Comments
 (0)