Skip to content

Commit

Permalink
Merge pull request #703 from Nosto/hotfix/5.0.4
Browse files Browse the repository at this point in the history
Fix fetching price for configurable product from wrong store
  • Loading branch information
Hannu Pölönen authored Aug 20, 2020
2 parents b7cb5e7 + 9b7885d commit b21a126
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

# 5.0.4
* Fix an issue with incorrect prices when different base currencies are used in websites and taxes are included in display prices

# 5.0.3
* Bump the PHP SDK version to be compatible with Nosto CMP module (no functional changes)

Expand Down
8 changes: 4 additions & 4 deletions Helper/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,10 @@ private function getConfigurableProductPrice(Product $product, $finalPrice, $inc
)
);
}
$skuResult = $this->nostoProductRepository->getByIds([$minSku[self::KEY_SKU_PRODUCT_ID]]);
$skuProducts = $skuResult->getItems();
$skuProduct = reset($skuProducts);

$skuProduct = $this->nostoProductRepository->reloadProduct(
$minSku[self::KEY_SKU_PRODUCT_ID],
$store->getId()
);
if ($skuProduct instanceof Product) {
$price = $this->getProductPrice($skuProduct, $store, true, $finalPrice);
}
Expand Down
17 changes: 17 additions & 0 deletions Model/Product/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,21 @@ public function getSkusAsArray(Product $product, Store $store)
);
return $this->skuResource->getSkuPricesByIds($store->getWebsite(), $inStockProductsByIds);
}

/**
* Loads (or reloads) Product object
* @param int $productId
* @param int $storeId
* @return ProductInterface|Product
* @throws NoSuchEntityException
*/
public function reloadProduct($productId, $storeId)
{
return $this->productRepository->getById(
$productId,
false,
$storeId,
true
);
}
}
35 changes: 10 additions & 25 deletions Model/Service/Product/DefaultProductService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@
use Exception;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\Store;
use Nosto\Exception\FilteredProductException;
use Nosto\Exception\NonBuildableProductException;
use Nosto\Model\Product\Product as NostoProduct;
use Nosto\Tagging\Logger\Logger as NostoLogger;
use Nosto\Tagging\Model\Product\Builder as NostoProductBuilder;
use Magento\Catalog\Model\ProductRepository;
use Nosto\Tagging\Model\Product\Repository as NostoProductRepository;

class DefaultProductService implements ProductServiceInterface
{
Expand All @@ -58,22 +57,22 @@ class DefaultProductService implements ProductServiceInterface
/** @var NostoLogger */
private $logger;

/** @var ProductRepository */
private $productRepository;
/** @var NostoProductRepository */
private $nostoProductRepository;

/**
* DefaultProductService constructor.
* @param NostoProductBuilder $nostoProductBuilder
* @param ProductRepository $productRepository
* @param NostoProductRepository $nostoProductRepository
* @param NostoLogger $logger
*/
public function __construct(
NostoProductBuilder $nostoProductBuilder,
ProductRepository $productRepository,
NostoProductRepository $nostoProductRepository,
NostoLogger $logger
) {
$this->nostoProductBuilder = $nostoProductBuilder;
$this->productRepository = $productRepository;
$this->nostoProductRepository = $nostoProductRepository;
$this->logger = $logger;
}

Expand All @@ -90,7 +89,10 @@ public function getProduct(ProductInterface $product, StoreInterface $store)
/** @var Store $store */
try {
return $this->nostoProductBuilder->build(
$this->reloadProduct($product, $store),
$this->nostoProductRepository->reloadProduct(
$product->getId(),
$store->getId()
),
$store
);
} catch (NonBuildableProductException $e) {
Expand All @@ -106,21 +108,4 @@ public function getProduct(ProductInterface $product, StoreInterface $store)
return null;
}
}

/**
* Loads (or reloads) Product object
* @param ProductInterface $product
* @param StoreInterface $store
* @return ProductInterface|Product
* @throws NoSuchEntityException
*/
private function reloadProduct(ProductInterface $product, StoreInterface $store)
{
return $this->productRepository->getById(
$product->getId(),
false,
$store->getId(),
true
);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nosto/module-nostotagging",
"description": "Increase your conversion rate and average order value by delivering your customers personalized product recommendations throughout their shopping journey.",
"type": "magento2-module",
"version": "5.0.3",
"version": "5.0.4",
"require-dev": {
"php": ">=7.1.0",
"phpmd/phpmd": "^2.5",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
<!--suppress XmlUnboundNsPrefix -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Nosto_Tagging" setup_version="5.0.3"/>
<module name="Nosto_Tagging" setup_version="5.0.4"/>
</config>

0 comments on commit b21a126

Please sign in to comment.