hello! I have a question regarding solidus interna...
# support
m
hello! I have a question regarding solidus internals and best way to achieve what i have on my mind. Let's say i have a shop in which you can buy a dog leash. Leash have different variants based on size and thickness but - user has an additional set of checkboxes when he wants to add a leash to his cart - he can select if he wants to make leash 2m longer for 5$ or if he wants an extra safe fastener for +4$. These adjustments applies to every possible variant combination so i can't really use variants for that as i would end up with 50 variant combinations per each product. I managed to implement a backend/admin logic for that (defining these adjustments, their prices etc) but i have no idea which internal tool of solidus should i use to actually adjust the line item price. Should i implement custom line item adjustment class? Or shuld i overwrite a calculator? What do you think? ๐Ÿ™‚ Thanks in advance for any clues !
c
Hey there ๐Ÿ‘‹ This is a great question and I think you have some options in how you go about implementing this. One option I can think of is to model these add-onโ€™s as an association or metadata on your line item records and update the price on the line item to include them.
m
that's exactly how i did that ๐Ÿ™‚
๐Ÿ‘๐Ÿผ 1
the only missing part is adjusting the actual line item price
c
for that there is an extension point in Solidus called pricing options
m
"adjusting line item price" sounds like a great match for "line item adjustments" haha but i always asssociated line item adjustments with promotions etc
oh, let me check
c
You can implement a custom pricing options class which can look at the line item โ€œadd-onsโ€ and add their cost to the price - https://github.com/solidusio/solidus/blob/39e8e46e05bdefe31a5933066ad316382bff275b/core/lib/spree/app_configuration.rb#L303-L306
m
oh wow this looks exactly like what i am looking for
to be honest the shop i am working with is still on spree and i was planning to migrate it to Solidus and i would need to implement that in spree first to showcase what's possible to my customer. I guess pricing options is something implemented strictly in solidus right?
c
Yeah, I am not too sure if itโ€™s in Spree, itโ€™s been a long time since Iโ€™ve looked at that codebase ๐Ÿ˜„
I know itโ€™s been in Solidus for a while now
m
ok, thank you for your feedback anyway ๐Ÿ™‚ Will definitely use that knowledge in the future
๐Ÿ‘๐Ÿผ 1
c
I think you are on the right track though, you could probably create an override for the order contents or trace where the line item price is set in Spree and add your custom logic there
m
yeah, sounds good. How about using custom line item adjustment class? Is that a good approach as well?
c
Adjustments are mostly used for taxes and promotions, so although possible, it may get tricky when it comes to calculating promotions on the order
m
that's what i thought
c
I would probably not worry about creating adjustments and just model this separate from that and just modify the line item price based on the add-ons, that way taxes and promotions will just work
You could try creating a completely different type of adjustment, but you may find you have to modify a lot of core code to handle those
m
that's precisely what i wanted to do to keep things simple and to not modify core behaviours too much ๐Ÿ™‚
๐Ÿ’ฏ 1
finding place in the code where such modification belongs is the hardest part but it's not Solidus anyway so i will not waste any more of your time and will move that to spree slack ๐Ÿ˜„ Thank you for all the ideas Chris! Much appreciated
c
you are welcome! good luck!
h
Maybe you can use this gem? it adds variants on the fly with surcharges when the item is put in cart. https://github.com/hefan/solidus_dynamic_variants if you have an questions regarding the gem i am happy to help.