ZMObject
└─ZMShoppingCart
public class ZMShoppingCart
extends ZMObject
| Field Summary | |
|---|---|
| mixed | |
| Fields inherited from org.zenmagick.core\ZMObject | |
|---|---|
| properties_ | |
| Method Summary | |
|---|---|
| void | Create new instance. |
| 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. |
| string | getHash() Calculate cart hash. |
| array | getItems() Get the items in the cart. |
| array | getMethodsForProvider(ZMShippingProvider provider) Get all available methods of the given provider for this cart. |
| mixed | 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 | Generate the JavaScript for the payment form validation. |
| int | getQty(string itemId, bool isQtyMixed, boolean qtyMixed) Get the cart quantity for the given product. |
| mixed | Get the selected shipping method. |
| int | Get the selected shipping method id. |
| ZMAddress | Get the current shipping address. |
| array | Get a list of all available shipping providers. |
| 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. |
| void | setShippingMethod(ZMShippingMethod method) Set the selected shipping method. |
| boolean | updateProduct(string sku, int quantity, boolean notify) Update item. |
| Methods inherited from org.zenmagick.core\ZMObject | |
|---|---|
| __construct, attachMethod, get, getAttachedMethods, getProperties, getPropertyNames, set, singleton | |
public mixed $cart_
public void __construct()
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 string getHash()
Calculate cart hash.
This hash can be used to validate that the cart didn't change during checkout.
public array getItems()
Get the items in the cart.
ZMShoppingCartItems.public array getMethodsForProvider(ZMShippingProvider provider)
Get all available methods of the given provider for this cart.
null for all.ZMShippingmethod instances.public mixed getOrderFormContent()
Returns the order form elements.
public string getOrderFormURL()
Returns the URL for the actual order form.
An example for the actual order form might look similar to this:
<?php echo $form->open($zm_cart->getOrderFormURL(), '', true) ?>
<?php $shoppingCart->getOrderFormContent() ?>
<div class="btn"><input type="submit" class="btn" value="<?php echo _zm("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()
Generate the JavaScript for the payment form validation.
public int getQty(string itemId, bool isQtyMixed, boolean qtyMixed)
Get the cart quantity for the given product.
false.public mixed getSelectedShippingMethod()
Get the selected shipping method.
public int getSelectedShippingMethodId()
Get the selected shipping method id.
public ZMAddress getShippingAddress()
Get the current shipping address.
public array getShippingProviders()
Get a list of all available shipping providers.
ZMShippingProvider instances.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 void setShippingMethod(ZMShippingMethod method)
Set the selected shipping method.
public boolean updateProduct(string sku, int quantity, boolean notify)
Update item.
truetrue if the product was updated, false if not.
Shopping cart.
This class is assuming a properly configured zen cart.