Skip to main content

Quick Order Placement Form


If we want to place fast and quick order. We want to list all the product along with their categories  and price. For achieving this goal we have to follow these steps:

1) Create Template File: Create a template  file at /app/design/frontend/default/blanco/template/catalog/product/list_fast_order.phtml which will the list of all products along with their categories and Price listing.

2) Edit Layout: Before this we have to add the phtml file in catalog.xml file.

3) Get ResultIn list_fast_order.phtml file we have to show the product category wise



       
/*assume we want to get all products of category id 5 */

$catid_1 = 5;

/*we are loading all the products from category id 5 */

$_category = Mage::getModel('catalog/category')->load($catid_1);

$subs = $_category->getAllChildren(true);

/* Use for loop for making result array */

$result = array();

foreach($subs as $cat_id) {

                  $category = new Mage_Catalog_Model_Category();

                  $category->load($cat_id);

                  $collection = $category->getProductCollection();

                  $result[$cat_id] = array();

                  foreach ($collection as $product) {

                                    $cat_name = $category->getName();

                                    $cat_url = $category->getUrl(); 

                  }

}

ksort($result);


4) Show Result: Use Table structure or Div to show the result array in list_fast_order.phtml .


       
<form name="frmQuickbuy" id="frmQuickbuy" style="margin:0px; padding:0px;">

 <table id="product_table" class="tablesorter" cellspacing="1" style="display:none;">

  <thead>

      <tr>

             <th><b><?php echo $this->__('Category') ?></b></th>

             <th><b><?php echo $this->__('Product') ?></b></th>    

             <th><b><?php echo $this->__('Price') ?></b></th> 

      </tr>

  </thead>

  <tbody>   

   <?php

   // All Products 

   foreach ($result as $cat) { 

       foreach ($cat as $p) {

           $_product = new Mage_Catalog_Model_Product();

           $_product->load($p["product_id"]);

           if($_product->isSaleable()) { ?>

   <tr>

    <td><a href="<?php echo $p["cat_url"] ?>" title="<?php echo $p["cat_name"]; ?>">

           <?php echo $p["cat_name"]; ?></a>

    </td>

    <td><a href="<?php echo $_product->getProductUrl() ?>" class="product_description" title="<?php echo $this->stripTags($_product->getDescription(), null, true) ?>">

            <?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName(), 'name') ?></a>

    </td>

    <td><?php echo $_product->getSku() ?></td>    

   </tr>   

   <?php }}}?>

  </tbody>

 </table>






5) Create Ajax Functionality: We have to create an ajax which will send whole form data to an php file.

       
/*On click 'Add to cart' */

jQuery("#quickbuy_add_to_cart").live({

    click: function() {

    /*serialize form data*/    

    frm_data = jQuery("#frmQuickbuy").serialize();

    /*ajax code*/ 

    jQuery.ajax({

        url: '/addToCart.php',

        data: frm_data,

        success: function(data_results) {

            var tmp = data_results.split("|");

            if(!parseInt(tmp[0])) {

                jQuery("#quickbuy_add_to_cart").show();

                alert(tmp[1]);

            } else {

                window.location.href = '/checkout/cart/'; 

            }                                                                              

        }

    });     

    }

});


This will look something like this:









Image: Order Placement Form


6) Create addToCart.php at root or parallel to app folder.

       
/*code for addToCart.php starts from here*/
include_once 'app/Mage.php';
Mage::app();
try {
$request = Mage::app()->getRequest();
        /*store all serialize form data to variable $data */
$data = $request->getParams();
$products_to_add = array();
        /*assigning values from stored array */
foreach($data["productdropdown"] as $product_id => $productcaseinfo) {
if(isset($data["productdropdown"][$product_id]) && (int)$data["productdropdown"][$product_id]) {
$products_to_add[] = array(
"product_id"=>$product_id,
"qty"=>1
);
}
}
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$cart = Mage::helper('checkout/cart')->getCart();
if($products_to_add) { foreach($products_to_add as $p) {
$product = Mage::getModel('catalog/product')->load($p["product_id"]);
$arr = array();
$arr['qty'] = $p["qty"];
$cart->addProduct($product, $arr);
$session->setLastAddedProductId($product->getId());
$session->setCartWasUpdated(true);
}}
$cart->save();
echo "1|";
} catch (Exception $e) {
$result = "0|'".$e->getMessage()."'";
echo $result;
}
7) Like this we can create an fast and quick order placement form in magento.

