2

I'm new to Craft Commerce.

I wish to add around 10 price tiers to each product. Users are in groups and the group determines which price tier they pay. All the data is to be imported (and kept up to date) via API from an inventory management system. There are around 5000 products.

Sales and Discounts do not seem to be a good option as these are applied to whole groups of products whereas in my case each product has different pricing at each tier - there is no standard formula.

Another SE question, Multiple Prices based on User in Craft Commerce, uses variants. Is this the best way to go? For me the only difference is price so I feel it is not really a variant and this is a rather cluttered approach, especially as for each variant I will have to repeat a number of other fields. (And I might want to be able to use variants for the real variants rather than have the real variants as separate products to avoid a variants-squared situation).

So, I'm looking for advice on overall direction. It will be Craft 3/Commerce 2. TIA.

UPDATE: I was able to import the price tiers into custom fields on each product, and then on the product page display the correct price based on the user category selecting the right price tier. And then use this in a hidden field - I had to use options because I couldn't get it to work otherwise - not sure what I was doing wrong:

<input type="hidden" name="options[customPrice]" value="{{price}}">

Then (not knowing much anything about OOP PHP, but being a good scrounger who can copy and paste) I was able to modify the line item in the checkout page like so in Plugin class:

public function init() {
  Event::on(LineItems::class, LineItems::EVENT_POPULATE_LINE_ITEM, function(LineItemEvent $e) {
    $lineItem = $e->lineItem;
    if(isset($lineItem->options['customPrice'])){
        $lineItem->price =  $lineItem->options['customPrice']; 
    }
});
}

It seems to work, but who knows what sensibility boundaries I have crossed. The OOP side of things may as well be Greek to me.

  • P.S. I'm not yet confident/competent enough to write a plugin or module - but if that is the way I need to go, I'll just have to learn :) – Jack McKenzie Jan 11 at 1:47
  • Writing a simple plugin/module would be the way to go. I will make an answer with an example plugin soon. – Luke Holder Jan 11 at 8:00
  • Thanks @LukeHolder - I had a go in the UPDATE above, but it might be obvious I am stabbing in the dark – Jack McKenzie Jan 14 at 23:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.