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

#86bx34e41 amasty checkout fixes #28

Merged
merged 2 commits into from
Feb 9, 2024
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
48 changes: 44 additions & 4 deletions Model/Carrier/Parcelpro.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public function collectRates(RateRequest $request)
->getQuote()->getGrandTotal();
}

$freeBoxes = $this->getFreeBoxesCount($request);

if ($_pricIncl) {
$total = $grandTotal; // Verzendkosten berekenen op basis van bedrag incl. BTW
}
Expand Down Expand Up @@ -218,8 +220,8 @@ public function collectRates(RateRequest $request)
}
$method->setMethod($key);
$method->setMethodTitle($pricerule['titel']);
$method->setPrice($request->getFreeShipping() === true ? 0 : $shippingPrice);
$method->setCost($request->getFreeShipping() === true ? 0 : $shippingPrice);
$method->setPrice($request->getFreeShipping() === true || $request->getPackageQty() == $freeBoxes ? 0 : $shippingPrice);
$method->setCost($request->getFreeShipping() === true || $request->getPackageQty() == $freeBoxes ? 0 : $shippingPrice);
$result->append($method);
}

Expand All @@ -244,8 +246,8 @@ public function collectRates(RateRequest $request)

$method->setMethod($key . "_" . $counter);
$method->setMethodTitle($pricerule['titel']);
$method->setPrice($request->getFreeShipping() === true ? 0 : $shippingPrice);
$method->setCost($request->getFreeShipping() === true ? 0 : $shippingPrice);
$method->setPrice($request->getFreeShipping() === true || $request->getPackageQty() == $freeBoxes ? 0 : $shippingPrice);
$method->setCost($request->getFreeShipping() === true || $request->getPackageQty() == $freeBoxes ? 0 : $shippingPrice);
$result->append($method);
}
}
Expand Down Expand Up @@ -347,4 +349,42 @@ private function isBeforeLastShippingTime($rawLastTime): bool
$now = new DateTime();
return $now < $parsed;
}

/**
* @param RateRequest $request
* @return int
*/
private function getFreeBoxesCount(RateRequest $request)
{
$freeBoxes = 0;
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
if ($item->getProduct()->isVirtual() || $item->getParentItem()) {
continue;
}

if ($item->getHasChildren() && $item->isShipSeparately()) {
$freeBoxes += $this->getFreeBoxesCountFromChildren($item);
} elseif ($item->getFreeShipping()) {
$freeBoxes += $item->getQty();
}
}
}
return $freeBoxes;
}

