Friday, December 4, 2015

Out of Stock Products Display in Custom list.phtml

Step 1:

Create New CMS Page in Below Content Add.

{{block type="catalog/product_outofstock" template="catalog/product/list.phtml" column_count="4"}}


Step 2 :  

Create New PHP File Below Path.

Example :-  app/code/local/Mage/Catalog/Block/Product/Outofstock.php


Step 3 :

OutofStock.php in Add Below Function.

protected function _getProductCollection()
   {

         $products = Mage::getModel('catalog/product')
                ->getCollection()
                ->joinField(
                        'is_in_stock',
                        'cataloginventory/stock_item',
                        'is_in_stock',
                        'product_id=entity_id',
                        '{{table}}.stock_id=1',
                        'left'
                )
->addAttributeToSelect('*')
->addAttributeToSort('entity_id', 'desc')
                ->addAttributeToFilter('is_in_stock', array('eq' => 0));

        return $products;
   } 

Saturday, September 19, 2015

Product price change programatically after add to cart in magento

Step 1: Create an Attribute for the products
Example :-  Change Price Set its type yes/no for the product 


Step 2: Open File

code/core/mage/checkout/model/cart.php


Step 3: Goto on this function

 public function save()
    {
      ........
      ........
     }
Step 4: Copy and Paste below code,
public function save()
    {
        Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));

        $this->getQuote()->getBillingAddress();
        $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
        $this->getQuote()->collectTotals();
               
        foreach($this->getQuote()->getAllItems() as $item) {             
          $productId = $item->getProductId();
          $product = Mage::getModel('catalog/product')->load($productId);
          if($product->getAttributeText('change_price') == 'Yes')
         {
                 $price = 5;
                 $item->setCustomPrice($price);
                 $item->setOriginalCustomPrice($price);
          }
        }  
        $this->getQuote()->save(); 
        $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
        
        /**
         * Cart save usually called after changes with cart items.
         */
        Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
        return $this;
      }
Step 5: Now, Insert Product  Admin side  and set Attribute Change Price value yes for that product
Step 6: Add that product  to cart you can see that, product  price will change to $5.

 Enjoy!!!!!

Add Increase and Decrease Quantity Buttons in Magento


open addtocart.phtml file replace this code

Path :- app\design\frontend\default\your theme\template\catalog\product\view\addtocart.phtml


<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = Mage::helper('core')->quoteEscape($this->__('Add to Cart')); ?>
<?php if($_product->isSaleable()): ?>
    <div class="add-to-cart">
        <?php if(!$_product->isGrouped()): ?>
        <div class="qty-wrapper">
            <label for="qty"><?php echo $this->__('Qty:') ?></label>
            <input type="text" pattern="\d*" name="qty" id="qty" maxlength="12" value="<?php echo max($this->getProductDefaultQty() * 1, 1) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" / 
           <button class="button-arrow button-up" type="button">Increase</button>
           <button class="button-arrow button-down" type="button">Decrease</button>
        </div>
        <?php endif; ?>
        <div class="add-to-cart-buttons">
            <button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
            <?php echo $this->getChildHtml('', true, true) ?>
        </div>
    </div>
<?php endif; ?>

<script type="text/javascript">

        //&lt;![CDATA[

        jQuery(function($) {

            $('.add-to-cart .button-up').click(function() {

                $qty = $(this).parent().find('.qty');

                qty = parseInt($qty.val()) + 1;

                $qty.val(qty);

            });

            $('.add-to-cart .button-down').click(function() {

                $qty = $(this).parent().find('.qty');

                qty = parseInt($qty.val()) - 1;

                if (qty < 0)

                    qty = 0;

                $qty.val(qty);

            });

        });

        //]]&gt;


        </script>

Sunday, August 30, 2015

Custom Step Checkout Page

