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 all commits
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
78 changes: 78 additions & 0 deletions Plugin/Catalog/Helper/Product/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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;
}

$updateCycleValueCallback = function ($item) use ($product) {
if (ucfirst(RecurrenceSubscriptionRepetitionsInterface::CYCLES) !== $item['label']) {
return $item;
}

$item['value'] = ProductHelper::applyDiscount($item['value'], $product);
return $item;
};

return array_map($updateCycleValueCallback, $result);
}
}
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 @@ -659,10 +659,6 @@

<!-- <preference for="Magento\CatalogWidget\Block\Product\ProductsList" type="Pagarme\Pagarme\Block\Web\ProductsList" />-->

<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>
135 changes: 0 additions & 135 deletions view/frontend/templates/product/priceCycles.phtml

This file was deleted.