Skip to content

Commit

Permalink
fix(checkout): allow multiple address (#738)
Browse files Browse the repository at this point in the history
* fix(checkout): allow multiple address

* fix(pix): hide qrcode when order has not been created

* feat(success): show pix on multishipping success page
  • Loading branch information
criskell authored Nov 5, 2024
1 parent f818d07 commit e67a2f6
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 4 deletions.
86 changes: 86 additions & 0 deletions Pix/Block/Multishipping/Checkout/Success.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace OpenPix\Pix\Block\Multishipping\Checkout;

class Success extends \Magento\Multishipping\Block\Checkout\Success
{
protected $checkoutSession;
protected $customerSession;
protected $_orderFactory;
protected $_helperData;

const LOG_NAME = 'pix_multishipping_checkout_success_block';

public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Customer\Model\Session $customerSession,
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Multishipping\Model\Checkout\Type\Multishipping $multishipping,
\Magento\Sales\Model\OrderFactory $orderFactory,
\OpenPix\Pix\Helper\Data $helper,
array $data = [],
) {
parent::__construct($context, $multishipping, $data);

$this->checkoutSession = $checkoutSession;
$this->customerSession = $customerSession;
$this->_helperData = $helper;
$this->_orderFactory = $orderFactory;
}

public function getQrCodes()
{
$orderIds = $this->_session->getOrderIds();

if (! $orderIds || ! is_array($orderIds)) {
return [];
}

$qrCodes = [];

foreach ($orderIds as $orderId) {
$order = $this->_orderFactory->create()
->loadByIncrementId($orderId);

if (! $order->getId()) {
continue;
}

$correlationID = $order->getOpenpixCorrelationid();

if (empty($correlationID)) {
continue;
}

$qrCodes[] = [
'paymentLinkUrl' => $order->getOpenpixPaymentlinkurl(),
'brCodeImage' => $order->getOpenpixQrcodeimage(),
'brCode' => $order->getOpenpixBrcode(),
'correlationID' => $correlationID,
];
}

return $qrCodes;
}

public function getAppID(): string
{
$appID = $this->_helperData->getAppID();

if (isset($appID)) {
return $appID;
}

return '';
}

public function getPluginSrc(): string
{
return $this->_helperData->getOpenPixPluginUrlScript();
}

public function getCustomerId()
{
return $this->customerSession->getCustomer()->getId();
}
}
2 changes: 1 addition & 1 deletion Pix/etc/payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
<methods>
<method name="openpix_pix">
<allow_multiple_address>0</allow_multiple_address>
<allow_multiple_address>1</allow_multiple_address>
</method>
</methods>
</payment>
11 changes: 11 additions & 0 deletions Pix/view/frontend/layout/multishipping_checkout_success.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="OpenPix_Pix::js/copytoclipboard.js"/>
</head>
<body>
<referenceBlock name="checkout_success">
<block class="OpenPix\Pix\Block\Multishipping\Checkout\Success" name="openpix.info.payment.multishipping" template="OpenPix_Pix::multishipping/checkout/success.phtml" />
</referenceBlock>
</body>
</page>
10 changes: 7 additions & 3 deletions Pix/view/frontend/templates/info/pix.phtml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php

/**
* @var $block \OpenPix\Pix\Block\Info\Pix
* @var \OpenPix\Pix\Block\Info\Pix $block
*/

$order = $block->getInfo()->getOrder();
?>

<dl class="payment-method purchase order">
<dt class="title"><?= $block->escapeHtml($block->getMethod()->getTitle()) ?></dt>
<dd class="content">
<img src="<?= $block->getInfo()->getOrder()->getOpenpixQrcodeimage() ?>" width="200" height="200" />
<?php if ($order): ?>
<img src="<?= $order->getOpenpixQrcodeimage() ?>" width="200" height="200" />
<?php endif; ?>
</dd>
</dl>
</dl>
24 changes: 24 additions & 0 deletions Pix/view/frontend/templates/multishipping/checkout/success.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/** @var $block \Magento\Checkout\Block\Onepage\Success */

$src = $block->getPluginSrc();
$qrCodes = $block->getQrCodes();
$correlationID = $block->getCorrelationID();
$appID = $block->getAppID();
?>

<?php foreach ($qrCodes as $qrCode): ?>
<div class="actions-toolbar flex">
<div id="openpix-order" data-appid="<?= $appID ?>" data-correlationID="<?= $qrCode['correlationID'] ?>"></div>

<script>
require(["jquery", "OpenPix"], function($, pym) {});
</script>
</div>
<?php endforeach; ?>

0 comments on commit e67a2f6

Please sign in to comment.