ZMObject
|
+--ZMShoppingCart
public class ZMShoppingCart
extends ZMObject
| Fields inherited from org.zenmagick.ZMObject | |
|---|---|
| properties_ | |
| Constructor Summary | |
|---|---|
Create new instance. |
|
| Method Summary | |
|---|---|
| boolean | addProduct(int productId, int quantity, array attributes, boolean notify) Add a product in the given quantity. |
| The | adjustQty(mixed quantity) Adjust the quantity based on the quantity settings. |
| static int | extractBaseProductId(mixed productId, string itemId) Extract the base product id from a given cart item id. |
| int | Get the cart owner's account id. |
| ZMAddress | Get the selected billing address. |
| string | Get optional customer comment. |
| array | Get list of available credit types; eg promo codes, etc. |
| array | getItems() Get the items in the cart. |
| mixed | getOrderFormContent(boolean echo) Returns the order form elements. |
| string | Returns the URL for the actual order form. |
| int | Get the id of the selected payment method. |
| ZMPaymentType | Get the selected payment type. |
| array | Get a list of the available payment types. |
| string | getPaymentsJavaScript(boolean echo) Generate the JavaScript for the payment form validation. |
| int | getQty(string itemId, mixed isQtyMixed, boolean qtyMixed) Get the cart quantity for the given product. |
| ZMAddress | Get the current shipping address. |
| mixed | Get the selected shipping method. |
| int | Get the selected shipping method id. |
| int | getSize() Get the size of the cart. |
| float | Get the cart subtotal. |
| ZMAddress | Get the tax address for this cart. |
| float | getTotal() Get the cart total. |
| array | Get the order totals. |
| float | Get the carts weight. |
| boolean | Checks if the cart has a billing address. |
| boolean | Check for out of stock items. |
| boolean | Checks if the cart has a shipping address. |
| boolean | isEmpty() Check if the cart is empty. |
| boolean | Check for virtual cart. |
| static string | mkItemId(string productId, mixed attributes, array attrbutes) Create unique cart item/sku id, based on the base product id and attribute information. |
| array | prepare_uploads(ZMProduct product, array attributes) Prepare file uploads. |
| boolean | Check whether the cart is ready for checkout or not. |
| boolean | removeProduct(string productId) Remove item from cart. |
| array | sanitize_attributes(ZMProduct product, array attributes) Sanitize the given attributes and add default values if attributes/values invalid/missing. |
| void | setAccountId(int accountId) Set the cart owner's account id. |
| void | setBillingAddressId(int addressId) Set the selected billing address. |
| void | setComment(string comment) Set the customer comment. |
| void | setItems(array items) Set the cart items. |
| void | setShippingAddressId(int addressId) Set the current shipping address id. |
| boolean | updateProduct(string sku, int quantity, boolean notify) Update item. |
| Methods inherited from org.zenmagick.ZMObject | |
|---|---|
| attachMethod, get, getAttachedMethods, getPropertyNames, set, singleton | |
public ZMShoppingCart()
Create new instance. /
public boolean addProduct(int productId, int quantity, array attributes, boolean notify)
Add a product in the given quantity.
Doesn't support uploads (yet).
If isSanitizeAttributes is set to true, missing
attributes will be added automatically and set to defaults.
1.ZMAttributeValue; default is an empty array.truetrue if the product was added, false if not.public The adjustQty(mixed quantity)
Adjust the quantity based on the quantity settings.
public static int extractBaseProductId(mixed productId, string itemId)
Extract the base product id from a given cart item id.
public int getAccountId()
Get the cart owner's account id.
public ZMAddress getBillingAddress()
Get the selected billing address.
public string getComment()
Get optional customer comment.
public array getCreditTypes()
Get list of available credit types; eg promo codes, etc.
NOTE: This is also using ZMPaymentType as class
to handle the data. Only difference is that the payment type is used to reduce
the cart total.
ZMPaymentType instances.public array getItems()
Get the items in the cart.
ZMShoppingCartItems.public mixed getOrderFormContent(boolean echo)
Returns the order form elements.
true, echo the code.public string getOrderFormURL()
Returns the URL for the actual order form.
An example for the actual order form might look similar to this:
<?php $form->open($zm_cart->getOrderFormURL(), '', true) ?>
<?php $shoppingCart->getOrderFormContent() ?>
<div class="btn"><input type="submit" class="btn" value="<?php zm_l10n("Confirm to order") ?>" /></div>
</form>
public int getPaymentMethodId()
Get the id of the selected payment method.
public ZMPaymentType getPaymentType()
Get the selected payment type.
public array getPaymentTypes()
Get a list of the available payment types.
ZMPaymentType instances.public string getPaymentsJavaScript(boolean echo)
Generate the JavaScript for the payment form validation.
true, echo the code.public int getQty(string itemId, mixed isQtyMixed, boolean qtyMixed)
Get the cart quantity for the given product.
false.public ZMAddress getShippingAddress()
Get the current shipping address.
public mixed getShippingMethod()
Get the selected shipping method.
public int getShippingMethodId()
Get the selected shipping method id.
public int getSize()
Get the size of the cart.
NOTE: This is the number of line items in the cart, not the total number of products.
public float getSubTotal()
Get the cart subtotal.
public ZMAddress getTaxAddress()
Get the tax address for this cart.
public float getTotal()
Get the cart total.
public array getTotals()
Get the order totals.
ZMOrderTotal instances.public float getWeight()
Get the carts weight.
public boolean hasBillingAddress()
Checks if the cart has a billing address.
true if there is a billing address, false if not.public boolean hasOutOfStockItems()
Check for out of stock items.
true if the cart contains items that are out of stock,
* false if not.public boolean hasShippingAddress()
Checks if the cart has a shipping address.
true if there is a shipping address, false if not.public boolean isEmpty()
Check if the cart is empty.
true if the cart is empty, false if the cart is not empty.public boolean isVirtual()
Check for virtual cart.
true if the cart is purely virtual.public static string mkItemId(string productId, mixed attributes, array attrbutes)
Create unique cart item/sku id, based on the base product id and attribute information.
This is the reverse of extractBaseProductId.
Attributes are sorted using krsort(..) so to be compatible
for different attribute orders.
zen_get_uprid(..)...public array prepare_uploads(ZMProduct product, array attributes)
Prepare file uploads.
Check for uploaded files and prepare attributes accordingly.
public boolean readyForCheckout()
Check whether the cart is ready for checkout or not.
true if the cart is ready or checkout, false if not.public boolean removeProduct(string productId)
Remove item from cart.
true if the product was removed, false if not.public array sanitize_attributes(ZMProduct product, array attributes)
Sanitize the given attributes and add default values if attributes/values invalid/missing.
public void setAccountId(int accountId)
Set the cart owner's account id.
public void setBillingAddressId(int addressId)
Set the selected billing address.
public void setComment(string comment)
Set the customer comment.
public void setItems(array items)
Set the cart items.
ZMShoppingCartItems.public void setShippingAddressId(int addressId)
Set the current shipping address id.
public boolean updateProduct(string sku, int quantity, boolean notify)
Update item.
truetrue if the product was updated, false if not.
Shopping cart.
This is assuming a properly configured zen cart.