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

[PaymentProvider] fix payment provider rule action and add payment provider rule condition #2614

Merged
merged 1 commit into from
Apr 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ public function __construct(
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('paymentproviderRule', PaymentProviderRuleChoiceType::class, [
->add('paymentProviderRule', PaymentProviderRuleChoiceType::class, [
'constraints' => [
new NotBlank(['groups' => $this->validationGroups]),
],
])
;

$builder->get('paymentproviderRule')->addModelTransformer(new CallbackTransformer(
function (mixed $paymentproviderRule) {
if ($paymentproviderRule instanceof PaymentProviderRuleInterface) {
return $paymentproviderRule->getId();
$builder->get('paymentProviderRule')->addModelTransformer(new CallbackTransformer(
function (mixed $paymentProviderRule) {
if ($paymentProviderRule instanceof PaymentProviderRuleInterface) {
return $paymentProviderRule->getId();
}

return null;
},
function (mixed $paymentproviderRule) {
if ($paymentproviderRule instanceof PaymentProviderRuleInterface) {
return $paymentproviderRule->getId();
function (mixed $paymentProviderRule) {
if ($paymentProviderRule instanceof PaymentProviderRuleInterface) {
return $paymentProviderRule->getId();
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ core_shop_payment:
payment_provider_rule_conditions_paymentProviderRule: '/bundles/coreshoppayment/pimcore/js/paymentproviderrule/conditions/paymentProviderRule.js'
payment_provider_rule_actions_addition_percent: '/bundles/coreshoppayment/pimcore/js/paymentproviderrule/actions/additionPercent.js'
payment_provider_rule_actions_discount_percent: '/bundles/coreshoppayment/pimcore/js/paymentproviderrule/actions/discountPercent.js'
payment_provider_rule_actions_paymentProviderRule: '/bundles/coreshoppayment/pimcore/js/paymentproviderrule/actions/paymentProviderRule.js'


payment_gateway_abstract: '/bundles/coreshoppayment/pimcore/js/provider/gateways/abstract.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ services:
coreshop.form_registry.payment_provider_rule.conditions:
class: CoreShop\Bundle\ResourceBundle\Form\Registry\FormTypeRegistry


coreshop.registry.payment_provider_rule.actions:
class: CoreShop\Component\Registry\ServiceRegistry
arguments:
Expand Down Expand Up @@ -46,6 +45,12 @@ services:
tags:
- { name: coreshop.payment_provider_rule.condition, type: amount, form-type: CoreShop\Bundle\PaymentBundle\Form\Type\Rule\Condition\AmountConfigurationType }

CoreShop\Component\Payment\Rule\Condition\PaymentProviderRuleConditionChecker:
arguments:
- '@coreshop.payment_provider_rule.processor'
- '@coreshop.repository.payment_provider_rule'
tags:
- { name: coreshop.payment_provider_rule.condition, type: paymentProviderRule, form-type: CoreShop\Bundle\PaymentBundle\Form\Type\Rule\Common\PaymentProviderRuleConfigurationType }

coreshop.payment_provider_rule.condition.nested:
class: CoreShop\Component\Rule\Condition\NestedConditionChecker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ body.pimcore_version_10 .coreshop_nav_icon_payment_provider {
background: url(../img/payment-provider-rule.svg) center center no-repeat !important;
}

body.pimcore_version_10 .coreshop_nav_icon_payment_provider_rule {
body.pimcore_version_10 .coreshop_nav_icon_payment_provider_rule,
.coreshop_rule_icon_action_paymentProviderRule,
.coreshop_rule_icon_condition_paymentProviderRule {
background: url(../img/payment-provider-rule_white.svg) center center no-repeat !important;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GPLv3 and CCL
*
*/

pimcore.registerNS('coreshop.paymentproviderrule.actions.paymentProviderRule');

coreshop.paymentproviderrule.actions.paymentProviderRule = Class.create(coreshop.rules.conditions.abstract, {
type: 'paymentProviderRule',

getForm: function () {
var me = this;

var rule = {
xtype: 'combo',
fieldLabel: t('coreshop_action_paymentProviderRule'),
typeAhead: true,
listWidth: 100,
width: 500,
store: {
type: 'coreshop_payment_provider_rules'
},
displayField: 'name',
valueField: 'id',
forceSelection: true,
multiselect: true,
triggerAction: 'all',
name: 'paymentProviderRule',
maxHeight: 400,
delimiter: false,
value: me.data.paymentProviderRule
};

if (this.data && this.data.paymentProviderRule) {
rule.value = this.data.paymentProviderRule;
}

this.form = new Ext.form.Panel({
items: [
rule
]
});

return this.form;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,36 @@
*
*/

pimcore.registerNS('coreshop.paymentproviderrule.conditions.paymentproviderRule');
pimcore.registerNS('coreshop.paymentproviderrule.conditions.paymentProviderRule');

coreshop.paymentproviderrule.conditions.paymentproviderRule = Class.create(coreshop.rules.conditions.abstract, {
type: 'paymentproviderRule',
coreshop.paymentproviderrule.conditions.paymentProviderRule = Class.create(coreshop.rules.conditions.abstract, {
type: 'paymentProviderRule',

getForm: function () {
var me = this;
var store = pimcore.globalmanager.get('');

var rule = {
xtype: 'combo',
fieldLabel: t('coreshop_condition_paymentproviderRule'),
fieldLabel: t('coreshop_condition_paymentProviderRule'),
typeAhead: true,
listWidth: 100,
width: 500,
store: {
type: 'coreshop_paymentprovider_rules'
type: 'coreshop_payment_provider_rules'
},
displayField: 'name',
valueField: 'id',
forceSelection: true,
multiselect: true,
triggerAction: 'all',
name: 'paymentproviderRule',
name: 'paymentProviderRule',
maxHeight: 400,
delimiter: false,
value: me.data.paymentproviderRule
value: me.data.paymentProviderRule
};

if (this.data && this.data.paymentproviderRule) {
rule.value = this.data.paymentproviderRule;
if (this.data && this.data.paymentProviderRule) {
rule.value = this.data.paymentProviderRule;
}

this.form = new Ext.form.Panel({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ coreshop.provider.item = Class.create(coreshop.resource.item, {
this.paymentProviderRuleGroupsGrid = Ext.create('Ext.grid.Panel', {
columns: [
{
header: t('coreshop_carriers_payment_provider_rule'),
header: t('coreshop_payment_provider_rule'),
flex: 2,
dataIndex: 'paymentProviderRule',
editor: new Ext.form.ComboBox({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ coreshop_payment_sofort_config_key: 'Konfigurationsschlüssel'
coreshop_paypal_sandbox: 'Sandbox'
coreshop_logo: 'Logo'
coreshop_payment_provider_rule: 'Zahlungsanbieterregel'
coreshop_action_paymentProviderRule: 'Zahlungsanbieterregel'
coreshop_condition_paymentProviderRule: 'Zahlungsanbieterregel'
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ coreshop_payment_sofort_config_key: 'Config Key'
coreshop_paypal_sandbox: 'Sandbox'
coreshop_logo: 'Logo'
coreshop_payment_provider_rule: 'Payment Provider Rules'
coreshop_payment_provider_main_panel: 'Main'
coreshop_payment_provider_main_panel: 'Main'
coreshop_action_paymentProviderRule: 'Payment Provider Rule'
coreshop_condition_paymentProviderRule: 'Payment Provider Rule'
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

/*
* CoreShop
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - CoreShop Commercial License (CCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GPLv3 and CCL
*
*/

namespace CoreShop\Component\Payment\Rule\Condition;

use CoreShop\Component\Payment\Model\PayableInterface;
use CoreShop\Component\Payment\Model\PaymentProviderInterface;
use CoreShop\Component\Payment\Model\PaymentProviderRuleInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use CoreShop\Component\Rule\Condition\RuleValidationProcessorInterface;

class PaymentProviderRuleConditionChecker extends AbstractConditionChecker
{
public function __construct(
protected RuleValidationProcessorInterface $ruleValidationProcessor,
protected RepositoryInterface $paymentProviderRuleRepository,
) {
}

public function isPaymentProviderRuleValid(
PaymentProviderInterface $paymentProvider,
PayableInterface $payable,
array $configuration
): bool {
$paymentProviderRuleId = $configuration['paymentProviderRule'];
$paymentProviderRule = $this->paymentProviderRuleRepository->find($paymentProviderRuleId);

if ($paymentProviderRule instanceof PaymentProviderRuleInterface) {
return $this->ruleValidationProcessor->isValid($paymentProvider, $paymentProviderRule, ['payable' => $payable]);
}

return false;
}
}