Skip to content

Commit

Permalink
New release/2.2.1 (#28)
Browse files Browse the repository at this point in the history
* Added base currency values to Orders API response.

* Use correct value for billing address name (was previously using shipping address name).

* Cast string to float to ensure discount line is formatted correctly when greater than zero but less than one.

* Add base currency values to line items in Orders API response.

* M2-30 Fix bug in currency code caching, ensure prices are converted to correct currency.

* M2-28 Default to trying to use the configurable product image regardless of UseConfigurableImage config.

* M2-34 Fix case on return variable name.

* M2-23 Move inventory access to independent service to allow MSI with backwards compatibility, used in ometria.raw_data and Product API V2.

* Return boolean for Product API V2 is_in_stock value.

* Add "reward_points" value to customer API response for Magento Commerce merchants.

* M2-37 Fix issue with pricing for configurables caused by Magento internal caching of price info per store.

* M2-37 Fix issue with pricing for configurables caused by Magento internal caching of price info per store.

* M2-37 Fix issue with pricing for configurables caused by Magento internal caching of price info per store.

* Remove redundant DI class.

* Bump versions.

* M2-38 Added config to enable/disable additional Ometria Page Views on variant selection within configurable/swatch PDP.

* Bump composer version.

* Remove whitespace.

* M2-42 Fix type error in Product Inventory Service.
  • Loading branch information
chris-pook authored May 12, 2021
1 parent 6bdbd9d commit 0704dac
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 180 deletions.
2 changes: 1 addition & 1 deletion app/code/Ometria/AbandonedCarts/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ometria_AbandonedCarts" setup_version="2.2.0"/>
<module name="Ometria_AbandonedCarts" setup_version="2.2.1"/>
</config>
114 changes: 74 additions & 40 deletions app/code/Ometria/Api/Controller/V1/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
use Magento\Catalog\Pricing\Price\FinalPrice;
use Magento\Catalog\Pricing\Price\RegularPrice;
use Magento\Catalog\Pricing\Price\SpecialPrice;
use Magento\CatalogInventory\Api\StockRegistryInterface;
use Magento\Framework\App\Area as AppArea;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\App\Emulation as AppEmulation;
use Ometria\Api\Helper\Filter\V1\Service as FilterService;
use Ometria\Api\Helper\Format\V1\Products as Helper;

Expand Down Expand Up @@ -36,6 +42,12 @@ class Products extends Base
/** @var StockRegistryInterface */
private $stockRegistry;

/** @var HttpContext */
private $httpContext;

/** @var AppEmulation */
private $appEmulation;

protected $storeIdCache=false;
protected $productTypeFactory;

Expand Down Expand Up @@ -72,7 +84,9 @@ public function __construct(
\Magento\Directory\Helper\Data $directoryHelper,
\Ometria\Api\Helper\StoreUrl $storeUrlHelper,
\Magento\Catalog\Model\Product\TypeFactory $productTypeFactory,
StockRegistryInterface $stockRegistry
StockRegistryInterface $stockRegistry,
HttpContext $httpContext,
AppEmulation $appEmulation
) {
parent::__construct($context);
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
Expand All @@ -94,6 +108,8 @@ public function __construct(
$this->storeUrlHelper = $storeUrlHelper;
$this->productTypeFactory = $productTypeFactory;
$this->stockRegistry = $stockRegistry;
$this->httpContext = $httpContext;
$this->appEmulation = $appEmulation;
}

public function execute()
Expand Down Expand Up @@ -374,7 +390,7 @@ protected function addStoreListingToItems($items)
}


protected function getProductListingsForStore($store, $productIds, $store_listings)
protected function getProductListingsForStore($store, $productIds, $storeListings)
{
$storeId = $store->getId();

Expand All @@ -392,8 +408,8 @@ protected function getProductListingsForStore($store, $productIds, $store_listin
$this->getRequest()->getParam('product_image', 'image')
);

$base_currency = $store->getBaseCurrency()->getCode();
$store_currency = $store->getDefaultCurrency()->getCode();
$baseCurrency = $store->getBaseCurrency()->getCode();
$storeCurrency = $store->getDefaultCurrency()->getCode();

foreach ($items as $item) {
$id = $item['id'];
Expand All @@ -402,57 +418,57 @@ protected function getProductListingsForStore($store, $productIds, $store_listin
'store_id' => $storeId,
'title' => $item['name'],
'url' => $url,
'store_currency' => $store_currency,
'store_currency' => $storeCurrency,
'visibility' => $item['visibility'],
'status' => $item['status'],
'image_url' => $item['image_url']
);
);

$tmp = $this->appendPricing($id, $tmp, $storeId, $base_currency, $store_currency);
$tmp = $this->appendPricing($id, $tmp, $storeId, $baseCurrency, $storeCurrency);

$store_listings[$id][$storeId] = $tmp;
$storeListings[$id][$storeId] = $tmp;
}

return $store_listings;
return $storeListings;
}

