Skip to content
This repository has been archived by the owner on Aug 1, 2018. It is now read-only.

Commit

Permalink
FIX issue #29
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Aug 17, 2017
1 parent fe2d0b9 commit c8aa29d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
21 changes: 20 additions & 1 deletion Model/Total/Quote/AbstractTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,38 @@

namespace MSP\CashOnDelivery\Model\Total\Quote;

use Magento\Quote\Api\PaymentMethodManagementInterface;
use Magento\Quote\Model\Quote\Address\Total\AbstractTotal as MageAbstractTotal;
use Magento\Quote\Model\Quote\Address\Total;
use Magento\Quote\Model\Quote;

abstract class AbstractTotal extends MageAbstractTotal
{
/**
* @var PaymentMethodManagementInterface
*/
private $paymentMethodManagement;

public function __construct(PaymentMethodManagementInterface $paymentMethodManagement)
{
$this->paymentMethodManagement = $paymentMethodManagement;
}

/**
* Return true if can apply totals
* @param Quote $quote
* @return bool
*/
protected function _canApplyTotal(Quote $quote)
{
// FIX bug issue #29
if (!$quote->getId()) {
return false;
}
$paymentMethodsList = $this->paymentMethodManagement->getList($quote->getId());
if ((count($paymentMethodsList) == 1) && ($paymentMethodsList[0]->getCode() == 'msp_cashondelivery')) {
return true;
}

return ($quote->getPayment()->getMethod() == 'msp_cashondelivery');
}
}
4 changes: 4 additions & 0 deletions Model/Total/Quote/Cashondelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace MSP\CashOnDelivery\Model\Total\Quote;

use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Quote\Api\PaymentMethodManagementInterface;
use Magento\Quote\Model\Quote\Address\Total;
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
use Magento\Quote\Model\Quote;
Expand All @@ -33,9 +34,12 @@ class Cashondelivery extends AbstractTotal
protected $priceCurrencyInterface;

public function __construct(
PaymentMethodManagementInterface $paymentMethodManagement,
PriceCurrencyInterface $priceCurrencyInterface,
CashondeliveryInterface $cashOnDeliveryInterface
) {
parent::__construct($paymentMethodManagement);

$this->cashOnDeliveryInterface = $cashOnDeliveryInterface;
$this->priceCurrencyInterface = $priceCurrencyInterface;
$this->setCode('msp_cashondelivery');
Expand Down
3 changes: 3 additions & 0 deletions Model/Total/Quote/CashondeliveryTax.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
namespace MSP\CashOnDelivery\Model\Total\Quote;

use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Quote\Api\PaymentMethodManagementInterface;
use Magento\Quote\Model\Quote\Address\Total;
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
use Magento\Quote\Model\Quote;
Expand All @@ -33,9 +34,11 @@ class CashondeliveryTax extends AbstractTotal
protected $priceCurrencyInterface;

public function __construct(
PaymentMethodManagementInterface $paymentMethodManagement,
PriceCurrencyInterface $priceCurrencyInterface,
CashondeliveryInterface $cashOnDeliveryInterface
) {
parent::__construct($paymentMethodManagement);
$this->cashOnDeliveryInterface = $cashOnDeliveryInterface;
$this->priceCurrencyInterface = $priceCurrencyInterface;
}
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MSP_CashOnDelivery" setup_version="1.1.7">
<module name="MSP_CashOnDelivery" setup_version="1.1.8">
<sequence>
<module name="Magento_Sales" />
<module name="Magento_Payment" />
Expand Down

0 comments on commit c8aa29d

Please sign in to comment.