Skip to content

Commit

Permalink
Merge pull request #4 from Styopchik/minimumorderfee-3
Browse files Browse the repository at this point in the history
Hide checkout agreement if fee is not applicable. fixes #3
  • Loading branch information
Styopchik committed Apr 18, 2019
2 parents d379d02 + 47ffe74 commit b26dd2d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
17 changes: 9 additions & 8 deletions Plugin/CheckoutAgreements/Model/AgreementsProviderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Netzexpert\MinimumOrderFee\Plugin\CheckoutAgreements\Model;


class AgreementsProviderPlugin
{

Expand All @@ -25,7 +24,7 @@ class AgreementsProviderPlugin
public function __construct(
\Magento\Checkout\Model\Session $session,
\Magento\CheckoutAgreements\Api\CheckoutAgreementsRepositoryInterface $checkoutAgreementsRepository
){
) {
$this->checkoutSession = $session;
$this->chekoutAgreementsRepository = $checkoutAgreementsRepository;
}
Expand All @@ -34,17 +33,18 @@ public function __construct(
/**
* @param \Magento\CheckoutAgreements\Model\AgreementsProvider $agreementsProvider
* @param int[] $agreementIds
* @return int[]
*/
public function afterGetRequiredAgreementIds(
\Magento\CheckoutAgreements\Model\AgreementsProvider $agreementsProvider,
$agreementIds
) {
$fee = $this->getMinimumOrderFeeValue();
if(!$fee){
foreach ($agreementIds as $key => $agreementId){
if (!$fee) {
foreach ($agreementIds as $key => $agreementId) {
$agreement = $this->chekoutAgreementsRepository->get($agreementId);
if ($agreement->getName() == 'Minimum Order Fee') {
unset ($agreementIds[$key]);
unset($agreementIds[$key]);
}
}
}
Expand All @@ -54,13 +54,14 @@ public function afterGetRequiredAgreementIds(
/**
* @return bool
*/
protected function getMinimumOrderFeeValue(){
protected function getMinimumOrderFeeValue()
{
$totals = $this->checkoutSession->getQuote()->getTotals();
if(!isset($totals['minimumorderfee'])){
if (!isset($totals['minimumorderfee'])) {
return false;
}
/** @var \Magento\Quote\Model\Quote\Address\Total $minimumOrderFee */
$minimumOrderFee = $totals['minimumorderfee'];
return $minimumOrderFee->getValue();
}
}
}
35 changes: 35 additions & 0 deletions Plugin/CheckoutAgreementsListPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Created by Andrew Stepanchuk.
* Date: 18.04.19
* Time: 16:12
*/

namespace Netzexpert\MinimumOrderFee\Plugin;

use Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface;
use Magento\CheckoutAgreements\Api\Data\AgreementInterface;
use Netzexpert\MinimumOrderFee\Plugin\CheckoutAgreements\Model\AgreementsProviderPlugin;

class CheckoutAgreementsListPlugin extends AgreementsProviderPlugin
{
/**
* @param CheckoutAgreementsListInterface $agreementsList
* @param AgreementInterface[] $agreements
* @return mixed
*/
public function afterGetList(
CheckoutAgreementsListInterface $agreementsList,
$agreements
) {
$fee = $this->getMinimumOrderFeeValue();
if (!$fee) {
foreach ($agreements as $key => $agreement) {
if ($agreement->getName() == 'Minimum Order Fee') {
unset($agreements[$key]);
}
}
}
return $agreements;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"magento/module-sales": ">=100.0.0 <104"
},
"type": "magento2-module",
"version": "1.0.1",
"version": "1.0.2",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
4 changes: 4 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
<plugin name="minimum_order_fee_message"
type="Netzexpert\MinimumOrderFee\Plugin\Checkout\CustomerData\CartPlugin" />
</type>
<type name="Magento\CheckoutAgreements\Api\CheckoutAgreementsListInterface">
<plugin name="feeFilterAgreements"
type="Netzexpert\MinimumOrderFee\Plugin\CheckoutAgreementsListPlugin" />
</type>
</config>

0 comments on commit b26dd2d

Please sign in to comment.