What's your biggest current challenge? Have your say in Community Polls along the right column.

Re: Theme.js - Product:added event

How to trigger product:added event on Avone theme for Estimated Delivery Date?

Linda_Ladley
Excursionist
25 1 2

We're using the Avone theme alongside the Order Deadline App to provide our customers with Estimated Delivery.

 

In previous themes when a customer added a product to the cart the Estimated Delivery Date appeared as a line item in the cart and also captured on the order details in admin as it was triggered by the product:added event. 

 

Unfortunately the Avone theme uses the product event but not product:added and whilst I've asked them to add this into the theme.js file they've stated we need to add it.

 

Can anyone share with me what the code should be please so that I can add it into the file.

Thanks

Lind

Replies 3 (3)

lewisCH
Visitor
2 0 0

Try  to add the following code to the theme.js file:

JavaScript
// Add the Estimated Delivery Date event to the Avone theme

shopify.on('product:added', function(product) {
  // Get the estimated delivery date
  var estimatedDeliveryDate = shopify.orderDeadline.getEstimatedDeliveryDate(product);

  // Add the estimated delivery date to the cart line item
  var cartLineItem = document.querySelector('[data-product-id="' + product.id + '"]');
  cartLineItem.setAttribute('data-estimated-delivery-date', estimatedDeliveryDate);

  // Add the estimated delivery date to the order details in admin
  var orderDetailsForm = document.querySelector('#order-details-form');
  var estimatedDeliveryDateField = orderDetailsForm.querySelector('[name="estimated_delivery_date"]');
  estimatedDeliveryDateField.value = estimatedDeliveryDate;
});
Linda_Ladley
Excursionist
25 1 2

Thank you, I've added the code but what I've found is:

The Line Item doesn't appear unless the cart is refreshed. 
We also find that the Cart Drawer disables as a result of adding the code.

Arsalan01
Shopify Partner
1 0 0

can u please tell me how to refresh cart in avone theme, cart:refresh is not working.