Shop module have some basic elements
IMPORTANT: After installation you have no Orders, Items, Categories, Attributes, Shipping types or Order statuses. You have to create them, preferably starting from the end of list moving to the beginning because items at the beginning of the list depends on items at the end.
There are no payment types except Cash out of the box, so Cash assumed by default. However, new payment types will appear in interface as soon as third party module that implements this functionality will be installed (there can be multiple modules for different payment types)
This section will describe how developer can extend Shop module to make it unique and implement necessary functionality that is not available out of the box.
All user-side elements are WebComponents, Polymer elements. This means that you can extend elements using patched Polymer that comes with CleverStyle CMS easily:
<polymer-element name="cs-shop-category" extends="cs-shop-category">
<template>
//Whatever here
</template>
<script>
// Whatever here
</script>
</polymer-element>
There are 2 APIs: one for administration, another for user-side. Usually you'll need user-side API, which is simple and will give you all information you may see on user-side pages and even more.
API is especially useful for customizing appearance, because sometimes you may need more that actually present in HTML markup, so you can easily load it on demand.
Possible API calls for user-side:
[ 'items' => $items, // Array of array elements [id => item_id, units => units, price => total_price] 'shipping' => $shipping // Array in form [type => shipping_type_id, price => shipping_type_price] ]
{ "price_formatting" : "$%s USD", "items_per_page" : 20, "items_per_page_admin" : 50, "automatically_reduce_in_stock_value" : 1, "default_order_status" : 2, "default_paid_order_status" : 3, "allow_guests_orders" : 1 }
{"id" : "1", "type" : "5", "title" : "Title", "title_internal" : "Internal title", "value" : "" }
[ { "id" : "1", "type" : "5", "title" : "Title", "title_internal" : "Internal title", "value" : "" }, { "id" : "3", "type" : "1", "title" : "Int set", "title_internal" : "Int set", "value" : [ "1", "2", "3", "4" ] } ]
{ "1" : "Integer set", "2" : "Fractional set", "3" : "Integer range", "4" : "Fractional range", "5" : "String", "6" : "String set", "7" : "Text", "8" : "Yes\/no switch", "9" : "Color set" }
[ { "id" : "1", "parent" : "0", "title" : "First category", "description" : "Long category description", "title_attribute" : "2", "description_attribute" : "6", "image" : "", "visible" : "1", "attributes" : [ "2", "6" ] }, { "id" : "2", "parent" : "1", "title" : "Second category (nested)", "description" : "Long description", "title_attribute" : "2", "description_attribute" : "6", "image" : "", "visible" : "1", "attributes" : [ "2", "3", "6" ] }, { "id" : "3", "parent" : "1", "title" : "Third category (nested)", "description" : "Long description", "title_attribute" : "1", "description_attribute" : "0", "image" : "", "visible" : "1", "attributes" : [] }, { "id" : "6", "parent" : "0", "title" : "Category with image", "description" : "This is the first category with image", "title_attribute" : "1", "description_attribute" : "0", "image" : "http:\/\/cscms.org\/storage\/public\/Plupload\/2014-12-15\/20\/2_3905548f2ac9b2d5f.jpg", "visible" : "1", "attributes" : [ "1", "2", "3", "6" ] } ]
[ { "id" : "1", "parent" : "0", "title" : "First category", "description" : "Long category description", "title_attribute" : "2", "description_attribute" : "6", "image" : "", "visible" : "1", "attributes" : [ "2", "6" ] }, { "id" : "6", "parent" : "0", "title" : "Category with image", "description" : "This is the first category with image", "title_attribute" : "1", "description_attribute" : "0", "image" : "http:\/\/cscms.org\/storage\/public\/Plupload\/2014-12-15\/20\/2_3905548f2ac9b2d5f.jpg", "visible" : "1", "attributes" : [ "1", "2", "3", "6" ] } ]
{ "id" : "6", "parent" : "0", "title" : "Category with image", "description" : "This is the first category with image", "title_attribute" : "1", "description_attribute" : "0", "image" : "http:\/\/cscms.org\/storage\/public\/Plupload\/2014-12-15\/20\/2_3905548f2ac9b2d5f.jpg", "visible" : "1", "attributes" : [ "1", "2", "3", "6" ] }
[ { "id" : "1", "parent" : "0", "title" : "First category", "description" : "Long category description", "title_attribute" : "2", "description_attribute" : "6", "image" : "", "visible" : "1", "attributes" : [ "2", "6" ] }, { "id" : "6", "parent" : "0", "title" : "Category with image", "description" : "This is the first category with image", "title_attribute" : "1", "description_attribute" : "0", "image" : "http:\/\/cscms.org\/storage\/public\/Plupload\/2014-12-15\/20\/2_3905548f2ac9b2d5f.jpg", "visible" : "1", "attributes" : [ "1", "2", "3", "6" ] } ]
[ { "id" : "1", "user" : "2", "date" : "1420929764", "shipping_type" : "0", "shipping_cost" : "0", "shipping_username" : "Назар", "shipping_phone" : "+380000000000", "shipping_address" : "Kyiv\nUkraine", "payment_method" : "shop:test", "paid" : "0", "status" : "2", "comment" : "Long comment from user\nin two lines", "for_payment" : 20 }, { "id" : "1", "user" : "2", "date" : "1419939973", "shipping_type" : "2", "shipping_cost" : "5", "shipping_username" : "Nazar", "shipping_phone" : "+380000000000", "shipping_address" : "Kyiv\nUkraine", "payment_method" : "shop:cash", "paid" : "1", "status" : "3", "comment" : "Comment for paid order", "for_payment" : 25 } ]
{ "shipping_type" : "1", "shipping_username" : "Назар", "shipping_phone" : "+380000000000", "shipping_address" : "Kyiv\nUkraine", "payment_method" : "shop:cash", "comment" : "Huge comment)", "items" : { "2" : 1, "3" : 5 } }
"http:\/\/cscms.org\/api\/Shop\/orders\/20"Status code: 201 Created
{ "id" : "20", "user" : "2", "date" : "1422918620", "shipping_type" : "1", "shipping_cost" : "0", "shipping_username" : "Назар", "shipping_phone" : "+380000000000", "shipping_address" : "Kyiv\nUkraine", "payment_method" : "shop:cash", "paid" : "0", "status" : "2", "comment" : "Huge comment)", "for_payment" : 0 }
[ { "id" : "20", "item" : "2", "units" : "1", "price" : "30", "unit_price" : "30" }, { "id" : "20", "item" : "3", "units" : "5", "price" : "10", "unit_price" : "2" } ]
[ { "id" : "20", "date" : "1422918620", "status" : "2", "comment" : "Order created" } ]
{ "shop:cash" : { "title" : "Cash", "description" : "" } }
Backend events greatly extends customizations and functionality - they allow to apply discounts, special offers, limit access to specific items for specific users and so on.
Shop module dispatches such own events:
Details about how to use them you can find at their declaration in source code, it is pretty simple.
Also Shop module dispatches some other events that might be useful for implementing additional payment methods and payment processing:
[ 'methods' => &$payment_methods, 'currency' => {currency} ]
[ 'amount' => {amount}, 'currency' => {currency}, 'user' => {user_id}, 'payment_method' => {payment_method}, 'module' => Shop, 'purpose' => orders/{order_id}, 'description' => {description} ]
Shop module is subscribed to events that corresponds to payments processing, which can be done by third-party modules:
[ 'module' => Shop, 'purpose' => orders/{order_id}, 'callback' => &$callback ]
[ 'module' => Shop, 'purpose' => orders/{order_id}, 'callback' => &$callback ]