public function saveExcellenceAction(){ if ($this->_expireAjax()) { return; } if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost('excellence', array()); // my custom code start $custom_price = $data['like']; $quote = Mage::getSingleton('checkout/session')->getQuote(); $product1 = Mage::getModel('catalog/product')->loadByAttribute('sku',$bundlePackageSku); $bundler_Price = $custom_price; foreach($quote->getAllVisibleItems() as $quote_item1) { $productPrice = $quote_item1->getProduct()->getPrice(); //print_r(get_class_methods($quote_item1)); $quote_item1->setPrice($bundler_Price + $productPrice); $quote_item1->setCustomPrice($bundler_Price + $productPrice); $quote_item1->setOriginalCustomPrice($bundler_Price + $productPrice); $quote_item1->setRowTotal($bundler_Price + $productPrice); $quote_item1->save(); } // my custom code end $result = $this->getOnepage()->saveExcellence($data); if (!isset($result['error'])) { $result['goto_section'] = 'billing'; } $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result)); } }

http://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript

Tuesday, August 4, 2015

Custom tab add in magento admin system configuration

Custom tab in magento admin system configuration :
How to create custom tab or menu from magento admin system configuration section. Easiest way to create, just need to follow below steps
We just want to create below two files, in your required place. Here my module is called ModuleName.

app\code\local\NameSpace\ModuleName\etc\system.xml
app\code\local\NameSpace\ModuleName\etc\adminhtml.xml


system.xml:


<?xml version="1.0"?>
<config>
    <tabs>
        <my_custom_tab translate="label" module="admincontact">
            <label>My Custom Tab</label>
            <sort_order>0</sort_order>
        </my_custom_tab>
    </tabs>
    <sections>
        <my_custom_section  translate="label" module="admincontact">                   
            <label>My Custom Section</label>
            <tab>my_custom_tab</tab>
            <frontend_type>text</frontend_type>
            <sort_order>0</sort_order>
            <show_in_default>1</show_in_default>
            <show_in_website>1</show_in_website>
            <show_in_store>1</show_in_store>           
            <groups>
                <my_custom_group translate="label">
                    <label>My Custom Group</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>0</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>

<inchoo_select translate="label">
                            <label>Your Module Has Been Display </label>
                            <comment>Source model provider Magento's default Yes/No values</comment>
                            <frontend_type>select</frontend_type>
                            <sort_order>0</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                        </inchoo_select>



                        <my_custom_field translate="label">
                            <label>My Custom Field</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>90</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                            <comment>Any comment I can set here</comment>
                            <tooltip>Field ToolTip</tooltip>
                        </my_custom_field>





 <textarea translate="label comment">
                            <label>Textarea</label>
                            <comment>Textarea with store view scope.</comment>
                            <frontend_type>textarea</frontend_type>
                            <sort_order>20</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </textarea>


<file translate="label comment">
                            <label>File</label>
                            <comment><![CDATA[File saved in <strong><span style="color: red;">var/uploads</span></strong> folder.]]></comment>
                            <frontend_type>file</frontend_type>
                            <backend_model>adminhtml/system_config_backend_file</backend_model>
                            <upload_dir>var/uploads</upload_dir>
                            <sort_order>50</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>0</show_in_website>
                            <show_in_store>0</show_in_store>
                        </file>


<text_field translate="label comment">
                            <label>Please Input Your Text</label>
                            <comment>Text field with store view scope.</comment>
                            <frontend_type>text</frontend_type>
                            <sort_order>10</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </text_field>


                    </fields>


                </my_custom_group>
            </groups>
        </my_custom_section>
    </sections>

</config>


adminhtml.xml:

<?xml version="1.0"?>
    <config>
        <acl>
            <resources>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <my_custom_section translate="title" module="admincontact">
                                            <title>My Custom Section Section</title>
                                            <sort_order>0</sort_order>
                                        </my_custom_section>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>

    </config>


To retrieve data saved in your configuration, you should use something like this:

Example :  $configValue =Mage::getStoreConfig('sectionName/groupName/fieldName');


echo $configValue = Mage::getStoreConfig('my_custom_section/my_custom_group/text_field'); 

Create Custom Contact us form in Magento

Step 1:app/design/frontend/default/default/template/admincontact/simple_contact.phtml



     <form action="<?php echo Mage::getBaseUrl().'admincontact/index/save' ?>" id="contactForm" method="post"         name="contact_form">
            <div class="fieldset">
                <h2 class="legend"><?php echo Mage::helper('contacts')->__('Contact Information') ?></h2>
                <ul class="form-list">
                    <li class="fields">
                        <div class="field">
                            <label for="name" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Name') ?></label>
                            <div class="input-box">
                                <input name="name" id="name" title="<?php echo Mage::helper('contacts')->__('Name') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserName()) ?>" class="input-text required-entry" type="text" />
                            </div>
                        </div>
                        <div class="field">
                            <label for="email" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Email') ?></label>
                            <div class="input-box">
                        <input name="email" id="email" title="<?php echo Mage::helper('contacts')->__('Email') ?>" value="<?php echo $this->htmlEscape($this->helper('contacts')->getUserEmail()) ?>" class="input-text required-entry validate-email" type="text" />
                    </div>
                </div>
            </li>
            <li>
                <label for="telephone"><?php echo Mage::helper('contacts')->__('Telephone') ?></label>
                <div class="input-box">
                    <input name="telephone" id="telephone" title="<?php echo Mage::helper('contacts')->__('Telephone') ?>" value="" class="input-text" type="tel" />
   
                </div>
            </li>
            <li>
                <label for="subject"><?php echo Mage::helper('contacts')->__('Subject') ?> <span class="required">*</span></label>
                <div class="input-box"><input name="subject" id="subject" title="<?php echo Mage::helper('contacts')->__('Subject') ?>" value="" class="required-entry input-text" type="text"/>
                </div>
            </li>
            <li class="wide">
                <label for="comment" class="required"><em>*</em><?php echo Mage::helper('contacts')->__('Comment') ?></label>
                <div class="input-box">
                    <textarea name="comment" id="comment" title="<?php echo Mage::helper('contacts')->__('Comment') ?>" class="required-entry input-text" cols="5" rows="3"></textarea>
                </div>
            </li>
        </ul>
    </div>
    <div class="buttons-set">
        <p class="required"><?php echo Mage::helper('contacts')->__('* Required Fields') ?></p>
        <input type="text" name="hideit" id="hideit" value="" style="display:none !important;" />
        <button type="submit" title="<?php echo Mage::helper('contacts')->__('Submit') ?>" class="button"><span><span><?php echo Mage::helper('contacts')->__('Submit') ?></span></span></button>
    </div>
</form>
<script type="text/javascript">
    //<![CDATA[
    var contactForm = new VarienForm('contactForm', true);
    //]]>
</script>


Step 2 :- app/code/local/Inchoo/admincontact/controllers/IndexController.php

public function saveAction(){

if ( $data = $this->getRequest()->getPost() ) {

 //$model = Mage::getModel('admincontact/admincontact');
   $model = Mage::getSingleton('admincontact/admincontact');
            $model->setData($data);
           $model->save();
  $message = $this->__('Data has been saved');
Mage::getSingleton('core/session')->addSuccess($message);


}
else{

  $message = $this->__('Data has been Not saved');
Mage::getSingleton('core/session')->addSuccess($message);
}



Step 3:  Database in data Save Successfully.