/** * Ensure the proper buyable will be returned for a given buyable… * This is being used to ensure a product with variations cannot be added to the cart… * a Variation has to be added instead! * @param Buyable $buyable * @return Buyable */ public function getCorrectBuyable(Buyable $buyable) { if ($buyable instanceof Product && $buyable->hasExtension('ProductVariationsExtension') && $buyable->Variations()->count() > 0) { foreach ($buyable->Variations() as $variation) { if ($variation->canPurchase()) { return $variation; } } } return $buyable; }