Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Magento Checkout Components

Describe how to modify and effectively customize the quote object, the quote item object, and the address object.
by

Jorj Daniel

on 18 December 2012

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Magento Checkout Components

Session 9 Checkout Session 10 Shopping Cart Flow (adding a product) Loads The Product Controller loads the product Responsible Class : Mage_Checkout_CartController Controller loads product by id passed via product url parameter. If the product is not loaded (not exist, not enabled, etc), then it returns customer to the previous page. Previous page is detected by referrer header or parameter. If it is not possible to detect previous page, customer just gets redirected to cart page. The loaded product with url parameters are passed to cart model method addProduct(). Prepare product request Cart Model Prepares Product Request Responsible Class : Mage_Checkout_Model_Cart

The request object is just a Varien_Object class instance with url parameters as data.

After creation of the object, requested quantity gets validated for matching minimal quantity settings of the product. If quantity is lower, it gets corrected automatically.

When product and request is prepared, the quote model method addProduct() gets involved. Cart Model Prepares Product Request (2) Modify Quote Item Create a quote and pass request to product type model Processes product request Quote Model Processes Product Request Responsible Class : Mage_Sales_Model_Quote

Finally Magento gets to a quote model, but just to pass request to product type model. At this step, method addProductAdvanced() of product type model is invoked. Validates request Product Type Model Validation and Processing of Request Responsible Class : Mage_Catalog_Product_Type_{TYPE} Quote :: addProductAdvanced Quote ProductType ::prepareForCart Quote ProductType ::_prepareProduct Simple Products (Mage_Catalog_Model_Product_Type_Simple) The first step of the request processing for this product type is validation of custom options. They are get validated by _prepareOptions() method of type model.

When options are validated and processed, then it throws an event. The event name depends on type of product processing: catalog_product_type_prepare_full_options or catalog_product_type_prepare_lite_options.

Afterwards the product is checked for being added to the cart by grouped parent, in this case additional product options are added. Then _processProduct()method just returns array with a single configured instance of product and special properties set to it (quantity, custom options, buy request, etc). Grouped Products (Mage_Catalog_Model_Product_Type_Grouped) Grouped type process is different from simple product type, however it involves simple products process for child products.

Everything starts from retrieving all assigned child products and comparing them to passed child ids in request. If no child products found in request, _prepareProduct() returns string with error message.

Otherwise it just invokes _prepareProduct() method of child product type model and adds it to array of configured product instances. When all child products are processed and there is no errors returned, it adds own product instance to the array and returns it. Code snippet Configurable Product (Mage_Catalog_Model_Product_Type_Configurable) The initial process is the same as in simple product and afterwards it checks configured options by finding a correct simple product that matches all the selected values and invokes its _prepareProduct() method.

Also if configurable product has custom options, this options partially added to simple product for making it unique in the cart.

If no simple product that matches selection is found, it returns string with error text, otherwise array with two items: configurable product itself and its matched child simple product. Code snippet Bundle Product (Mage_Bundle_Model_Product_Type) The initial process as well the same as in simple product. Then all the possible options and their selections gets loaded and each options gets validated.

If option is required and at least one selection was not specified in the request, then it returns an error string. Then the selections that were selected are checked for their purchase availability (i.e. isSalable() method is invoked).

Later on all the selections are iterated to set selection quantity from input or predefined value (if input is empty or customer cannot change it). As well prepareForCart() method gets invoked for each selection product to add its own options. In the end, bundle product model returns bundle product and all its selection products in the array of result. Throws Exception Message
&
Redirect Applies Custom Options & Returning Child Products Product already exits in Cart Create Quote Item for each Product No Assign product data and Custom Options Changes Quote item quantity Yes Dispatch qty change event Check quote item for error Collect Totals and Saves Quote Redirect Customer to Shipping Cart or Product Page Save cart Dispatch add to cart event Quote Model Adds a New Item or Changes Existing One Qty First of all, before creating a new quote item, quote model checks for existence of the product with the same combination of options and product id.

For this purpose method getItemByProduct() is used. This method walks though all quote items and calls representProduct() method of quote item model. If method returns true, quote model just updates existing item qty by calling addQty() method. Otherwise creates a new quote item and does the same for it. How to create custom Magento Total models Xml <global>
<sales>
<quote>
<totals>
<your_total>
<class>your_module/quote_address_total_yourTotal</class>
<after>shipping</after> <!-- calculate after these total models -->
<before>grand_total,tax</before> <!-- calculate before these total models -->
</your_total>
</totals>
</quote>
( . . . ) How to create custom Magento Total models (2) PHP class Your_Module_Model_Quote_Address_Total_YourTotal
extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
// Calculate your total value
public function collect(Mage_Sales_Model_Quote_Address $address)
{
parent::collect($address);
// some logic here
return $this;
}

public function fetch(Mage_Sales_Model_Quote_Address $address)
{
if ($address->getMyTotal() > 0)
{
$address->addTotal(array(
'code' => $this->getCode(),
'title' => Mage::helper('your_module')->__('Your Total'),
'value' => $address->getMyTotal()
));
}
return $this;
}
} The End
Full transcript