In the context of e-commerce, items are products that that can be added to a shopping cart and be acquired by the customer. They typically have properties, such as a price, availability, etc.
The plugin ffItem offers typical properties and methods for e-commerce items.
Usage
It's good practice to create a prefixed class for your project
file classes/nsItem.php
class nsItem extends ffItem{
// project-specific overwrites and functionality
}
You can turn any ffNode into an item by instantiating it with the current node:
To make use of item variants, first the possible attributes need to be defined.
The attribute definition of variants is located in the metadata of one of the item's ancestor nodes. Based on the logic of the store, you can choose, where the definition is located.
In our shirt example, they could be located in the items/shirts node. This will allow all nodes below shirts to access the defined variant attributes.
It could also be located in the items node. This will allow all nodes below items to access the defined variant attributes.
Build a ffItem object from any node within the t-shirt node to access the attributes and their values.
Example: current path points to items,shirts,t-shirt,Size-S-Color-Green:
File presenter/item.php
$item = ffItem::getInstance($this->me);
// returns nsItem object
// N.B. this will return a nsItem only if you have created a nsItem class)
$item->getAttribute('Color');
// returns "Green"
$item->getAttribute('Availability');
// returns "87"
$item->getAttribute('Price');
// returns "10"
// N.B. This value is inherited from the base item
$item->hasVariants();
// returns true
$item->isVariantsBase();
// returns false
$item->getVariantsBase();
// returns the ffNode instance of items,shirts,t-shirt
$item->getMyVariantData();
// returns ["Size" => "S", "Color" => "Green"]
$item->getCustomAttributes() // method will probably be renamed
// returns ["Size", "Color"]
$item->getVariantAttributeSets()
// returns ["Size" => ["S", "M", "L", "XL"], "Color" => ["Red", "Green", "Blue"]]
$item->getNode();
// returns the ffNode of items,shirts,t-shirt,Size-S-Color-Green
Attribute inheritance
The inheritance mechanism of ffItem will make sure, that variants will always fall back to their base item's attributes if they are not explicitly defined in the variant node.
Any child node of items,shirts,t-shirt will return 10 for the price attribute by default.
Building a variant selector
Prices
ffItem provides out-of-the-box logic for various common price related topics, such as:
item price
multiple equal item price (if multiples of the same item are acquired)