• Resolved eclair4151

    (@eclair4151)


    Right now, if you have a variable product with one of the attributes as ‘any’ you are unable to add this item using a cart link campaign, because the attributes need to be specified when it is added to the cart.

    Inside AddProductsAction, the 4th variable is empty.

    $this->cart->add_to_cart( $product_id, $product->get_quantity(), $variation_id, [], $cart_item_data );

    ideally inside the admin panel, when adding a product to a cart link campaign, there would be a checkbox where you can check, and then add a list of custom attributes, and their values, which would then be passed in to this function, so the correct item can be added to the cart.

    as of now, if you have a variation product with an ‘any’ attribute, you simply cannot use this plug-in for that product.

    Any help is greatly appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor lusp

    (@lusp)

    Hi @eclair4151,

    Could you please provide us with some more detailed information on how to reproduce this issue step by step?

    We’d like to take a closer look at the situation and check what can be done on this matter.

    Kind regards,
    Luke

    Thread Starter eclair4151

    (@eclair4151)

    Hey, thanks for your reply, yes here are more details, and an example.

    First, set up a new variable product with an attribute.

    Then set up a variation, with the attribute specified, and left as “Any”

    You will see, when using the item regularly, you need to specify the color while checking out, which is then added to the item meta data in the order

    But now, if you add this new test item to a cart link campaign, there is no way to specify additional meta data for the items

    So when you try to load the campaign, you are just met with an error that the attribute is required.

    Ideally, inside the admin of the cart link campaign, when you add a product there would be a spot where you can specify multiple extra item meta data entries, all of which will be passed as a dict in to

    $this->cart->add_to_cart( $product_id, $product->get_quantity(), $variation_id, [META DATA DICT HERE], $cart_item_data );

    Inside AddProductAction

    Thanks again, let me know if you have any further questions.

    Thread Starter eclair4151

    (@eclair4151)

    You can see an example of this on my shop here:

    Here is the variable product:

    https://wolfpacktackle.com/product/test-product/

    And here is a cart link campaign trying to add it to the cart

    https://wolfpacktackle.com/testcampaign/

    Thread Starter eclair4151

    (@eclair4151)

    Another note, when calling

    $this->cart->add_to_cart( $product_id, $product->get_quantity(), $variation_id, [META DATA DICT HERE], $cart_item_data );

    In my testing you need to prepend the meta data you want with attribute_ ie this code is what correctly adds the item to my cart with the red color selected:

    $this->cart->add_to_cart( $product_id, $product->get_quantity(), $variation_id, ["attribute_pa_color" => "red"], $cart_item_data );

    Plugin Author Sebastian Pisula

    (@sebastianpisula)

    Hi @eclair4151 ,

    thank you very much for describing in detail how to reproduce the problem – it’s very helpful and we understood what’s going on.

    It seems a bit complex because we would have to change the campaign management UI in our plugin, it takes some time to think about how to do it right with backward compatibility and to make it a good performance solution.

    So my question is: will it help you as MVP if we add a filter for [META DATA DICT HERE]? It will be possible to temporarily work around this programmatically without losing the ability to perform updates.

    Something like:

    
    $variation = apply_filters( 'cart_link/add_to_cart/variation', [], $product, $this->campaign, $product_id, $variation_id );
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Add way to add custom attributes to variable products’ is closed to new replies.