How to modify post checkout script for pickup point selection?

How to modify post checkout script for pickup point selection?

PetrMachacek
Explorer
71 1 18

Dear Expers,

I would like to ask for help as my skills are not enough to crack this 🙂

 

I have in checkout additional scripts code for pickup point selection.

Now I would need after this script call following address:

 

https://www.heureka.cz/direct/dotaznik/objednavka.php?id=ed41fb4d2c6c09d7a27e25f6f227ba01&email=xxxx@xxxx.xx&itemId[]=yyyyy&orderid=zzzzz

 

where xxxx should be customer email

yyyy should be product SKU

zzzz should be order number

 

Would really help if someone could guide me.

I'm adding also current script:

 

{%- comment -%}
Zasilkovna start
{%- endcomment -%}
{% assign zasilkovna_shipping_method_name = "zásilkovna" %}
{% assign zasilkovna_api_key = "549d1fdde5bd54be" %}

{% assign zasilkovna_selected_heading = "Výdejní místo vybráno" %}
{% assign zasilkovna_selected_text = "Zásilku pošleme na výdejní místo:" %}

{% assign zasilkovna_not_selected_heading = "Kam to bude?" %}
{% assign zasilkovna_not_selected_text = "Vyber výdejní místo Zásilkovny." %}
{%- comment -%}
Zasilkovna config end - please don't change anything after this
{%- endcomment -%}
{% assign zasilkovna_method = false %}
{% for shipping_method in order.shipping_methods %}
{% assign shipping_method_name = shipping_method.title|downcase %}
{% assign downcase_zasilkovna_shipping_method_name = zasilkovna_shipping_method_name|downcase %}
{% if shipping_method_name contains downcase_zasilkovna_shipping_method_name %}
{% assign zasilkovna_method = true %}
{% endif %}
{% endfor %}

{% for attr in order.attributes %}
{% assign attr_name = attr|first %}
{% if attr_name == "PickupPointName" %}
{% assign zasilkovna_name = attr|last %}
{% assign pickup_point = zasilkovna_name %}
{% endif %}
{% endfor %}

{%if zasilkovna_method %}
{% assign order_hmac = order.id | hmac_sha256:"08ad7cda14b6de7cffa662ffcdf9ddc8b137a95a5991fb7819376cb84cf97c61" %}

<script src="https://widget.packeta.com/www/js/library.js"></script>

<script type="text/javascript">
function packetaCallback(extendedPoint) {
if (extendedPoint == null) {
return;
}

fetch("https://shopify-zasilkovna.herokuapp.com/api/pickup-point-selected", {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify({
pickup_point_id: extendedPoint.id,
pickup_point_name: extendedPoint.name,
order_id: {{ order.id }},
order_hmac: "{{ order_hmac }}",
myshopify_domain: Shopify.shop,
})
}).then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
}).catch(error => {
alert('There has been a problem when saving pickup point selection. Please try again or contact us.');
window.location.reload();
});

document.getElementById("zasilkovna_heading").innerText = "{{ zasilkovna_selected_heading }}";
document.getElementById("zasilkovna_text").innerText = "{{ zasilkovna_selected_text }} " + extendedPoint.name;
}

function openPickupPointSelection() {
Packeta.Widget.pick('{{ zasilkovna_api_key }}', packetaCallback);
return false;
}

{%- if pickup_point -%}
Shopify.Checkout.OrderStatus.addContentBox(
'<h2>{{ zasilkovna_selected_heading }}</h2>',
'<p>{{ zasilkovna_selected_text }} {{pickup_point}}.</p>');
{%- else -%}
Shopify.Checkout.OrderStatus.addContentBox(
'<h2 id="zasilkovna_heading">{{ zasilkovna_not_selected_heading }}</h2>',
'<p id="zasilkovna_text"><a href="#" onclick="openPickupPointSelection()">{{ zasilkovna_not_selected_text }}</a></p>');
openPickupPointSelection();
{%- endif -%}
</script>

{%endif%}

{%- comment -%}
Zasilkovna end
{%- endcomment -%}

 

 

Replies 2 (2)

jakubhalik
Shopify Partner
29 1 1

Hi friend, our agency developed a zásilkovna app so you can sure try emailing our support (apps@soundsgood.agency) and we could sure make a deal with you regarding doing some customization of the app 🙂

If you could describe some more what exactly you want to do with the "

https://www.heureka.cz/direct/dotaznik/objednavka.php?id=ed41fb4d2c6c09d7a27e25f6f227ba01&email=xxxx@xxxx.xx&itemId[]=yyyyy&orderid=zzzzz" i might be able to give you an advice.

But besides all that I also took a look at your code and you have a lot of things there with which that code can no longer function.

Shopify updated deleted all of the "order." commands.

So you have to change your "order.shipping_methods" to "checkout.shipping_methods", "order.attributes" to "checkout.attributes" and "order.id" to "checkout.order_id". 🙂

Packeta | Zasilkovna: http://apps.shopify.com/packeta-zasilkovna-alpha
AMA: apps@soundsgood.agency
Certified Shopify Experts: https://experts.shopify.com/soundsgood

edgar007
Shopify Partner
8 1 2

While not a solution, I wanted to share our experience that having pickup point selection after checkout led to:

  • Many missed sales, as customers were hesitant to complete payment because they were unsure about selecting a pickup location
  • An increase in after-sales support, with customers choosing parcel locker deliveries for items too large or heavy to fit in the locker compartments, or just leaving the "thank you" page before selecting a location

Therefore, if you can offer point selection at the checkout step (before the order confirmation page), it should improve your conversion rate.

Edgar from ShipWisely — Native parcel locker delivery integration with Omniva, Venipak, Unisend, InPost, DPD, and more across the EU & UK
Learn more: https://apps.shopify.com/shipwisely-pickup-points