Skip to content

Commit

Permalink
DCAT-733: Prices Indexing (part 3) (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
le0n4ik committed Aug 10, 2023
1 parent 7a50a33 commit 7d22594
Show file tree
Hide file tree
Showing 85 changed files with 5,443 additions and 1,556 deletions.
Expand Up @@ -162,6 +162,8 @@ private function formatBundleValuesRow(array $row) : array
'sku' => $row['sku'],
'label' => $row['label'],
'qty' => $row['qty'],
'priceType' => $row['price_type'] ? 'percent' : 'fixed',
'price' => $row['price_value'],
'sortOrder' => $row['sort_order'],
'isDefault' => $row['default'],
'qtyMutability' => (bool)$row['qty_mutability'],
Expand Down
Expand Up @@ -114,6 +114,8 @@ public function getQuery(array $productIds, string $storeViewCode) : Select
'id' => 'main_table.selection_id',
'sort_order' => 'main_table.position',
'default' => 'main_table.is_default',
'price_type' => 'main_table.selection_price_type',
'price_value' => 'main_table.selection_price_value',
'attribute_id' => 'name_default.attribute_id',
'qty' => 'main_table.selection_qty',
'qty_mutability' => 'main_table.selection_can_change_qty',
Expand Down
85 changes: 82 additions & 3 deletions BundleProductDataExporter/Test/Integration/BundleProductTest.php
Expand Up @@ -38,14 +38,14 @@ protected function setUp() : void
* @param array $bundleProductOptionsDataProvider
*
* @magentoDataFixture Magento/Bundle/_files/product_1.php
* @dataProvider getBundleProductOptionsDataProvider
* @dataProvider getBundleFixedProductOptionsDataProvider
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*
* @return void
*/
public function testBundleProductOptions(array $bundleProductOptionsDataProvider) : void
public function testBundleFixedProductOptions(array $bundleProductOptionsDataProvider) : void
{
$extractedProduct = $this->getExtractedProduct('bundle-product', 'default');
$this->assertNotEmpty($extractedProduct, 'Feed data must not be empty');
Expand All @@ -56,12 +56,37 @@ public function testBundleProductOptions(array $bundleProductOptionsDataProvider
}
}

/**
* Validate bundle product options data
*
* @param array $bundleProductOptionsDataProvider
*
* @return void
* @throws \Zend_Db_Statement_Exception
* @magentoDataFixture Magento/Bundle/_files/dynamic_bundle_product_with_special_price.php
* @dataProvider getBundleDynamicProductOptionsDataProvider
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
*
*/
public function testBundleDynamicProductOptions(array $bundleProductOptionsDataProvider) : void
{
$extractedProduct = $this->getExtractedProduct('dynamic_bundle_product_with_special_price', 'default');
$this->assertNotEmpty($extractedProduct, 'Feed data must not be empty');

foreach ($bundleProductOptionsDataProvider as $key => $expectedData) {
$diff = $this->arrayUtils->recursiveDiff($expectedData, $extractedProduct[$key]);
self::assertEquals([], $diff, 'Actual feed data doesn\'t equal to expected data');
}
}

/**
* Get bundle product options data provider
*
* @return array
*/
public function getBundleProductOptionsDataProvider() : array
public function getBundleFixedProductOptionsDataProvider() : array
{
return [
'bundleProduct' => [
Expand All @@ -86,6 +111,60 @@ public function getBundleProductOptionsDataProvider() : array
'isDefault' => false,
'qtyMutability' => true,
'sku' => 'simple',
'price' => 2.75,
'priceType' => 'fixed'
],
],
],
],
],
],
],
];
}

