Package: ecs.cart
ECS CARTThis is a package from the ecs suite, that provide a cart object for ecommerce
projects.In standart use it provide classical functionnalities:Add/delete product from cartPrice manipulation and amount (with vat)Weight amountReductions (in % or value)But this package also provide rules system that add the posibility to improve
his functionnalities (like connection with database, logistic function, …)Read docs/source/module/README.txt or inlinehttp://docs.emencia.net/ecs.cartEcs cart Changelog0.4 (January 13, 2008)fix small bugsimprove documentation (logo + spec doc)O.3 (December 15, 2008)fix docstestfix bug in rules configO.2 (December 10, 2008)use now sphinx for doc and nose for testingre-develop the rules config with classical python conf files and paste for
import modules0.1 (October 22, 2008)project creationecscartecscart is a module who can manage the caddy of an user.
This module save the product reference, price and quantity.The caddy has two states, valided or not valided.
The caddy has the possibility to compute rules for the total amount,
like reductions, taxes, delivery prices.The computed caddy can be published as many format, like xml, json.Finally the caddy will be persistant in database, to ensure data integrity
during a crash.Launching the cartA few initialisation procedure is mandatory to instatiate theCartclass. ;;>>> from ecs.cart import Cart
>>> user_id = 'Doriane'
>>> cart = Cart(user_id)Adding a product in the caddyTo add a product into the caddy we must use theadd_productmethod.
The first parameters is the reference of the product, the second the price,
and the optional quantity parameters.>>> cart.add_product('brosse a cheveux', 12.4)
>>> cart.add_product('lime a ongle', price=3.32, quantity=5)Set quantity of the productYou can eventualy change the quantity of a product in a cart by theset_quantitymethod.>>> cart.get_product_property('brosse a cheveux', 'quantity')
1.0
>>> cart.set_quantity('brosse a cheveux', 2)
>>> cart.get_product_property('brosse a cheveux', 'quantity')
2.0Delete a productYou can delete a product by setting his quantity to 0, or most symply
with thedel_productmethod.>>> cart.add_product('fond de teint', 19)
>>> cart.add_product('mascara', 12)
...
>>> cart.set_quantity('fond de teint', 0)
>>> cart.del_product('mascara')
...
>>> cart.get_product_property('fond de teint', 'price')
Traceback (most recent call last):
...
ValueError: Invalid reference fond de teint
>>> cart.get_product_property('mascara', 'quantity')
Traceback (most recent call last):
...
ValueError: Invalid reference mascaraGetting the amount of the caddyIt’s symply to have the amount of the caddy using theget_cart_amount>>> amount = cart.get_cart_amount()
>>> round(amount)
41.0Add reductionsYou could add reduction on the cart.>>> cart.add_reduction(5)
>>> amount = cart.get_cart_amount()
>>> round(amount)
36.0You could delete the reductionConfirm the caddyA flag is provided to manage is the caddy is valided. Thevalidationmethod
is also providedvalidationcan take a parameters wich will be the flag value:>>> cart.validation_statut
False
>>> cart.validation()
>>> cart.validation_statut
True
>>> cart.validation('Not yet')
>>> cart.validation_statut
'Not yet'Removing a caddy for an userTo delete the caddy from the persistence you must use theremovemethod>>> cart.remove()
>>> cart.products
{}