Removing item from cart using Ajax

  • Posts: 292
  • Thank you received: 5
  • Hikashop Business
4 years 4 months ago #321920

-- HikaShop version -- : 4.2.3
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.3.19

I have the following item line in the cart.
To change the quantity want the user to click the refresh icon.
Want that to remove the item from the cart and return user to the product page so they can re-enter quantity.



There might be other better / simpler ways of achieving the same result.
If I allow the user to update the quantity field it does not update the weight.
User orders 1.5KG - cart shows quantity of 1 and weight (custom field) of 1.5.
If user changes quantity to 2 - the shop staff think they want 2 packs of 1.5kg not 1 pack of 2kg!!

The code I have for this in show_block_cart.php is:
<?php>
echo $item->lengthm . ' kg'; // lengthm is a custom item field - naming convention??...
$url = hikashop_contentLink('product&task=show&cid=' . $product->product_id . '&name=' . $product->alias . $url_itemid, $product);
$delete_url = hikashop_completeLink('/product&task=updatecart&product_id='.$product->product_id.'&quantity=0');
?>
<input id="hikashop_checkout_quantity_<?php echo $product->cart_product_id;?>"
            type="hidden" name="checkout[cart][item][<?php echo $product->cart_product_id;?>]"
           data-hk-qty-old="<?php echo $product->cart_product_quantity; ?>"
            value="<?php echo $product->cart_product_quantity; ?>"/>
<div class="hikashop_cart_product_quantity_refresh">
    <a class="hikashop_no_print"
          data-cart-type="<?php echo $this->escape($cart->cart_type); ?>"
          data-cart-id="<?php echo (int)$cart->cart_id; ?>"
          data-cart-product-id="<?php echo (int)$product->cart_product_id; ?>"
           href="<?php echo $delete_url; ?>"
           onclick="window.hikashop.deleteFromCart(this, null, false); alert('Go to product URL'); return false;">
           <i class="fa fa-sync"></i>
    </a>
</div>

The item does not get deleted from the cart and the xhr.responseText response is Please enter a value for the field.
See line 1280 of file hikashop.js.

The Ajax URL is:
/checkout/product/updatecart/quantity-0/cid-1461.html?tmpl=raw
The Ajax post parameters are:
cart_type=cart&cart_id92300&cart_product_id=150694

Suggestions?

One other issue will need to address is that the Ajax call needs to be synchronous.
Otherwise replacing the alert with window.location = "..."; won't work!

Attachments:
Last edit: 4 years 4 months ago by brainforge.

Please Log in or Create an account to join the conversation.

  • Posts: 292
  • Thank you received: 5
  • Hikashop Business
4 years 4 months ago #321924

Does not solve the problem of how to allow the user to update the item value, but this screenshot illustrates 3 different ways in which the quantity / weight information could be displayed. Displaying 2 of 1.5kg looks like a quick fix for now - leaving out the refresh icon, leaving in the delete icon.

Attachments:
Last edit: 4 years 4 months ago by brainforge.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
4 years 4 months ago #321937

Hi,

How about updating to HikaShop 4.3.0 ?
With the 4.3.0 release, we introduced the cart product edition interface.
You'll get an edit icon next to the name of products with custom item fields / characteristics in the cart so that the customer can change the value of the custom fields / characteristics of the product in the cart.

Please Log in or Create an account to join the conversation.

  • Posts: 292
  • Thank you received: 5
  • Hikashop Business
4 years 4 months ago #321956

Thanks - perfect!

Custom field config - Cart Product Edition option (typing - should it be editor?)



After customising the views we get ...


Attachments:

Please Log in or Create an account to join the conversation.

Time to create page: 0.092 seconds
Powered by Kunena Forum