Author,
Mohit verma


Comments

  1. Hi Mohit ,

    Thanks for sharing this one ,really useful.



    Magento Developers

    ReplyDelete
  2. Dear Mohit,

    Thank you for posting this tutorial, that's what I been looking for about a month now.
    However I do have a question regarding your tutorial, Is step 2,3,4,5 going the same file I just created "list_fast_order.phtml" or are they a separated files if so what are the file names an what location,... or is there a way that I can download the original files or if its too much to asking to share the complete source Im new to this any help will be greatly appreciated Thanks

    ReplyDelete
  3. Hi Johny,

    Apologies for late reply step 2 belongs to layout file and 3, 4, 5 step is for list_fast_order.phtml file. In step 2 file is layout file which is located in app/design/frontend/default/{yourthemefolder}/layout/layout.xml. Here layout.xml is layout file for that particular extension on which you are working.

    Besides if you can send me your email id then i will send you the code.

    Thanks

    ReplyDelete
  4. Hi All,

    Checkout my new gig
    https://www.fiverr.com/mohitverma836/make-an-ecommerce-website-for-you?arrived_from_manage_gigs=true&display_share=true

    Thanks,
    Mohit verma

    ReplyDelete
  5. Thanks for your tutorial, it's useful for me and it helped me much.
    I also followed some of these tips on this link: http://bsscommerce.com/blog/magento-wholesale-tip-way-extension/

    ReplyDelete
    Replies
    1. Hi PenG,

      Thanks for your feedback. I am working on a plugin which is advance version of this.

      Delete
  6. Thanks for sharing.
    However I suggest another simple way for this issue, this is using an extension for Magento. I recommend using Wholesale Fast Order, check its demo here: https://goo.gl/LBtNa4
    Hope it helps!

    ReplyDelete

Post a Comment

Popular posts from this blog

Add Products to cart Programmatically in Magento

Sometimes we need to add products into cart programmatically in controller. Below is the code which you can use to add product to cart.   1) For Simple Products If you are working in magento controller and wants to add a simple product programmatically then here is the code: Suppose our product id value stored in $productId.         // Below code will create instance of cart         $cart = Mage::getModel('checkout/cart');         // This will initialize cart         $cart->init();         // Get the product collection by passing product id         $productCollection = Mage::getModel('catalog/product')->load($productId); This product collection will be required as we have to pass it at the time of adding product to cart. For adding the product we have to call addProduct() function. In this function we have to pass two parameters first is productcollection and second is an array. This array contains product id and quantity which we are going

Magento Multiple Store Setup

Many times we need to create multiple stores in magento website. In magento we create different stores to make it more local. We can access different stores using below ways: 1) Domain (e.g. www.store1.com and www.store2.com) 2) Subdomain (e.g. store1.mystore.com and store2.mystore.com) 3) Folder (e.g. mystore.com/store1/ and mystore.com/store2/) Its all upto to you which way you prefer. For all these we need to follow below steps: Step 1: Add new Magento store: It might be possible that both store have different  catalogue so to manage this. We need to make two different Base Categories. To create a new base category follow below steps: Log in to your Magento admin panel. Go to Catalog -> Manage Categories . If you want both your websites to share same “ Default Category ”, select it by clicking on it on the left. Or click Add Root Category to create a new root category different from the existing one. Once the category is selected, under the General