Skip to content

Commit b3d76da

Browse files
Maikcoleonardo albuquerquebrunoroedercris-silveiracristhianss
authored
Adiciona opção para selecionar planos cadastrados na Vindi (#72)
* #11177 Iniciado criação do meio de pagamento por cartão de crédito * #11177 adicionado estrutura base * #11177 adicionada estrutura base * #11177 removido arquivos não necessários para esta release * #11177 iniciado implementação do checkout * #11177 iniciado criação da opção no carrinho * #11177 criado form para adicionar os dados do cartão de crédito * #11177 agora é possível salvar os dados do cartão na ordem de compra * #11177 iniciado implementação do bloco de info da ordem * #11177 agora é mostrado os dados do cartão de crédito na area admin * #11177 removido coisas desnecessárias * #11177 adicionado campo para nome no cartão de crédito * #11177 atualizado rota para controller * #11177 corrigido nome dos cartões de crédito, removido códigos não necessários nesta release * #11177 removido array de status * movido arquivos para base para poder utilizar modman e composer * adicionado seletor para status da ordem ao ser confirmada * corrigido chamada da função createCustomer fix #30 * validation for existence of some payment method and validation of filling the token field in the configurations of the module * fix ApiKeyValidator Exception Phrase * Envia valores de desconto e acréscimos para a Vindi * Update Model/Payment/Product.php Co-Authored-By: Laerte Guimarães <[email protected]> * Update Model/Payment/Product.php Co-Authored-By: Laerte Guimarães <[email protected]> * Update Model/Payment/Product.php Co-Authored-By: Laerte Guimarães <[email protected]> * Inicio dos testes de cupons, taxas e frete * Correções nos mocks das respostas esperadas * Trocar o nome da classe * Testes nas mudanças de status para pedidos com boletos * Testes nos status dos pedidos de acordo com os meios de pagamento * Ajustes nos testes para conformidade com PR 55 * Insere informações de Teste * Ajusta link de download * Atualizando o status da assinatura no Magento * Possibilidade de associar o produto bundle no Magento a um plano existente na Vindi. * Update Setup/UpgradeData.php Co-authored-by: Laerte Guimarães <[email protected]> * Update i18n/pt_BR.csv Co-authored-by: Laerte Guimarães <[email protected]> * Update Model/Config/Source/Plan.php Co-authored-by: Laerte Guimarães <[email protected]> Co-authored-by: leonardo albuquerque <[email protected]> Co-authored-by: Bruno Roeder <[email protected]> Co-authored-by: Cristhian Silveira Silva <[email protected]> Co-authored-by: Cristhian Silveira Silva <[email protected]> Co-authored-by: Gabriel Ranghetti <[email protected]> Co-authored-by: Laerte Guimarães <[email protected]> Co-authored-by: Yauari Vieira <[email protected]> Co-authored-by: Bruno Roeder <[email protected]>
1 parent d8fe9aa commit b3d76da

File tree

8 files changed

+143
-6
lines changed

8 files changed

+143
-6
lines changed

Model/Config/Source/Plan.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Vindi\Payment\Model\Config\Source;
4+
5+
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
6+
use Vindi\Payment\Helper\Api;
7+
8+
/**
9+
* Class Plan
10+
*/
11+
class Plan extends AbstractSource
12+
{
13+
/**
14+
* @var Api
15+
*/
16+
private $api;
17+
18+
/**
19+
* Plan constructor.
20+
* @param Api $api
21+
*/
22+
public function __construct(
23+
Api $api
24+
) {
25+
$this->api = $api;
26+
}
27+
28+
/**
29+
* Get all options
30+
* @return array
31+
*/
32+
public function getAllOptions()
33+
{
34+
if ($this->_options === null) {
35+
$this->_options = [
36+
['label' => __('Create New Plan'), 'value' => 0]
37+
];
38+
39+
$this->_options = array_merge($this->_options, $this->getAvailablePlans());
40+
}
41+
42+
return $this->_options;
43+
}
44+
45+
/**
46+
* @return array
47+
*/
48+
public function getAvailablePlans()
49+
{
50+
$data = [];
51+
52+
$result = $this->api->request('plans?query=status%3Dactive', 'GET');
53+
54+
if (!empty($result) && !empty($result['plans'])) {
55+
foreach ($result['plans'] as $plan) {
56+
$data[] = [
57+
'label' => $plan['name'],
58+
'value' => $plan['id']
59+
];
60+
}
61+
}
62+
63+
return $data;
64+
}
65+
}

Model/Payment/AbstractMethod.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,17 @@ protected function processPayment(InfoInterface $payment, $amount)
251251

252252
/**
253253
* @param InfoInterface $payment
254-
* @param OrderItemInterface $plan
254+
* @param OrderItemInterface $orderItem
255255
* @return mixed
256256
* @throws LocalizedException
257257
*/
258-
private function handleSubscriptionOrder(InfoInterface $payment, OrderItemInterface $plan)
258+
private function handleSubscriptionOrder(InfoInterface $payment, OrderItemInterface $orderItem)
259259
{
260260
/** @var Order $order */
261261
$order = $payment->getOrder();
262262
$customerId = $this->customer->findOrCreate($order);
263-
$planId = $this->planManagement->create($plan->getProductId());
263+
264+
$planId = $this->planManagement->create($orderItem->getProductId());
264265

265266
$productItems = $this->productManagement->findOrCreateProductsToSubscription($order);
266267

Model/Vindi/PlanManagement.php

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function create($productId)
5151
throw new LocalizedException(__('Product Type not support to plan'));
5252
}
5353

54+
$planId = $product->getVindiPlanId();
55+
if ($planId) {
56+
return $planId;
57+
}
58+
5459
$data = [
5560
'name' => $product->getName(),
5661
'code' => Data::sanitizeItemSku($product->getSku()),

Observer/ProductSaveObserver.php

+4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public function execute(Observer $observer)
4747
return;
4848
}
4949

50+
if ($product->getVindiPlanId() > 0) {
51+
return;
52+
}
53+
5054
$this->plansManagement->create($product->getId());
5155
}
5256
}

