ZenMagick 0.9.1


org.zenmagick.ZMShoppingCart

Class ZMShoppingCart

ZMObject
|
+--ZMShoppingCart

public class ZMShoppingCart
extends ZMObject

Shopping cart.

This is assuming a properly configured zen cart.

Author:
mano
Version:
$Id: ZMShoppingCart.php 1105 2008-05-15 02:04:12Z DerManoMann $

Constructor Summary

ZMShoppingCart()

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

base_product_id(string productId)

Extract the base product id from a given string.

int

freeProductsCount()

Checks for free products in the cart.

boolean

freeShippingCount()

Checks for free shipping.

ZMAddress

getBillingAddress()

Get the selected billing address.

string

getComment()

Get the customer comment.

array

getCreditTypes()

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

getOrderFormURL()

Returns the URL for the actual order form.

int

getPaymentMethodId()

Get the id of the selected payment method.

ZMPaymentType

getPaymentType()

Get the selected payment type.

array

getPaymentTypes()

Get a list of the available payment types.

string

getPaymentsJavaScript(boolean echo)

Generate the JavaScript for the payment form validation.

int

getQty(string productId, mixed isQtyMixed, boolean qtyMixed)

Get the cart quantity for the given product.

ZMAddress

getShippingAddress()

Get the current shipping address.

mixed

getShippingMethod()

Get the selected shipping method.

int

getShippingMethodId()

Get the selected shipping method id.

int

getSize()

Get the size of the cart.

ZMAddress

getTaxAddress()

Get the tax address for this cart.

float

getTotal()

Get the cart total.

array

getTotals()

Get the order totals.

float

getWeight()

Get the carts weight.

boolean

hasBillingAddress()

Checks if the cart has a billing address.

boolean

hasOutOfStockItems()

Check for out of stock items.

boolean

hasShippingAddress()

Checks if the cart has a shipping address.

boolean

isEmpty()

Check if the cart is empty.

boolean

isGVOnly()

Checks if there are only gift vouchers in the cart.

boolean

isVirtual()

Check for virtual cart.

array

prepare_uploads(ZMProduct product, array attributes)

Prepare file uploads.

static string

product_variation_id(string productId, mixed attributes, array attrbutes)

Reverse of base_product_id.

boolean

readyForCheckout()

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

setBillingAddressId(int addressId)

Set the selected billing address.

void

setShippingAddressId(int addressId)

Set the current shipping address id.

boolean

updateProduct(string cartProductId, int quantity, boolean notify)

Update item.

int

virtualProductsCount()

Checks for virtual products in the cart.

Methods inherited from org.zenmagick.ZMObject
backtrace, create, log, singleton

Constructor Detail

ZMShoppingCart

public ZMShoppingCart()

Create new instance. /


Method Detail

addProduct

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.

Parameters:
productId - The product id.
quantity - The quantity; default is 1.
attributes - Optional list of attributes; key is the attribute id, the value can * be either an int or ZMAttributeValue; default is an empty array.
notify - Flag whether to add the product to the notify list or not; default is true
Returns:
true if the product was added, false if not.

adjustQty

public The adjustQty(mixed quantity)

Adjust the quantity based on the quantity settings.

Parameters:
quantity - The quantity.
Returns:
adjusted quantity.

base_product_id

public static int base_product_id(string productId)

Extract the base product id from a given string.

Parameters:
productId - The full product id incl. attribute suffix.
Returns:
The product id.

freeProductsCount

public int freeProductsCount()

Checks for free products in the cart.

Returns:
The number of free products in the cart.

freeShippingCount

public boolean freeShippingCount()

Checks for free shipping.

Returns:
true if the cart is free of shipping.

getBillingAddress

public ZMAddress getBillingAddress()

Get the selected billing address.

Returns:
The billing address.

getComment

public string getComment()

Get the customer comment.

Returns:
The customer comment.

getCreditTypes

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.

Returns:
List of ZMPaymentType instances.

getItems

public array getItems()

Get the items in the cart.

Returns:
List of ZMShoppingCartItems.

getOrderFormContent

public mixed getOrderFormContent(boolean echo)

Returns the order form elements.

Parameters:
echo - If true, echo the code.
Returns:
The form content for the actual order process.
See Also:
org.zenmagick.ZMShoppingCart#getOrderFormURL

getPaymentMethodId

public int getPaymentMethodId()

Get the id of the selected payment method.

Returns:
The payment method id.

getPaymentType

public ZMPaymentType getPaymentType()