protected function appendPricing($product_id, $item, $storeId = null, $base_currency = null, $store_currency = null)
protected function appendPricing($productId, $item, $storeId = null, $baseCurrency = null, $storeCurrency = null)
{
$store_price = $this->getProductPrice(
$product_id,
$storePrice = $this->getProductPrice(
$productId,
$storeId,
\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE,
$base_currency,
$store_currency
RegularPrice::PRICE_CODE,
$baseCurrency,
$storeCurrency
);

if ($store_price) {
$item['price'] = $store_price;
if ($storePrice) {
$item['price'] = $storePrice;
}

$store_special_price = $this->getProductPrice(
$product_id,
$storeSpecialPrice = $this->getProductPrice(
$productId,
$storeId,
\Magento\Catalog\Pricing\Price\SpecialPrice::PRICE_CODE,
$base_currency,
$store_currency
SpecialPrice::PRICE_CODE,
$baseCurrency,
$storeCurrency
);

if ($store_special_price) {
$item['special_price'] = $store_special_price;
if ($storeSpecialPrice) {
$item['special_price'] = $storeSpecialPrice;
}

if ($this->_request->getParam('final_price') === 'true') {
$store_final_price = $this->getProductPrice(
$product_id,
$storeFinalPrice = $this->getProductPrice(
$productId,
$storeId,
\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
$base_currency,
$store_currency
FinalPrice::PRICE_CODE,
$baseCurrency,
$storeCurrency
);

if ($store_final_price) {
$item['final_price'] = $store_final_price;
if ($storeFinalPrice) {
$item['final_price'] = $storeFinalPrice;
}
}

Expand Down Expand Up @@ -482,28 +498,46 @@ private function appendStock($productId, $item)
}

protected function getProductPrice(
$product_id,
$productId,
$storeId,
$price_code,
$base_currency = null,
$store_currency = null
$priceCode,
$baseCurrency = null,
$storeCurrency = null
) {
$product = $this->productRepository->getById($product_id, false, $storeId);
// Override HTTP currency value to ensure Magento internals use correct store currency
$beforeCurrency = $this->httpContext->getValue(HttpContext::CONTEXT_CURRENCY);
$this->httpContext->setValue(HttpContext::CONTEXT_CURRENCY, $storeCurrency, null);

$price = $product->getPriceInfo()->getPrice($price_code)->getValue();
$product = $this->productRepository->getById($productId, false, $storeId);

if ($store_currency && $base_currency) {
// Emulate store as required to ensure Magento internals use correct store currency
$this->appEmulation->startEnvironmentEmulation(
$product->getStoreId(),
AppArea::AREA_FRONTEND,
true
);

$price = $product->getPriceInfo()->getPrice($priceCode)->getValue();

// Final price is already converted so skip it here
if ($priceCode != FinalPrice::PRICE_CODE && $storeCurrency && $baseCurrency) {
try {
$price = $this->directoryHelper->currencyConvert(
$price,
$base_currency,
$store_currency
$baseCurrency,
$storeCurrency
);
} catch (\Exception $e) {
// Allow the "undefined rate" exception and return the price as is if no rate has been setup.
}
}

// Stop emulating store
$this->appEmulation->stopEnvironmentEmulation();

// Reset HTTP currency value to before value
$this->httpContext->setValue(HttpContext::CONTEXT_CURRENCY, $beforeCurrency, $beforeCurrency);

return $price;
}

Expand Down
1 change: 1 addition & 0 deletions app/code/Ometria/Api/Controller/V2/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ private function appendProductPriceData(&$productData, ProductInterface $product
$productData[OmetriaProductInterface::FINAL_PRICE] = $finalPrice;
}

// Add tax data to the product data array (this is currency converted internally)
$taxDetailsItem = $this->getTaxDetails(
$product,
$finalPrice
Expand Down
3 changes: 1 addition & 2 deletions app/code/Ometria/Api/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ometria_Api" setup_version="2.2.0"/>
<module name="Ometria_Api" setup_version="2.2.1"/>
</config>

Loading

0 comments on commit 0704dac

Please sign in to comment.