/**
* Get bundle product options data provider
*
* @return array
*/
public function getBundleDynamicProductOptionsDataProvider() : array
{
return [
'bundleProduct' => [
'item' => [
'feedData' => [
'sku' => 'dynamic_bundle_product_with_special_price',
'storeViewCode' => 'default',
'name' => 'Bundle Product',
'type' => 'bundle',
'optionsV2' => [
[
'type' => 'bundle',
'renderType' => 'select',
'required' => true,
'label' => 'Option 1',
'sortOrder' => 0,
'values' => [
[
'sortOrder' => 0,
'label' => 'Simple Product With Price 10',
'qty' => 1,
'isDefault' => false,
'qtyMutability' => false,
'sku' => 'simple1000',
'price' => 0,
'priceType' => 'fixed'
],
[
'sortOrder' => 0,
'label' => 'Simple Product With Price 20',
'qty' => 1,
'isDefault' => false,
'qtyMutability' => false,
'sku' => 'simple1001',
'price' => 0,
'priceType' => 'fixed'
],
],
],
Expand Down
12 changes: 12 additions & 0 deletions BundleProductDataExporter/etc/et_schema.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_DataExporter:etc/et_schema.xsd">
<record name="ProductOptionValue">
<field name="priceType" type="String" />
</record>
</config>
64 changes: 0 additions & 64 deletions CatalogDataExporter/Model/CreatePriceReadTable.php

This file was deleted.

61 changes: 0 additions & 61 deletions CatalogDataExporter/Model/Indexer/MarkRemovedEntities.php

This file was deleted.

71 changes: 0 additions & 71 deletions CatalogDataExporter/Model/Provider/Product/CustomOptions.php
Expand Up @@ -9,7 +9,6 @@

use Magento\CatalogDataExporter\Model\Query\CustomOptions as CustomOptionsQuery;
use Magento\CatalogDataExporter\Model\Query\CustomOptionValues;
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\NoSuchEntityException;

Expand All @@ -33,32 +32,19 @@ class CustomOptions
*/
private $customOptionValues;

/**
* @var CollectionFactory
*/
private $customerGroups;

/**
* @var string[]
*/
private $customerGroupsArray = [];

/**
* @param CustomOptionsQuery $customOptions
* @param CustomOptionValues $customOptionValues
* @param ResourceConnection $resourceConnection
* @param CollectionFactory $customerGroups
*/
public function __construct(
CustomOptionsQuery $customOptions,
CustomOptionValues $customOptionValues,
ResourceConnection $resourceConnection,
CollectionFactory $customerGroups
) {
$this->customOptions = $customOptions;
$this->resourceConnection = $resourceConnection;
$this->customOptionValues = $customOptionValues;
$this->customerGroups = $customerGroups;
}

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

foreach ($productOptions as $option) {
if (in_array($option['type'], $optionTypes)) {
$option = $this->setPricingData($option, $productOptionsPercentPrices, $storeViewCode);
$filteredProductOptions[$option['entity_id']][] = $option;
}
}
Expand Down Expand Up @@ -125,58 +108,4 @@ private function addValues(array $productOptions, string $storeViewCode): array

return $productOptions;
}

/**
* Get the final product Price
*
* @param array $productIds
* @param string $storeViewCode
* @return array
* @throws NoSuchEntityException
*/
public function getPercentFinalPrice(array $productIds, string $storeViewCode): array
{
$formattedPrices = [];
$priceQuery = $this->customOptionValues->percentPriceQuery($productIds, $storeViewCode);
$prices = $this->resourceConnection->getConnection()->fetchAll($priceQuery);
foreach ($prices as $price) {
$calculatedPrice = $price['price'] / 100 * $price['final_price'];
$key = $price['entity_id'] . $storeViewCode . $price['option_id'];
$formattedPrices[$key]['price'] = $calculatedPrice;
}
return $formattedPrices;
}

/**
* Fill out the price by type
*
* @param array $option
* @param array $productOptionsPercentPrices
* @param string $storeViewCode
* @return array
*/
private function setPricingData(array $option, array $productOptionsPercentPrices, string $storeViewCode): array
{
if ($option['price_type'] === 'percent') {
$key = $option['entity_id'] . $storeViewCode . $option['option_id'];
if (isset($productOptionsPercentPrices[$key])) {
$option['price'] = $productOptionsPercentPrices[$key]['price'];
}
} elseif ($option['price_type'] === 'fixed') {
// TODO: should be handled by ProductOverride feed
// $prices = [];
// if (isset($option['price'])) {
// foreach ($this->customerGroupsArray as $customerGroup) {
// $prices[] = [
// 'regularPrice' => $option['price'],
// 'finalPrice' => $option['price'],
// 'scope' => $customerGroup['label'],
// ];
// }
// $option['price'] = $prices;
//}
}

return $option;
}
}

0 comments on commit 7d22594

Please sign in to comment.