-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0"?> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceBlock name="head.additional"> | ||
<block name="paazl-js" | ||
template="Elgentos_HyvaCheckoutPaazl::paazl-scripts.phtml" after="-"/> | ||
</referenceBlock> | ||
|
||
<referenceBlock name="checkout.shipping.methods"> | ||
<arguments> | ||
<argument name="magewire" xsi:type="object"> | ||
Elgentos\HyvaCheckoutPaazl\Magewire\Shipping\MethodList\MethodListExtend | ||
</argument> | ||
</arguments> | ||
<block name="checkout.shipping.method.paazl" template="Elgentos_HyvaCheckoutPaazl::paazl.phtml" | ||
as="paazlshipping_paazlshipping"> | ||
<arguments> | ||
<argument name="magewire" xsi:type="object"> | ||
Elgentos\HyvaCheckoutPaazl\Magewire\Shipping\Method\Paazl | ||
</argument> | ||
</arguments> | ||
</block> | ||
</referenceBlock> | ||
|
||
</body> | ||
</page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/* | ||
* Copyright © elgentos. All rights reserved. | ||
* https://elgentos.nl | ||
*/ | ||
|
||
use Elgentos\HyvaCheckoutPaazl\ViewModel\Shipping\Method\Paazl as PaazlViewModel; | ||
use Hyva\Theme\Model\ViewModelRegistry; | ||
use Magento\Framework\Escaper; | ||
use Magento\Framework\View\Element\Template; | ||
|
||
/** @var Escaper $escaper */ | ||
/** @var ViewModelRegistry $viewModels */ | ||
/** @var Template $block */ | ||
|
||
$paazlViewModel = $viewModels->require(PaazlViewModel::class); | ||
$paazlConfig = $paazlViewModel->getPaazlConfig(); | ||
|
||
?> | ||
|
||
|
||
<?php if ($paazlViewModel->getPaazlMode() === 'live') : ?> | ||
<script preload src="<?= $escaper->escapeUrl($block->getViewFileUrl('Paazl_CheckoutWidget::js/checkout/lib/checkout_local_live.js')); ?>"></script> | ||
<?php else : ?> | ||
<script preload src="<?= $escaper->escapeUrl($block->getViewFileUrl('Paazl_CheckoutWidget::js/checkout/lib/checkout_local_test.js')); ?>"></script> | ||
<?php endif; ?> | ||
|
||
|
||
<script> | ||
window.addEventListener('postcode:updated', (event) => { | ||
if (event.detail.postcode === '') { | ||
return; | ||
} | ||
|
||
PaazlCheckout.setConsigneeCountryCode(event.detail.country); | ||
PaazlCheckout.setConsigneePostalCode(event.detail.postcode); | ||
}); | ||
|
||
function isCheckoutUrl(url) { | ||
const checkoutApiUrl = '<?= $escaper->escapeUrl($paazlConfig['paazlshipping']['checkoutApiUrl']) ?>'; | ||
return checkoutApiUrl && (checkoutApiUrl.indexOf( | ||
url) === 0); | ||
} | ||
|
||
function isLocationUrl(url) { | ||
let locationsUrl = '<?= $escaper->escapeUrl($paazlConfig['paazlshipping']['baseApiUrl']) ?>'; | ||
locationsUrl += 'pickuplocations'; | ||
return (locationsUrl.indexOf(url) === 0); | ||
} | ||
|
||
let openOrig = window.XMLHttpRequest.prototype.open; | ||
let sendOrig = window.XMLHttpRequest.prototype.send; | ||
|
||
window.XMLHttpRequest.prototype.open = function (method, url, async, user, password) { | ||
return openOrig.apply(this, arguments); | ||
}; | ||
|
||
window.XMLHttpRequest.prototype.send = function (body) { | ||
this.removeEventListener('load', onLocationSelect); | ||
this.addEventListener('load', onLocationSelect.bind(this, body)); | ||
return sendOrig.apply(this, arguments); | ||
}; | ||
|
||
function onLocationSelect(body, event) { | ||
var ready = | ||
(this.readyState === 4) | ||
&& event.target | ||
&& this.responseURL | ||
&& (event.target.status === 200); | ||
if (ready && isCheckoutUrl(this.responseURL)) { | ||
Magewire.emit('paazle_updated', body?.shippingOption?.identifier); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/* | ||
* Copyright © elgentos. All rights reserved. | ||
* https://elgentos.nl | ||
*/ | ||
|
||
use Elgentos\HyvaCheckoutPaazl\ViewModel\Shipping\Method\Paazl as PaazlViewModel; | ||
use Hyva\Theme\Model\ViewModelRegistry; | ||
use Magento\Framework\Escaper; | ||
use Magento\Framework\View\Element\Template; | ||
|
||
/** @var Escaper $escaper */ | ||
/** @var ViewModelRegistry $viewModels */ | ||
/** @var Template $block */ | ||
|
||
$paazlViewModel = $viewModels->require(PaazlViewModel::class); | ||
|
||
$widgetConfig = $paazlViewModel->getWidgetConfig(); | ||
$paazlConfig = $paazlViewModel->getPaazlConfig(); | ||
|
||
?> | ||
|
||
<div> | ||
<script> | ||
PaazlCheckout.init(<?= /** @noEscape */ json_encode($widgetConfig); ?>); | ||
</script> | ||
|
||
<div id="widget_paazlshipping_paazlshipping"></div> | ||
</div> |