Skip to content

Commit

Permalink
Release of version v3.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
syneriseapp committed Dec 8, 2024
1 parent 0ce29d2 commit eda7b99
Show file tree
Hide file tree
Showing 22 changed files with 174 additions and 651 deletions.

This file was deleted.

51 changes: 0 additions & 51 deletions Block/ElasticsuiteTracker/Variables/Page/Search.php

This file was deleted.

50 changes: 35 additions & 15 deletions Helper/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Sales\Api\Data\OrderItemInterface;
use Magento\Store\Model\ScopeInterface;
use Synerise\Integration\Model\Config\Source\Products\Price as PriceCode;

class Price
{
public const XML_PATH_PRODUCT_CALCULATE_TAX = 'synerise/product/calculate_tax';
public const XML_PATH_PRODUCT_INCLUDE_TAX = 'synerise/product/calculate_tax';

/**
* @var ScopeConfigInterface
Expand All @@ -20,18 +21,18 @@ class Price
/**
* @var Data
*/
private $helper;
private $catalogHelper;

/**
* @param ScopeConfigInterface $scopeConfig
* @param Data $helper
* @param Data $catalogHelper
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
Data $helper
Data $catalogHelper
) {
$this->scopeConfig = $scopeConfig;
$this->helper = $helper;
$this->catalogHelper = $catalogHelper;
}

/**
Expand All @@ -43,17 +44,21 @@ public function __construct(
* @param bool|null $includingTax
* @return float
*/
public function getPrice(Product $product, float $price, ?int $storeId = null, ?bool $includingTax = null): float
public function getTaxPrice(Product $product, float $price, ?int $storeId = null, ?bool $includingTax = null): float
{
if ($includingTax === null) {
$includingTax = $this->calculateTax($storeId);
$includingTax = $this->includeTax($storeId);
}

if ($includingTax) {
return $this->helper->getTaxPrice($product, $price, true);
} else {
return $price;
}
return $this->catalogHelper->getTaxPrice(
$product,
$price,
$includingTax,
null,
null,
null,
$storeId
);
}

/**
Expand All @@ -65,7 +70,7 @@ public function getPrice(Product $product, float $price, ?int $storeId = null, ?
*/
public function getFinalUnitPrice(OrderItemInterface $item, ?int $storeId): float
{
if ($this->calculateTax($storeId)) {
if ($this->includeTax($storeId)) {
return round(($item->getRowTotal() + $item->getTaxAmount() - $item->getDiscountAmount()) /
$item->getQtyOrdered(), 2);
} else {
Expand All @@ -79,10 +84,25 @@ public function getFinalUnitPrice(OrderItemInterface $item, ?int $storeId): floa
* @param int|null $storeId
* @return bool
*/
public function calculateTax(?int $storeId = null): bool
public function includeTax(?int $storeId = null): bool
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_PRODUCT_CALCULATE_TAX,
self::XML_PATH_PRODUCT_INCLUDE_TAX,
ScopeInterface::SCOPE_STORE,
$storeId
);
}

/**
* Get price code for price attribute
*
* @param int|null $storeId
* @return string
*/
public function getPriceCode(?int $storeId = null): string
{
return $this->scopeConfig->getValue(
PriceCode::XML_PATH_PRODUCT_PRICE,
ScopeInterface::SCOPE_STORE,
$storeId
);
Expand Down
2 changes: 1 addition & 1 deletion Helper/Tracking/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Context
/**
* @var MobileDetect
*/
protected MobileDetect $mobileDetect;
protected $mobileDetect;

/**
* @param StoreManagerInterface $storeManager
Expand Down
7 changes: 7 additions & 0 deletions Model/Config/Source/Products/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public function toOptionArray(): array
}
}

foreach (Price::OPTIONS as $item) {
$options[] = [
'value' => $item['value'],
'label' => $item['value']
];
}

return $options;
}
}
29 changes: 29 additions & 0 deletions Model/Config/Source/Products/Price.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Synerise\Integration\Model\Config\Source\Products;

use Magento\Framework\Data\OptionSourceInterface;

class Price implements OptionSourceInterface
{
public const XML_PATH_PRODUCT_PRICE = 'synerise/product/price';

public const OPTIONS = [
[
'value' => 'regular_price',
'label' => 'Regular Price'
],
[
'value' => 'final_price',
'label' => 'Final Price'
]
];

/**
* @inheritDoc
*/
public function toOptionArray(): array
{
return self::OPTIONS;
}
}
Loading

0 comments on commit eda7b99

Please sign in to comment.