Setup/UpgradeData.php

+43
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
1515
use Vindi\Payment\Model\Config\Source\BillingCycles;
1616
use Vindi\Payment\Model\Config\Source\Interval;
17+
use Vindi\Payment\Model\Config\Source\Plan;
1718
use Vindi\Payment\Model\Config\Source\BillingTriggerType;
1819

1920
/**
@@ -78,6 +79,10 @@ public function upgrade(
7879
$this->createPlanAttributeSet();
7980
$this->createProductAttributes();
8081
}
82+
83+
if (version_compare($context->getVersion(), "1.1.1", "<")) {
84+
$this->addPlanIdFieldProductAttribute();
85+
}
8186
}
8287

8388
/**
@@ -271,4 +276,42 @@ private function createProductAttributes()
271276
);
272277
}
273278
}
279+
280+
private function addPlanIdFieldProductAttribute()
281+
{
282+
/** @var EavSetup $eavSetup */
283+
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
284+
285+
$attribute = $eavSetup->getAttribute(Product::ENTITY, 'vindi_plan_id');
286+
if (!$attribute) {
287+
$eavSetup->addAttribute(Product::ENTITY, 'vindi_plan_id', [
288+
'sort_order' => 1,
289+
'type' => 'varchar',
290+
'backend' => '',
291+
'frontend' => '',
292+
'label' => 'Vindi Plan',
293+
'input' => 'select',
294+
'class' => '',
295+
'source' => Plan::class,
296+
'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
297+
'visible' => true,
298+
'required' => false,
299+
'user_defined' => true,
300+
'default' => null,
301+
'searchable' => false,
302+
'filterable' => false,
303+
'comparable' => false,
304+
'visible_on_front' => false,
305+
'used_in_product_listing' => false,
306+
'unique' => false
307+
]);
308+
309+
$eavSetup->addAttributeToGroup(
310+
Product::ENTITY,
311+
self::VINDI_PLANOS,
312+
self::VINDI_PLAN_SETTINGS,
313+
'vindi_plan_id'
314+
);
315+
}
316+
}
274317
}

etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" ?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
4-
<module name="Vindi_Payment" setup_version="1.1.0">
4+
<module name="Vindi_Payment" setup_version="1.1.1">
55
<sequence>
66
<module name="Magento_Sales"/>
77
</sequence>

i18n/pt_BR.csv

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,5 @@
115115
"Cancel Subscription","Cancelar Assinatura"
116116
"Something went wrong while cancel the Subscription.","Ocorreu um erro ao cancelar a assinatura."
117117
"You canceled the Subscription.","Você cancelou a assinatura."
118-
"Sync Subscription","Recarregar Assinaturas"
118+
"Vindi Plan","Plano Vindi"
119+
"Create New Plan","Criar Novo Plano"

view/adminhtml/templates/product/plan.phtml

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script>
22
require([
33
"jquery",
4-
], function ($) {
4+
"uiRegistry"
5+
], function ($, uiRegistry) {
56
var canChange = false;
67
var dayOptions = '<?php echo $block->getDayOptions() ?>';
78
var daysOfMonthOptions = '<?php echo $block->getDaysOfMonth() ?>';
@@ -38,5 +39,22 @@
3839
bodyElement.trigger('processStop');
3940
}
4041
});
42+
43+
$(document).on("change", "[name='product[vindi_plan_id]']", function () {
44+
var fieldsetIntervalCount = $('.admin__field-interval-count').parents('fieldset.admin__field');
45+
var fieldsetBillingTriggerType = $('.admin__field-billing-trigger-type').parents('fieldset.admin__field');
46+
47+
if ($(this).val() > 0) {
48+
fieldsetIntervalCount.addClass('hidden');
49+
fieldsetBillingTriggerType.addClass('hidden');
50+
51+
uiRegistry.get('index = vindi_interval_count', function (elem) {
52+
elem.value(0);
53+
});
54+
} else {
55+
fieldsetIntervalCount.removeClass('hidden');
56+
fieldsetBillingTriggerType.removeClass('hidden');
57+
}
58+
});
4159
});
4260
</script>

0 commit comments

Comments
 (0)