menu

SiteGenesis / Server-side JS / Module: controllers/Cart

Controller that adds and removes products and coupons in the cart. Also provides functions for the continue shopping button and minicart.

Source:

Members

(static) AddBonusProduct

Adds bonus product to cart.

Source:
See:

(static) AddCouponJson

Adds a coupon to the cart using JSON. Called during checkout.

Source:
See:

(static) AddProduct

Adds a product to the cart.

Source:
See:

(static) AddToWishlist

Adds the product with the given ID to the wish list.

Source:
See:

(static) ContinueShopping

Redirects the user to the last visited catalog URL.

Source:
See:

(static) MiniCart

Displays the current items in the cart in the minicart panel.

Source:
See:

(static) Show

Invalidates the login and shipment forms. Renders the basket content.

Source:
See:

(static) SubmitForm

Form handler for the cart form.

Source:
See:

Methods

(inner) addBonusProductJson()

Adds a bonus product to the cart.

Parses the httpParameterMap and adds the bonus products in it to an array.

Gets the bonus discount line item. In a transaction, removes the bonus discount line item. For each bonus product in the array, gets the product based on the product ID and adds the product as a bonus product to the cart.

If the product is a bundle, updates the product option selections for each child product, finds the line item, and replaces it with the current child product and selections.

If the product and line item can be retrieved, recalculates the cart, commits the transaction, and renders a JSON object indicating success. If the transaction fails, rolls back the transaction and renders a JSON object indicating failure.

Source:

(inner) addCouponJson()

Adds a coupon to the cart using JSON.

Gets the CartModel. Gets the coupon code from the httpParameterMap couponCode parameter. In a transaction, adds the coupon to the cart and renders a JSON object that includes the coupon code and the status of the transaction.

Source:

(inner) addProduct()

Adds or replaces a product in the cart, gift registry, or wishlist. If the function is being called as a gift registry update, calls the GiftRegistry controller ReplaceProductListItem function. The httpParameterMap source and cartAction parameters indicate how the function is called. If the function is being called as a wishlist update, calls the Wishlist controller ReplaceProductListItem function. If the product line item for the product to add has a:

  • uuid - gets a ProductModel that wraps the product and determines the product quantity and options. In a transaction, calls the CartModel updateLineItem function to replace the current product in the line item with the new product.
  • plid - gets the product list and adds a product list item. Otherwise, adds the product and checks if a new discount line item is triggered. Renders the checkout/cart/refreshcart template if the httpParameterMap format parameter is set to ajax, otherwise renders the checkout/cart/cart template.
Source:

(inner) addToWishlist()

Adds the product with the given ID to the wish list.

Gets a ProductModel that wraps the product in the httpParameterMap. Uses ProductModel updateOptionSelection to get the product options selected for the product. Gets a ProductListModel and adds the product to the product list. Renders the checkout/cart/cart template.

Source:

(inner) continueShopping()

Redirects the user to the last visited catalog URL if known, otherwise redirects to a hostname-only URL if an alias is set, or to the Home-Show controller function in the default format using the HTTP protocol.

Source:

(inner) miniCart()

Displays the current items in the cart in the minicart panel.

Source:

(inner) show()

Invalidates the login and shipment forms. Renders the checkout/cart/cart template.

Source:

(inner) submitForm()

Handles the form actions for the cart.

  • addCoupon(formgroup) - adds a coupon to the basket in a transaction. Returns a JSON object with parameters for the template.
  • calculateTotal - returns the cart object.
  • checkoutCart - validates the cart for checkout. If valid, redirect to the COCustomer-Start controller function to start the checkout. If invalid returns the cart and the results of the validation.
  • continueShopping - calls the continueShopping function and returns null.
  • deleteCoupon(formgroup) - removes a coupon from the basket in a transaction. Returns a JSON object with parameters for the template
  • deleteGiftCertificate(formgroup) - removes a gift certificate from the basket in a transaction. Returns a JSON object with parameters for the template.
  • deleteProduct(formgroup) - removes a product from the basket in a transaction. Returns a JSON object with parameters for the template.
  • editLineItem(formgroup) - gets a ProductModel that wraps the pid (product ID) in the httpParameterMap and updates the options to select for the product. Updates the product in a transaction. Renders the checkout/cart/refreshcart template. Returns null.
  • login - calls the Login controller and returns a JSON object with parameters for the template.
  • logout - logs the customer out and returns a JSON object with parameters for the template.
  • register - calls the Account controller StartRegister function. Updates the cart calculation in a transaction and returns null.
  • unregistered - calls the COShipping controller Start function and returns null.
  • updateCart - In a transaction, removes zero quantity line items, removes line items for in-store pickup, and copies data to system objects based on the form bindings. Returns a JSON object with parameters for the template.
  • error - returns null.

Note: The CartView sets the ContinueURL to this function, so that any time URLUtils.continueURL() is used in the cart.isml, this function is called. Several actions have formgroup as an input parameter. The formgroup is supplied by the FormModel handleAction function in the FormModel module. The formgroup is session.forms.cart object of the triggered action in the form definition. Any object returned by the function for an action is passed in the parameters to the cart template and is accessible using the $pdict.property syntax. For example, if a function returns {CouponStatus: status} is accessible via ${pdict.CouponStatus} Most member functions return a JSON object that contains {cart: cart}. The cart property is used by the CartView to determine the value of $pdict.Basket in the cart.isml template.

For any member function that returns an object, the page metadata is updated, the function gets a ContentModel that wraps the cart content asset, and the checkout/cart/cart template is rendered.

Source: