• Resolved Tim

    (@timstl)


    Hello,

    I’m trying to store a custom cart item value (unit of measure). The visitor selects from a custom dropdown while adding to cart. That value is then carried through the checkout process.

    This is the method I am currently using:

    function _wpsc_add_to_cart_do_uom($product_id, $parameters, $this, $new_cart_item  )
    {
    	if(isset($_REQUEST['wpsc_quantity_um']) && $_REQUEST['wpsc_quantity_um'] != '')
    	{
    		$new_cart_item->update_meta('ordered_quantity_uom', esc_html(trim($_REQUEST['wpsc_quantity_um'])));
    	}
    }
    add_action('wpsc_set_cart_item', '_wpsc_add_to_cart_do_uom', 1, 4);

    It works as expected with one exception: If the user adds to cart and then logs in to a WP account, the custom meta value is lost. The cart item itself carries over to the user’s cart but without the meta value.

    Is $new_cart_item->update_meta the right approach or is there a better way to do this? Do I maybe have to tie into another filter to transfer the item meta values over to the user’s cart at login? I’ve been digging through the core files trying to come up with something, but no luck yet.

    Thanks,

    Tim

    https://www.ads-software.com/plugins/wp-e-commerce/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi Tim.

    Just took a look at the WPeC code. It looks like the _wpsc_merge_cart function may have a deficiency. When a user with a non-empty cart logs in the intent is for the non-logged in user’s cart to be merged into the logged in user cart. I can see the code that copies the cart items themselves, but no code to copy any meta data associated with the copied cart items.

    I will see if I can put together a little patch and add it to the 3.8.14.2 branch.

    Jeff

    Thread Starter Tim

    (@timstl)

    That would be great. I kind of figured it had something to do with _wpsc_merge_cart, but I’m not quite familiar enough with how it’s all supposed to work.

    Thanks for the help.

    Tim

    Tim,

    Looks like the change might be a very simple one. ANy chance you can test it?

    In customer-private.php, around line 341, in the merge cart function, add the line that starts with ‘item_meta’. The code should end up looking like this:

    // add each item to the new cart
    	foreach ( $items as $item ) {
    		$new_cart->set_item(
    				$item->product_id, array(
    						'quantity'         => $item->quantity,
    						'variation_values' => $item->variation_values,
    						'custom_message'   => $item->custom_message,
    						'provided_price'   => $item->provided_price,
    						'time_requested'   => $item->time_requested,
    						'custom_file'      => $item->custom_file,
    						'is_customisable'  => $item->is_customisable,
    						'meta'             => $item->meta,
    						'item_meta'        => $item->get_meta(),
    				)
    		);
    	}

    Let me know if it works for you. I am also trying to test it.

    Jeff

    Thread Starter Tim

    (@timstl)

    Worked for me. I tested several scenarios, didn’t find any problems. Thanks!

    Thanks for finding the bug, i’ll work with Justin and get it into the point release

    Tim,

    For your reference the change is in Pull Request #1467

    Jeff

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Storing custom cart item meta’ is closed to new replies.