/**
* @param mixed $item
* @return mixed
*/
private function getFreeBoxesCountFromChildren($item)
{
$freeBoxes = 0;
foreach ($item->getChildren() as $child) {
if ($child->getFreeShipping() && !$child->getProduct()->isVirtual()) {
$freeBoxes += $item->getQty() * $child->getQty();
}
}
return $freeBoxes;
}
}
6 changes: 5 additions & 1 deletion view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ config = {
"Amasty_Checkout/template/onepage/3columns.html":"Parcelpro_Shipment/template/onepage/3columns.html",
// 'Magento_Checkout/js/view/billing-address': "Parcelpro_Shipment/js/view/billing-address",
"Amasty_Checkout/template/onepage/shipping/address.html": "Parcelpro_Shipment/template/amastyonepage/shipping.html",
"Amasty_Checkout/template/onepage/shipping/methods.html": "Parcelpro_Shipment/template/amastyonepage/methods.html"
"Amasty_Checkout/template/onepage/shipping/methods.html": "Parcelpro_Shipment/template/amastyonepage/methods.html",
"Amasty_CheckoutCore/template/onepage/shipping/methods.html": "Parcelpro_Shipment/template/amastyonepage/methods.html"
/*
** FireCheckout ondersteuning
** Onderstaande regel activeren zodat gekozen pakketpunt opgeslagen wordt bij de order.
Expand All @@ -19,6 +20,9 @@ config = {
"Magento_Checkout/js/view/billing-address": {
"Parcelpro_Shipment/js/view/billing-address-mixin": true
},
"Magento_Checkout/js/model/shipping-save-processor/default" : {
"Parcelpro_Shipment/js/model/shipping-save-processor/default-mixin" : true
},
"Amasty_Checkout/js/action/set-shipping-information": {
"Parcelpro_Shipment/js/action/set-shipping-information-mixin" : true
},
Expand Down
100 changes: 100 additions & 0 deletions view/frontend/web/js/model/shipping-save-processor/default-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright © CM.com. All rights reserved.
* See LICENSE.txt for license details.
*/

define([
'ko',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/resource-url-manager',
'mage/storage',
'Magento_Checkout/js/model/payment-service',
'Magento_Checkout/js/model/payment/method-converter',
'Magento_Checkout/js/model/error-processor',
'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/action/select-billing-address',
'Magento_Checkout/js/model/shipping-save-processor/payload-extender',
'underscore'
], function (
ko,
quote,
resourceUrlManager,
storage,
paymentService,
methodConverter,
errorProcessor,
fullScreenLoader,
selectBillingAddressAction,
payloadExtender,
_
) {
'use strict';

return function (defaultProcessor) {
defaultProcessor.saveShippingInformation = function () {
let payload;

if (!quote.billingAddress() || (quote.shippingMethod().method_code == 'postnl_pakjegemak' || quote.shippingMethod().method_code == 'dpd_parcelshop' || quote.shippingMethod().method_code == 'dhl_parcelshop' || quote.shippingMethod().method_code == 'intrapost_parcelshop')) {
if(quote.billingAddress() === null) selectBillingAddressAction(quote.shippingAddress());
if(! quote.billingAddress()) return;

var billingstreet = quote.billingAddress().street[0];
if(quote.shippingMethod().method_code == 'postnl_pakjegemak' || quote.shippingMethod().method_code == 'dhl_parcelshop' || quote.shippingMethod().method_code == 'dpd_parcelshop' || quote.shippingMethod().method_code == 'intrapost_parcelshop'){

quote.shippingAddress().company = jQuery("#shipping_method\\:company").val();
quote.shippingAddress().firstname = jQuery("#shipping_method\\:firstname").val();
quote.shippingAddress().lastname = jQuery("#shipping_method\\:lastname").val();
var street = jQuery("#shipping_method\\:street1").val();
var number = jQuery("#shipping_method\\:street2").val();
quote.shippingAddress().street = [street, number];
quote.shippingAddress().postcode = jQuery("#shipping_method\\:postcode").val();
quote.shippingAddress().city = jQuery("#shipping_method\\:city").val();
quote.shippingAddress().customerAddressId = null;
quote.shippingAddress().customerId = null;
quote.shippingAddress().isDefaultShipping(false);
quote.shippingAddress().canUseForBilling(false);
}
if(
quote.shippingAddress().firstname.toLowerCase().indexOf("postnl") == -1 &&
quote.shippingAddress().firstname.toLowerCase().indexOf("dhl") == -1 &&
quote.shippingAddress().firstname.toLowerCase().indexOf("dpd") == -1 &&
quote.shippingAddress().firstname.toLowerCase().indexOf("intrapost") == -1
){
quote.billingAddress().street[0] = billingstreet;
selectBillingAddressAction(quote.billingAddress());
}
}

payload = {
addressInformation: {
'shipping_address': quote.shippingAddress(),
'billing_address': quote.billingAddress(),
'shipping_method_code': quote.shippingMethod()['method_code'],
'shipping_carrier_code': quote.shippingMethod()['carrier_code']
}
};

payloadExtender(payload);

fullScreenLoader.startLoader();

return storage.post(
resourceUrlManager.getUrlForSetShippingInformation(quote),
JSON.stringify(payload)
).done(
function (response) {
quote.setTotals(response.totals);
paymentService.setPaymentMethods(methodConverter(response['payment_methods']));
fullScreenLoader.stopLoader();
}
).fail(
function (response) {
errorProcessor.process(response);
fullScreenLoader.stopLoader();
}
);
};

return defaultProcessor;
};
});
Loading