Not seeing cart_id from within v:store:cart:items
  • When iterating over cart contents, I would like to keep a reference to the item id within the cart so a user can remove/update the item via my PHP webservice. Only problem is I'm not able to extract the 'cart_id' attribute within that context (it isn't dumped to the markup).

    Am I doing something wrong? I've tried both %v:php and v= (using HAML below)

    %v:store:cart:items
    %v:php
    return $context['cart_id'];
    <v=cart_id>



    Thanks!

  • 2 Answers sorted by
  • Can you try $id in PHP or in VaeML? If that works, I'll update the docs. This may just be a docs error.

  • $id returns what appears to be the actual id of the product, whereas $cart_id is the key I'm using to iterate over the result from vae_store_cart_items(), so it's not on the same level as the item entity.

    I did a test where I remapped the cart_id into a helper array (in __vae.php) with each product id as the key, which is then looked up when generating the markup, a-la:


    // in __vae.php
    $cart_ids = array();
    function cartContents() {
    global $cart_ids;
    $items = vae_store_cart_items();
    foreach ($items as $cart_id => $item) {
    $cart_ids[(string)$item['id']] = $cart_id;
    }
    return $items;
    }
    cartContents();




    // in markup
    .icon.close{"data-cart-id" => "<v? return $cart_ids[$context['id']];?>"}




    This is less than ideal for obvious obfuscation reasons. Also, is it possible have vae_store_remove_from_cart() return true OR false depending on what happens, instead of always true? Thanks a bunch,

    D

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion