These are chat archives for reactioncommerce/reaction

7th
Feb 2016
Aaron Judd
@aaronjudd
Feb 07 2016 00:53
@PaulSavignano to be clear, you are adding a client cart qty per variant input (vs an admin variant qty input which already exists). you would just use that Meteor.call('cart/addToCart’) on an template event (change of the new input) for the new template. :cold_sweat:
Paul Savignano
@PaulSavignano
Feb 07 2016 02:40
@aaronjudd Yes, client. Basically, like selecting each child variant and adding them to the cart I would like the add-to-cart click to loop through all the child variants and add them and their quantities to the cart. I was thinking of placing the Meteor.call('cart/addToCart') within a loop and iterating over it. Is this a good approach? How do I identify the child variants.lenght?
Paul Savignano
@PaulSavignano
Feb 07 2016 03:41
@aaronjudd My product includes quantities of child variants. Rather than have the user onfocus each child v to add it to the cart, I'd like to include quantity fields and add them all upon click of add-to-cart. I was thinking of extending my own productDetail and variantList templates. I could add a number input to the variantList.html button and then have the add-to-cart event loop over the child variants.lenght and add all the child vs and their quantities to the cart. What is the best practice to add this custom cart behavior?
newsiberian
@newsiberian
Feb 07 2016 05:14
@PaulSavignano, hello, it is not completely clear what kind of product you have. Could you provide small live example? Is it correct that you want behavior like:
user adds one item of child variant to cart, and system should automatically add one item of all this TopLevel variant child-variants to the cart? If you want something like this, I think, the more safety way to implement this is an async method calls loop, something like that.
Paul Savignano
@PaulSavignano
Feb 07 2016 14:56
@newsiberian Let's say I'm selling pizza's. Each pizza comes with 8 toppings out of 10 topping choices. A user may select any combination of toppings to achieve 8. When the user clicks add-to-cart all toppings should be added to the pizza order. I'll will have to address price as well because the total cost of the pizza is not affected by the number of toppings.
newsiberian
@newsiberian
Feb 07 2016 15:14

@PaulSavignano, ok, I see two ways: complex one, and the one you already know))
complex: you need to extend addToCart method to allow arrays of variants with arrays of their quantity. It could be some kind of object instead of array.
then it will be good to expand product variant schema to allow it to accept several variants at once.
and you'll need to extend UI to hold all selected variants somewhere before adding to cart.

And the way you know is the last part from previous + loop over addToCart method calls. This is from the first glance.

Paul Savignano
@PaulSavignano
Feb 07 2016 15:24
@newsiberian Thanks! I was hoping to not affect any of RC's packages so I was extending the productDetail and variantList templates and the productDetail.js for the events. I've placed these copies in the roots client directory. What would the loop I need look like? How do I identify the child variants.length?
Aesop7
@Aesop7
Feb 07 2016 15:33
Hi all, I'm getting .less errors with the new version. Do I need to include reaction-core-theme files in custom.reaction.import.less in my project? Thanks in advance!
newsiberian
@newsiberian
Feb 07 2016 15:47
@PaulSavignano, I think you need to run next iteration from within method callback of previous. For now you could get this child variants like this
Paul Savignano
@PaulSavignano
Feb 07 2016 16:23
@newsiberian So is the preferred way to handle the add-to-cart functionality through the addToCart method versus add-to-cart event?
newsiberian
@newsiberian
Feb 07 2016 16:50
I think yes, because if you just run a loop over child variants it will be too fast and it could lead to side effects. Maybe I'm wrong with that
Paul Savignano
@PaulSavignano
Feb 07 2016 16:57
Interesting. What is the best practice for extending a method? Would I make a copy of cart.js from reaction-core/server/methods and add it to the roots server directory? I know there is Template.myTemplate.replaces for extending templates. Is there a similar function for events and methods?
newsiberian
@newsiberian
Feb 07 2016 17:06
I think we have a misunderstanding. In a few last comments I was talking about loop over addToCart callbacks without any changes on server side.
Paul Savignano
@PaulSavignano
Feb 07 2016 17:11
Are you referring to Meteor.call("cart/addToCart" on line 159 of productDetail.js?
newsiberian
@newsiberian
Feb 07 2016 17:16
yes
Paul Savignano
@PaulSavignano
Feb 07 2016 17:35
@newsiberian Perfect, thanks for helping me out!
newsiberian
@newsiberian
Feb 07 2016 17:49
:+1:
Aesop7
@Aesop7
Feb 07 2016 18:47
Has anyone seen this error?
   reaction/packages/reaction-core-theme/theme/dashboard/packages/grid/package/package.less:4:11:
   variable @brand-success is undefined
   reaction/packages/reaction-core-theme/theme/layout/header/tags/tags.less:8:2: .margin-left
   is undefined
   reaction/packages/reaction-core-theme/theme/cart/checkout/checkout.less:2:2: .flex is
   undefined
   reaction/packages/reaction-core-theme/theme/dashboard/orders/orders.less:13:2:
   .btn-success is undefined
   reaction/packages/reaction-core-theme/theme/layout/header/header.less:11: .ltr is
   undefined
   reaction/packages/my-custom-theme-template/styles/base.less:10:2: .margin-left is
   undefined
   reaction/packages/reaction-core-theme/default/panels.less:4:4: .flex is undefined
ha, nevermind, figured it out!
Paul Savignano
@PaulSavignano
Feb 07 2016 22:49
@aaronjudd Well, you were right about the cold sweats :) I was able to get the loop working correctly however, have found the way it functions with the cart to be less than desirable. I believe I will need to modify the addToCart method. I don't want to break Reaction by modifying any of it's core code. How would I extend a custom method?
Paul Savignano
@PaulSavignano
Feb 07 2016 22:56
@newsiberian So it looks as though I will indeed need the complex option :) How can I extend a custom method?