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

MiniCart fix for m2.1.9 #115

Merged
merged 4 commits into from
Sep 20, 2018
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
70 changes: 70 additions & 0 deletions Block/Checkout/Success.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* Bolt magento2 plugin
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category Bolt
* @package Bolt_Boltpay
* @copyright Copyright (c) 2018 Bolt Financial, Inc (https://www.bolt.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace Bolt\Boltpay\Block\Checkout;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\App\ProductMetadataInterface;

/**
* Class Success
*
* @package Bolt\Boltpay\Block\Checkout
*/
class Success extends Template
{
/**
* @var ProductMetadataInterface
*/
private $productMetadata;

/**
* Success constructor.
*
* @param ProductMetadataInterface $productMetadata
* @param Context $context
* @param array $data
*/
public function __construct(
ProductMetadataInterface $productMetadata,
Context $context,
array $data = []
){
parent::__construct($context, $data);

$this->productMetadata = $productMetadata;
}

/**
* @return bool
*/
public function isAllowInvalidateQuote()
{
// Workaround for known magento issue - https://github.com/magento/magento2/issues/12504
return (bool) (version_compare($this->getMagentoVersion(), '2.2.0', '<'));
}

/**
* Get magento version
*
* @return string
*/
private function getMagentoVersion()
{
return $this->productMetadata->getVersion();
}
}
41 changes: 41 additions & 0 deletions Plugin/ClearQuote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Bolt magento2 plugin
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category Bolt
* @package Bolt_Boltpay
* @copyright Copyright (c) 2018 Bolt Financial, Inc (https://www.bolt.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
namespace Bolt\Boltpay\Plugin;

use Magento\Checkout\Model\Session as CheckoutSession;

/**
* Class ClearQuote
*
* @package Bolt\Boltpay\Plugin
*/
class ClearQuote
{
/**
* @param CheckoutSession $subject
* @return CheckoutSession
* @throws \Exception
*/
public function afterClearQuote(CheckoutSession $subject)
{
// Workaround for known magento issue - https://github.com/magento/magento2/issues/12504
$subject->setLoadInactive(false);
$subject->replaceQuote($subject->getQuote()->save());

return $subject;
}
}
3 changes: 3 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@
<argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session</argument>
</arguments>
</type>
<type name="Magento\Checkout\Model\Session">
<plugin name="BoltClearQuoteAfterOrderCompletion" type="Bolt\Boltpay\Plugin\ClearQuote" />
</type>
</config>
14 changes: 14 additions & 0 deletions view/frontend/layout/checkout_onepage_success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="content">
<block class="Bolt\Boltpay\Block\Checkout\Success" name="bolt.success.page" template="Bolt_Boltpay::checkout/success.phtml" after="-" />
</referenceBlock>
</body>
</page>
11 changes: 11 additions & 0 deletions view/frontend/templates/checkout/success.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php /* @var $block Bolt\Boltpay\Block\Checkout\Success */ ?>
<?php if ($block->isAllowInvalidateQuote()): ?>
<script>
require([
'Magento_Customer/js/customer-data'
], function (customerData) {
var sections = ['cart'];
customerData.invalidate(sections);
});
</script>
<?php endif; ?>