Skip to content

Commit

Permalink
Merge pull request #92 from pagarme/bugfix/cent-missing-recurrence-pr…
Browse files Browse the repository at this point in the history
…ice/PAOPN-12

PAOPN-12 Cents missing in the recurrence price
mauriciohaygert authored Jun 13, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents acd5b0e + 525cdab commit 71bf5fe
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 6 additions & 4 deletions Helper/ProductHelper.php
Original file line number Diff line number Diff line change
@@ -36,8 +36,7 @@ public function getProductList(array $productIdList)

$productList = [];
foreach ($productIdList as $productId) {
$product =
$objectManager
$product = $objectManager
->create('Magento\Catalog\Model\Product')
->load($productId);

@@ -80,7 +79,10 @@ public static function getDiscountAmount($product)
*/
public static function extractValueFromTitle($title)
{
return (float)preg_replace('/[^0-9,]/', '', ProductHelper::getStringBetween($title, '(', ')'));
return (float)str_replace(',', '.',
preg_replace('/[^0-9,.]/', '',
ProductHelper::getStringBetween($title, '(', ')'))
);
}

/**
@@ -100,7 +102,7 @@ public static function calculateDiscount($value, $discountAmount)
*/
public static function convertDecimalMoney($amount)
{
$amount = number_format($amount, 2, ',', '.');
$amount = number_format($amount, 2);
return $amount;
}

10 changes: 4 additions & 6 deletions Observer/DiscountCyclesObserver.php
Original file line number Diff line number Diff line change
@@ -41,21 +41,19 @@ public function execute(Observer $observer)
if (isset($observer->getProduct()->getOptions()[0])) {
$this->applyDiscountCycles(
$observer->getProduct()->getOptions()[0]->getValues(),
ProductHelper::getDiscountAmount($observer->getProduct())
$observer->getProduct()
);
}
}

/**
* @param Cycles $cycles
* @param DiscountAmount $discountAmount
* @param Product $product
*/
private function applyDiscountCycles($cycles, $discountAmount)
private function applyDiscountCycles($cycles, $product)
{
foreach ($cycles as $cycle) {
$value = ProductHelper::extractValueFromTitle($cycle->getTitle());
$discountValue = ProductHelper::calculateDiscount($value, $discountAmount);
$cycle->setTitle(strtok($cycle->getTitle(), '-') . ' - ' . ProductHelper::applyMoneyFormat($discountValue));
ProductHelper::applyDiscount($cycle->getTitle(), $product);
}
}
}

0 comments on commit 71bf5fe

Please sign in to comment.