Get the selected payment type.

Returns:
The payment type.

getPaymentTypes

public array getPaymentTypes()

Get a list of the available payment types.

Returns:
List of ZMPaymentType instances.

getPaymentsJavaScript

public string getPaymentsJavaScript(boolean echo)

Generate the JavaScript for the payment form validation.

Parameters:
echo - If true, echo the code.
Returns:
Fully formatted JavaScript incl. of wrapping <script> tag.

getQty

public int getQty(string productId, mixed isQtyMixed, boolean qtyMixed)

Get the cart quantity for the given product.

Parameters:
productId - The product id.
qtyMixed - Indicates whether to return just the specified product variation quantity, or * the quantity across all variations; default is false.
Returns:
The number of products in the cart.

getShippingAddress

public ZMAddress getShippingAddress()

Get the current shipping address.

Returns:
The shipping address.

getShippingMethod

public mixed getShippingMethod()

Get the selected shipping method.

Returns:
The zen-cart shipping method.

getShippingMethodId

public int getShippingMethodId()

Get the selected shipping method id.

Returns:
The shipping method id.

getSize

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.

Returns:
The number of different products in the cart.

getTaxAddress

public ZMAddress getTaxAddress()

Get the tax address for this cart.

Returns:
The tax address.

getTotal

public float getTotal()

Get the cart total.

Returns:
The cart total.

getTotals

public array getTotals()

Get the order totals.

Returns:
List of ZMOrderTotal instances.

getWeight

public float getWeight()

Get the carts weight.

Returns:
The weight if the shopping cart.

hasBillingAddress

public boolean hasBillingAddress()

Checks if the cart has a billing address.

Returns:
true if there is a billing address, false if not.

hasOutOfStockItems

public boolean hasOutOfStockItems()

Check for out of stock items.

Returns:
true if the cart contains items that are out of stock, * false if not.

hasShippingAddress

public boolean hasShippingAddress()

Checks if the cart has a shipping address.

Returns:
true if there is a shipping address, false if not.

isEmpty

public boolean isEmpty()

Check if the cart is empty.

Returns:
true if the cart is empty, false if the cart is not empty.

isGVOnly

public boolean isGVOnly()

Checks if there are only gift vouchers in the cart.

Returns:
true if only vouchers are in the cart.

isVirtual

public boolean isVirtual()

Check for virtual cart.

Returns:
true if the cart is purely virtual.

prepare_uploads

public array prepare_uploads(ZMProduct product, array attributes)

Prepare file uploads.

Check for uploaded files and prepare attributes accordingly.

Parameters:
product - The product.
attributes - The given attributes.
Returns:
A set of valid attribute values for the given product.
Todo:
IMPLEMENT!

product_variation_id

public static string product_variation_id(string productId, mixed attributes, array attrbutes)

Reverse of base_product_id.

Creates a unique id for the given product variation.

Attributes are sorted using krsort(..) so to be compatible for different attribute orders.

Parameters:
productId - The full product id incl. attribute suffix.
attrbutes - Additional product attributes.
Returns:
The product id.
Todo:
currently uses zen_get_uprid(..)...

readyForCheckout

public boolean readyForCheckout()

Check whether the cart is ready for checkout or not.

Returns:
true if the cart is ready or checkout, false if not.

removeProduct

public boolean removeProduct(string productId)

Remove item from cart.

Parameters:
productId - The product id.
Returns:
true if the product was removed, false if not.

sanitize_attributes

public array sanitize_attributes(ZMProduct product, array attributes)

Sanitize the given attributes and add default values if attributes/values invalid/missing.

Parameters:
product - The product.
attributes - The given attributes.
Returns:
A set of valid attribute values for the given product.
Todo:
return note of changes made

setBillingAddressId

public void setBillingAddressId(int addressId)

Set the selected billing address.

Parameters:
addressId - The billing address id.

setShippingAddressId

public void setShippingAddressId(int addressId)

Set the current shipping address id.

Parameters:
addressId - The new shipping address id.

updateProduct

public boolean updateProduct(string cartProductId, int quantity, boolean notify)

Update item.

Parameters:
cartProductId - The product id as used in the shopping cart (incl. the attributes suffix).
quantity - The quantity.
notify - Flag whether to add the product to the notify list or not; default is true
Returns:
true if the product was updated, false if not.

virtualProductsCount

public int virtualProductsCount()

Checks for virtual products in the cart.

Returns:
The number of virtual products in the cart.

ZenMagick 0.9.1