Hot answers tagged

3

Your product element criteria is using a condition param: hasVariants, but it should be hasVariant as per the docs: https://craftcommerce.com/docs/craft-commerce-products#hasvariant That correctly only returns products (where a variant that belongs to that product) is in stock.


2

The next time the cart 're-calculates' - so really any process on the cart such as updating it etc, the out of stock product will be detected and removed from the cart. If somehow they get straight to the attempt order completion stage, then I am pretty sure an error is raised (& returned in flash) and the order won't complete.


1

Commerce (as at V2) has basic stock handling that will do exactly what you mention - for each product you can set a stock level (alternatively, you can set it to unlimited stock if you wish). When orders are completed stock is debited by the amount sold (note stock is not debited when items are added to carts - which is good, because it means you don't have ...


1

You can use the beforeGenerateLicenseKey event and query for a custom key in your custom table and set the license key Event::on(License::class, License::EVENT_GENERATE_LICENSE_KEY, function(GenerateKeyEvent $e) { $licenseKey = (new Query()) ->select(['mykey']) ->from('{{%mytable}}') ...


1

I haven't done this, but as a rule I try an mimic what Commerce actually does itself. In this area I would be inclined to follow the code Commerce uses in it's own completed order handling, found in public function orderCompleteHandler in commerce/services/Commerce_VariantsService.php around line 290: $purchasable = $lineItem->getPurchasable(); ...


Only top voted, non community-wiki answers of a minimum length are eligible