ZenMagick 0.9.8


org.zenmagick.store.model.checkout.ZMShoppingCart
\store\model\checkout\ZMShoppingCart.php at line 36

Class ZMShoppingCart

ZMObject
└─ZMShoppingCart

public class ZMShoppingCart
extends ZMObject

Shopping cart.

This class is assuming a properly configured zen cart.

Author:
DerManoMann
Version:
$Id: ZMShoppingCart.php 2694 2009-12-03 22:32:18Z dermanomann $

Fields inherited from org.zenmagick.core.ZMObject
properties_
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

extractBaseProductId(mixed productId, string itemId)

Extract the base product id from a given cart item id.

int

getAccountId()

Get the cart owner's account id.

ZMAddress

getBillingAddress()

Get the selected billing address.

string

getComment()

Get optional 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 itemId, 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.

float

getSubTotal()

Get the cart subtotal.

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

isVirtual()

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

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

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.core.ZMObject
attachMethod, get, getAttachedMethods, getPropertyNames, set, singleton

Constructor Detail

\store\model\checkout\ZMShoppingCart.php at line 49

ZMShoppingCart

public ZMShoppingCart()

Create new instance.


Method Detail

\store\model\checkout\ZMShoppingCart.php at line 538

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.

\store\model\checkout\ZMShoppingCart.php at line 475

adjustQty

public The adjustQty(mixed quantity)

Adjust the quantity based on the quantity settings.

Parameters:
quantity - The quantity.
Returns:
adjusted quantity.
Todo:
move to helper?

\store\model\checkout\ZMShoppingCart.php at line 777

extractBaseProductId

public static int extractBaseProductId(mixed productId, string itemId)

Extract the base product id from a given cart item id.

Parameters:
itemId - The full shopping cart item id incl. attribute suffix.
Returns:
The product id.

\store\model\checkout\ZMShoppingCart.php at line 169

getAccountId

public int getAccountId()

Get the cart owner's account id.

Returns:
The account id.

\store\model\checkout\ZMShoppingCart.php at line 280

getBillingAddress

public ZMAddress getBillingAddress()

Get the selected billing address.

Returns:
The billing address.

\store\model\checkout\ZMShoppingCart.php at line 187

getComment

public string getComment()

Get optional customer comment.

Returns:
The customer comment.

\store\model\checkout\ZMShoppingCart.php at line 425

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.

\store\model\checkout\ZMShoppingCart.php at line 130

getItems

public array getItems()

Get the items in the cart.

Returns:
List of ZMShoppingCartItems.

\store\model\checkout\ZMShoppingCart.php at line 324

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.

\store\model\checkout\ZMShoppingCart.php at line 309

getOrderFormURL

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>

Returns:
The URL to be used for the actual order form.

\store\model\checkout\ZMShoppingCart.php at line 214

getPaymentMethodId

public int getPaymentMethodId()

Get the id of the selected payment method.

Returns:
The payment method id.

\store\model\checkout\ZMShoppingCart.php at line 237

getPaymentType

public ZMPaymentType getPaymentType()

Get the selected payment type.

Returns:
The payment type.

\store\model\checkout\ZMShoppingCart.php at line 411

getPaymentTypes

public array getPaymentTypes()

Get a list of the available payment types.

Returns:
List of ZMPaymentType instances.

\store\model\checkout\ZMShoppingCart.php at line 392

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.

\store\model\checkout\ZMShoppingCart.php at line 499

getQty

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

Get the cart quantity for the given product.

Parameters:
itemId - The cart item/sku 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.

\store\model\checkout\ZMShoppingCart.php at line 261

getShippingAddress

public ZMAddress getShippingAddress()

Get the current shipping address.

Returns:
The shipping address.

\store\model\checkout\ZMShoppingCart.php at line 223

getShippingMethod

public mixed getShippingMethod()

Get the selected shipping method.

Returns:
The zen-cart shipping method.

\store\model\checkout\ZMShoppingCart.php at line 205

getShippingMethodId

public int getShippingMethodId()

Get the selected shipping method id.

Returns:
The shipping method id.

\store\model\checkout\ZMShoppingCart.php at line 82

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.

\store\model\checkout\ZMShoppingCart.php at line 150

getSubTotal

public float getSubTotal()

Get the cart subtotal.

Returns:
The cart subtotal.

\store\model\checkout\ZMShoppingCart.php at line 631

getTaxAddress

public ZMAddress getTaxAddress()

Get the tax address for this cart.

Returns:
The tax address.

\store\model\checkout\ZMShoppingCart.php at line 160

getTotal

public float getTotal()

Get the cart total.

Returns:
The cart total.

\store\model\checkout\ZMShoppingCart.php at line 362

getTotals

public array getTotals()

Get the order totals.

Returns:
List of ZMOrderTotal instances.

\store\model\checkout\ZMShoppingCart.php at line 89

getWeight

public float getWeight()

Get the carts weight.

Returns:
The weight if the shopping cart.

\store\model\checkout\ZMShoppingCart.php at line 254

hasBillingAddress

public boolean hasBillingAddress()

Checks if the cart has a billing address.

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

\store\model\checkout\ZMShoppingCart.php at line 97

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.

\store\model\checkout\ZMShoppingCart.php at line 247

hasShippingAddress

public boolean hasShippingAddress()

Checks if the cart has a shipping address.

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

\store\model\checkout\ZMShoppingCart.php at line 73

isEmpty

public boolean isEmpty()

Check if the cart is empty.

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

\store\model\checkout\ZMShoppingCart.php at line 112

isVirtual

public boolean isVirtual()

Check for virtual cart.

Returns:
true if the cart is purely virtual.

\store\model\checkout\ZMShoppingCart.php at line 796

mkItemId

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.

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

\store\model\checkout\ZMShoppingCart.php at line 659

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!

\store\model\checkout\ZMShoppingCart.php at line 464

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.

\store\model\checkout\ZMShoppingCart.php at line 577

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.

\store\model\checkout\ZMShoppingCart.php at line 682

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

\store\model\checkout\ZMShoppingCart.php at line 178

setAccountId

public void setAccountId(int accountId)

Set the cart owner's account id.

Parameters:
accountId - The account id.

\store\model\checkout\ZMShoppingCart.php at line 289

setBillingAddressId

public void setBillingAddressId(int addressId)

Set the selected billing address.

Parameters:
addressId - The billing address id.

\store\model\checkout\ZMShoppingCart.php at line 196

setComment

public void setComment(string comment)

Set the customer comment.

Parameters:
comment - The customer comment.

\store\model\checkout\ZMShoppingCart.php at line 121

setItems

public void setItems(array items)

Set the cart items.

Parameters:
items - List of ZMShoppingCartItems.

\store\model\checkout\ZMShoppingCart.php at line 270

setShippingAddressId

public void setShippingAddressId(int addressId)

Set the current shipping address id.

Parameters:
addressId - The new shipping address id.

\store\model\checkout\ZMShoppingCart.php at line 594

updateProduct

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

Update item.

Parameters:
sku - The product sku.
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.

ZenMagick 0.9.8