AddToCartTrait uses trait:short
"Add to cart" from the catalog (list and detail).
The cart itself reserves nothing; stock is contested only when the order is submitted. The
signal does verify that the set may be ordered at all
(ProductSet::isOrderable()): templates do not
render the call to action for unorderable goods and this check is the server counterpart. A hidden
button is no gate; anyone can type ?do=addToCart&setId=... by hand.
Two paths, one behavior:
- AJAX (the link has
class="ajax", naja intercepts it): the customer stays on the page and only the header cart badge (CartWidget, snippetcartWidget) and a flash message (turned into a toast by the theme,flashMessages.js) are redrawn. No custom JS event is needed; snippet invalidation is native to Nette/naja. - without JS: PRG, the item is added and the request redirects to the cart (a refresh then adds no further piece).
Table of Contents
Constants
- SETTINGS_MODULE_ESHOP : mixed = 4
- Settings module (`cms_system_settings`): e-shop = 4.
Methods
- handleAddToCart() : void
- allowsOutOfStockOrder() : bool
- Returns `4/order.outOfStock.allowed`: whether the customer may order goods that are not in stock.
- guardCatalogOnly() : void
- isCatalogOnly() : bool
- isSetOrderable() : bool
- Returns whether the set may be ordered.
Constants
SETTINGS_MODULE_ESHOP
Settings module (`cms_system_settings`): e-shop = 4.
private
mixed
SETTINGS_MODULE_ESHOP
= 4
Methods
handleAddToCart()
public
handleAddToCart(int $setId[, int $quantity = 1 ]) : void
Parameters
- $setId : int
- $quantity : int = 1
allowsOutOfStockOrder()
Returns `4/order.outOfStock.allowed`: whether the customer may order goods that are not in stock.
protected
allowsOutOfStockOrder() : bool
Off (default): "Add to cart" is not offered for sold-out goods and checkout rejects it
(strict reservation). On: pre-selling; the reservation may then end with the state none
(nothing covered), see ReservationService.
A missing key in the DB means off: silently allowing oversell just because a settings migration was not run would be the worst possible failure.
Return values
boolguardCatalogOnly()
protected
guardCatalogOnly() : void
isCatalogOnly()
protected
isCatalogOnly() : bool
Return values
boolisSetOrderable()
Returns whether the set may be ordered.
private
isSetOrderable(int $setId) : bool
Availability is read from the same source as the list
(ProductSetManager::fetchAvailability()), so
the gate cannot diverge from what the customer saw in the catalog. A set unknown to
availability (deleted, nonexistent) behaves as availableSets = null, i.e. unorderable.
Parameters
- $setId : int