Skip to content

Commit 212dd50

Browse files
committed
Allow for price per website config as well as global conversion rates based pricing.
1 parent d7d02d7 commit 212dd50

File tree

5 files changed

+46
-35
lines changed

5 files changed

+46
-35
lines changed

app/code/Ometria/AbandonedCarts/etc/module.xml

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0"?>
2-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"><module name="Ometria_AbandonedCarts" setup_version="2.0.1"/></config>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"><module name="Ometria_AbandonedCarts" setup_version="2.0.2"/></config>

app/code/Ometria/Api/Controller/V1/Products.php

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -402,47 +402,52 @@ protected function getProductListingsForStore(
402402
'image_url' => $this->getBaseImageUrl() . $this->getCustomAttribute($item,$this->getImageUrlKey())
403403
);
404404

405-
$tmp = $this->appendPricing($id, $tmp, $store_currency, $base_currency);
405+
$tmp = $this->appendPricing($id, $tmp, $storeId, $base_currency, $store_currency);
406406

407407
$store_listings[$id][$storeId] = $tmp;
408408
}
409409

410410
return $store_listings;
411411
}
412412

413-
protected function appendPricing($product_id, $item, $store_currency=null, $base_currency=null){
414-
413+
protected function appendPricing($product_id, $item, $storeId = null, $base_currency = null, $store_currency = null)
414+
{
415415
$store_price = $this->getProductPrice(
416416
$product_id,
417-
$item,
417+
$storeId,
418418
\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE,
419-
$store_currency,
420-
$base_currency);
419+
$base_currency,
420+
$store_currency
421+
);
422+
423+
if ($store_price) {
424+
$item['price'] = $store_price;
425+
}
421426

422427
$store_special_price = $this->getProductPrice(
423428
$product_id,
424-
$item,
429+
$storeId,
425430
\Magento\Catalog\Pricing\Price\SpecialPrice::PRICE_CODE,
426-
$store_currency,
427-
$base_currency);
431+
$base_currency,
432+
$store_currency
433+
);
428434

429-
$item['price'] = $store_price;
435+
if ($store_special_price) {
436+
$item['special_price'] = $store_special_price;
437+
}
430438

431439
if($this->_request->getParam('final_price') === 'true') {
432440
$store_final_price = $this->getProductPrice(
433441
$product_id,
434-
$item,
442+
$storeId,
435443
\Magento\Catalog\Pricing\Price\FinalPrice::PRICE_CODE,
436-
$store_currency,
437-
$base_currency);
438-
439-
$item['final_price'] = $store_final_price;
440-
}
444+
$base_currency,
445+
$store_currency
446+
);
441447

442-
if ($store_special_price) {
443-
$item['special_price'] = $store_special_price;
444-
//$item['special_price_dt_from'] = null;
445-
//$item['special_price_dt_to'] = null;
448+
if ($store_final_price) {
449+
$item['final_price'] = $store_final_price;
450+
}
446451
}
447452

448453
return $item;
@@ -451,20 +456,26 @@ protected function appendPricing($product_id, $item, $store_currency=null, $base
451456

452457
protected function getProductPrice(
453458
$product_id,
454-
$item,
459+
$storeId,
455460
$price_code,
456-
$store_currency=null,
457-
$base_currency=null
458-
){
459-
$product = $this->productRepository->getById($product_id);
460-
$price = $product->getPriceInfo()->getPrice($price_code)->getValue();
461+
$base_currency = null,
462+
$store_currency = null
463+
) {
464+
$product = $this->productRepository->getById($product_id, false, $storeId);
461465

462-
if ($store_currency && $base_currency){
463-
$price = $this->directoryHelper->currencyConvert(
464-
$price,
465-
$base_currency,
466-
$store_currency
466+
$price = $product->getPriceInfo()->getPrice($price_code)->getValue();
467+
468+
if ($store_currency && $base_currency) {
469+
try {
470+
$price = $this->directoryHelper->currencyConvert(
471+
$price,
472+
$base_currency,
473+
$store_currency
467474
);
475+
} catch (\Exception $e) {
476+
$a = true;
477+
// Allow the "undefined rate" exception and return the price as is if no rate has been setup.
478+
}
468479
}
469480

470481
return $price;

app/code/Ometria/Api/etc/module.xml

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0"?>
2-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"><module name="Ometria_Api" setup_version="2.0.1"/></config>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"><module name="Ometria_Api" setup_version="2.0.2"/></config>

app/code/Ometria/Core/etc/module.xml

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0"?>
2-
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"><module name="Ometria_Core" setup_version="2.0.1"/></config>
2+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"><module name="Ometria_Core" setup_version="2.0.2"/></config>

composer.json

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ometria/magento2",
33
"type": "magento2-module",
4-
"version": "2.0.1",
4+
"version": "2.0.2",
55
"description": "Dev composer package for Ometria Extension",
66
"authors": [
77
{

0 commit comments

Comments
 (0)