Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring in showing cycle option value in cart #213

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions Plugin/Catalog/Helper/Product/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* @author Open Source Team
* @copyright 2023 Pagar.me (https://pagar.me)
* @license https://pagar.me Copyright
*
* @link https://pagar.me
*/

declare(strict_types=1);

namespace Pagarme\Pagarme\Plugin\Catalog\Helper\Product;

use Exception;
use Magento\Catalog\Helper\Product\Configuration as ConfigurationOriginal;
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
use Pagarme\Core\Recurrence\Services\RecurrenceService;
use Pagarme\Pagarme\Api\Data\RecurrenceSubscriptionRepetitionsInterface;
use Pagarme\Pagarme\Helper\ProductHelper;
use Pagarme\Pagarme\Concrete\Magento2CoreSetup;

class Configuration
{
/**
* @var RecurrenceService
*/
private $recurrenceService;

/**
* @var \Pagarme\Core\Kernel\Aggregates\Configuration
*/
private $pagarmeConfig;

/**
* @param RecurrenceService $recurrenceService
* @throws Exception
*/
public function __construct(RecurrenceService $recurrenceService)
{
Magento2CoreSetup::bootstrap();
$this->pagarmeConfig = Magento2CoreSetup::getModuleConfiguration();
$this->recurrenceService = $recurrenceService;
}

/**
* @param ConfigurationOriginal $subject
* @param callable $proceed
* @param ItemInterface $item
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundGetCustomOptions(
ConfigurationOriginal $subject,
callable $proceed,
ItemInterface $item
) {
$result = $proceed($item);

$product = $item->getProduct();
$hasNoRecurrence = !$this->pagarmeConfig->isEnabled() ||
!$this->pagarmeConfig->getRecurrenceConfig()->isEnabled() ||
empty($this->recurrenceService->getRecurrenceProductByProductId($product->getId()));
if ($hasNoRecurrence) {
return $result;
}

return array_map(function ($item) use ($product) {
mateus-picoloto marked this conversation as resolved.
Show resolved Hide resolved
if (ucfirst(RecurrenceSubscriptionRepetitionsInterface::CYCLES) !== $item['label']) {
return $item;
}

$item['value'] = ProductHelper::applyDiscount($item['value'], $product);
return $item;
}, $result);
}
}
132 changes: 0 additions & 132 deletions Plugin/Princing/Render/FinalPricePlugin.php

This file was deleted.

40 changes: 0 additions & 40 deletions Plugin/Princing/Render/ProductPriceCyclesPlugin.php

This file was deleted.

4 changes: 0 additions & 4 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,6 @@
<!-- <plugin name="Pagarme_Pagarme_change_template" type="Pagarme\Pagarme\Plugin\Princing\Render\FinalPricePlugin" />-->
<!-- </type>-->

<type name="\Magento\Checkout\Block\Cart\Item\Renderer">
<plugin name="Pagarme_Pagarme_change_template_cycles" type="Pagarme\Pagarme\Plugin\Princing\Render\ProductPriceCyclesPlugin" />
</type>

<!-- Recurrence -->

<preference for="Pagarme\Core\Recurrence\Interfaces\RepetitionInterface" type="Pagarme\Core\Recurrence\Aggregates\Repetition" />
Expand Down
7 changes: 7 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@
</argument>
</arguments>
</type>

<type name="Magento\Catalog\Helper\Product\Configuration">
<plugin name="Pagarme_Pagarme::Magento_Catalog:Configuration"
type="Pagarme\Pagarme\Plugin\Catalog\Helper\Product\Configuration"
sortOrder="10"
disabled="false"/>
</type>
</config>
Loading