Skip to content
Open
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
79 changes: 57 additions & 22 deletions Block/Checkout/Minicart.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,21 @@

namespace Bread\BreadCheckout\Block\Checkout;

use Bread\BreadCheckout\Helper\Catalog;
use Bread\BreadCheckout\Helper\Customer;
use Bread\BreadCheckout\Helper\Quote;
use Bread\BreadCheckout\Model\Payment\Method\BreadPaymentMethodFactory;
use Magento\Catalog\Block\ShortcutInterface;
use Magento\Catalog\Helper\Product;
use Magento\Checkout\Model\Session;
use Magento\ConfigurableProduct\Model\ConfigurableAttributeData;
use Magento\ConfigurableProduct\Model\Product\Type\ConfigurableFactory;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Locale\ResolverInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\Stdlib\ArrayUtils;
use Magento\Framework\View\Element\Template\Context;
use Magento\Payment\Model\MethodInterface;
use Bread\BreadCheckout\Helper\Data;
Expand Down Expand Up @@ -39,12 +50,25 @@ class Minicart extends Overview implements ShortcutInterface
/**
* Minicart constructor.
*
* @param Context $context
* @param ResolverInterface $localeResolver
* @param Session $checkoutSession
* @param BreadPaymentMethodFactory $breadPaymentMethodFactory
* @param Data $helperData
* @param array $data
* @param \Magento\Catalog\Block\Product\Context $context
* @param \Magento\Framework\Json\Helper\Data $jsonHelper
* @param Catalog $catalogHelper
* @param Customer $customerHelper
* @param Data $dataHelper
* @param ConfigurableFactory $configurableProductFactory
* @param \Magento\ConfigurableProduct\Block\Product\View\Type\ConfigurableFactory $configurableBlockFactory
* @param Quote $quoteHelper
* @param ArrayUtils $arrayUtils
* @param EncoderInterface $jsonEncoder
* @param \Magento\ConfigurableProduct\Helper\Data $configurableHelper
* @param Product $catalogProductHelper
* @param CurrentCustomer $currentCustomer
* @param PriceCurrencyInterface $priceCurrency
* @param ConfigurableAttributeData $configurableAttributeData
* @param Session $checkoutSession
* @param BreadPaymentMethodFactory $paymentFactory
* @param Data $helperData
* @param array $data
*/
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
Expand All @@ -63,7 +87,7 @@ public function __construct(
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
\Magento\ConfigurableProduct\Model\ConfigurableAttributeData $configurableAttributeData,
Session $checkoutSession,
BreadPaymentMethodFactory $breadPaymentMethodFactory,
private BreadPaymentMethodFactory $paymentFactory,
Data $helperData,
array $data = []
) {
Expand All @@ -87,7 +111,6 @@ public function __construct(
);

$this->checkoutSession = $checkoutSession;
$this->payment = $breadPaymentMethodFactory->create();
$this->helperData = $helperData;
$this->quoteHelper = $quoteHelper;
}
Expand Down Expand Up @@ -120,25 +143,37 @@ public function getContainerId()
}

/**
* Check if the block should be displayed
*
* @return bool
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Exception
*/
public function isActive()
{
$show = ($this->isApiVersionIsBread2())
? $this->helperData->showMinicartLink()
: $this->helperData->allowMinicartCheckout();
if (!$show) {
return false;
}

if (!$this->payment) {
$this->payment = $this->paymentFactory->create();
}

return $this->payment->isAvailable($this->checkoutSession->getQuote()) &&
!$this->isCartView() &&
$this->quoteHelper->aboveThreshold($this->quoteHelper->getGrandTotal()/100);
}

$aboveThreshold = $this->quoteHelper->aboveThreshold($this->quoteHelper->getGrandTotal()/100);
$apiVersion = $this->helperData->getApiVersion();
if($apiVersion === 'bread_2') {
return $this->payment->isAvailable($this->checkoutSession->getQuote()) &&
$this->helperData->showMinicartLink() &&
!$this->isCartView() &&
$aboveThreshold;
} else {
return $this->payment->isAvailable($this->checkoutSession->getQuote()) &&
$this->helperData->allowMinicartCheckout() &&
!$this->isCartView() &&
$aboveThreshold;
}
/**
* Check if API version is bread_2
*
* @return bool
*/
private function isApiVersionIsBread2(): bool
{
return $this->helperData->getApiVersion() === 'bread_2';
}

/**
Expand Down
25 changes: 22 additions & 3 deletions Model/Payment/Method/BreadPaymentMethodFactory.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php
<?php

namespace Bread\BreadCheckout\Model\Payment\Method;

class BreadPaymentMethodFactory
{
protected $objectManager;
protected $helper;
protected $quoteHelper;

/**
* Constructor.
*
* @param \Magento\Framework\ObjectManagerInterface $objectManager
* @param \Bread\BreadCheckout\Helper\Data $helper
* @param \Bread\BreadCheckout\Helper\Quote $quoteHelper
*/
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
\Bread\BreadCheckout\Helper\Data $helper,
Expand All @@ -16,7 +24,17 @@ public function __construct(
$this->helper = $helper;
$this->quoteHelper = $quoteHelper;
}
public function create($quote = null, array $data = array())

/**
* Create Payment Method.
*
* @param null $quote
* @param array $data
*
* @return mixed
* @throws \Exception
*/
public function create($quote = null, array $data = [])
{
$currentCurrencyCode = $this->helper->getCurrentCurrencyCode();
// Get currency from quote if it was passed in
Expand All @@ -31,6 +49,7 @@ public function create($quote = null, array $data = array())
} else {
$instanceName = 'Bread\BreadCheckout\Model\Payment\Method\Bread';
}

return $this->objectManager->create($instanceName, $data);
}
}
9 changes: 8 additions & 1 deletion etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

<type name="Bread\BreadCheckout\Block\Checkout\Minicart">
<arguments>
<argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session\Proxy</argument>
<argument name="data" xsi:type="array">
<item name="template" xsi:type="string">Bread_BreadCheckout::breadcheckout/minicart.phtml</item>
<item name="alias" xsi:type="string">breadcheckout.mini-cart</item>
Expand All @@ -23,4 +24,10 @@
<argument name="payment" xsi:type="object">Bread\BreadCheckout\Model\Payment\Method\BreadPaymentMethodFactory</argument>
</arguments>
</type>
</config>

<type name="Bread\BreadCheckout\Helper\Quote">
<arguments>
<argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session\Proxy</argument>
</arguments>
</type>
</config>