Tuesday, October 23, 2012

Download Magento extension without Pear

Now You can download the magento extension and can check the code

http://freegento.com/ddl-magento-extension.php

http://www.tangkoko.com/direct-download-magento-extension/


Monday, October 22, 2012

Alter a form in Admin

Here I am adding a storied in a form

Step 1: Alter table in database and add a field storeid in Table

Step 2: You can alter it from install file

<?php
      
      $installer = $this;
      
      $installer->startSetup();
      
      $installer->run("
      
DROP TABLE IF EXISTS {$this->getTable('locator')};
CREATE TABLE {$this->getTable('locator')} (
  `locator_id` int(11) unsigned NOT NULL auto_increment,
  `name` varchar(255) NOT NULL default '',
  `address` varchar(255) NOT NULL default '',
  `city` varchar(100) NOT NULL default '',
  `state` varchar(2) NOT NULL default '',
  `postal_code` varchar(8) NOT NULL default '',
  `phone` varchar(20) default NULL,
  `longitude` double NOT NULL,
  `latitude` double NOT NULL,
  `status` smallint(6) NOT NULL default '0',
  `created_time` datetime NULL,
  `update_time` datetime NULL,
  `storeid` smallint(6) NOT NULL default '0',
  PRIMARY KEY (`locator_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
      
          ");
      
      $installer->endSetup();

3) Create an array of dropdown of store

 public function toOptionArray()
    {
        $allStores = Mage::app()->getStores();
        $dataPoints= array();
        foreach ($allStores as $_eachStoreId => $val)
        {
            $_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
            $_storeName = Mage::app()->getStore($_eachStoreId)->getName();
            $_storeId = Mage::app()->getStore($_eachStoreId)->getId();

            //$dataPoints = array(
            //"value"=>$_storeId,
            //"label"=>$_storeName);
        $dataPoints[] =  array("value"=>$_storeId,"label"=>$_storeName);

          

        }
     

        return $dataPoints;
    
    }
Step 4: Show field in Form
$fieldset->addField('storeid', 'select', array(
        'name'  => 'storeid',
        'label'     => 'Store',
        'values'    => $this->toOptionArray(),
    ));

Step 5: Now Alter save function

 $locatorModel->setId($this->getRequest()->getParam('id'))
                        ->setName(trim($postData['name']))
                        ->setStatus($postData['status'])
                        ->setAddress(trim($postData['address']))
                        ->setCity(trim($postData['city']))
                        ->setState(trim($postData['state']))
                        ->setPostalCode(trim($postData['postal_code']))
                        ->setPhone(trim($postData['phone']))
                        ->setLongitude($longitude)
                        ->setLatitude($latitude)
                        ->setStoreid($storeid)
                        ->save();



Thursday, October 18, 2012

Change Product Image on View Page to Associated Product's Image


Change Product Image on View Page to Associated Product's Image

Last modified by nuzil on Wed, August 17, 2011 14:24
Source|Old Revisions  

1. app/design/frontend/*/*/template/catalog/product/view.phtml

Change
  1. <script type="text/javascript">
  2.     var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
  3. </script>
Edit ——————- Fixed bug in IE caused by the last comma in the foreach loop
  1. <script type="text/javascript">
  2.     var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
  3.     var assocIMG =  // Added  - Removed { here, causes issues with other scripts when not working with a configurable product.
  4.     <?php
  5.     if ($_product->getTypeId() == "configurable") {
  6.         echo "{";
  7.         $associated_products = $_product->loadByAttribute('sku', $_product->getSku())->getTypeInstance()->getUsedProducts();
  8.         foreach ($associated_products as $assoc)
  9.             $dados[] = $assoc->getId().":'".($assoc->image == "no_selection" || $assoc->image == "" ? $this->helper('catalog/image')->init($_product, 'image', $_product->image)->resize(365,400) : $this->helper('catalog/image')->init($assoc, 'image', $assoc->image)->resize(365,400))."'";
  10.     } else {
  11.         $dados[]"''";
  12.     }
  13.     echo implode(',', $dados );     
  14.     if ($_product->getTypeId() == "configurable") {
  15.         echo "}";
  16.     }
  17.     ?>
  18. </script>

2. app/design/frontend/*/*/template/catalog/product/view/type/options/configurable.phtml

Change
  1. <script type="text/javascript">
  2.     var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
  3. </script>
to
  1. <script type="text/javascript">
  2.     var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
  3.     var selectedAssocProducts = {}; // Added
  4. </script>

#EDITED: nuzil: I ckecked in magento 1.5.1.0 and it works for file

3. js/varien/configurable.js

=== 3. js/varien/product.js ===
a) Add to top :
  1. if(typeof selectedAssocProducts=='undefined') {
  2.     var selectedAssocProducts = {};
  3. }

b) In configureElement : function(element)
add to end of function after the following lines
  1.        this.reloadPrice();
  2. //      Calculator.updatePrice();
add this :
  1. /***** Load Associated Image : This should come after this.resetChildren is called *****/
  2.  
  3. // If an option doesnt have a value attribute, it'll take its innerHTML as its value - hence the reason for || element.value.substr(0,6) == 'choose'
  4. if (!element.value || element.value.substr(0,6) == 'choose') return; // Selected "choose option"
  5. var attributeId = element.id.replace(/[a-z]*/, '');
  6. for (var a in this.config.attributes)
  7. {
  8.     for (i = 0; i < this.config.attributes[a].options.length; i++)
  9.     {
  10.         if (this.config.attributes[a].options[i].id != element.value) continue;
  11.         selectedAssocProducts[a] = this.config.attributes[attributeId].options[i].products;
  12.     }
  13. }
  14.  
  15. var productNo = intersect(selectedAssocProducts) || selectedAssocProducts[attributeId][0];
  16. $('image').src = assocIMG[productNo];

c) Change resetChildren : function(element) to
  1. resetChildren : function(element){
  2.     delete selectedAssocProducts[element.config.id]; // Added
  3.     if(element.childSettings) {       
  4.         for(var i=0;i<element.childSettings.length;i++){
  5.             element.childSettings[i].selectedIndex = 0;
  6.             element.childSettings[i].disabled = true;               
  7.             delete selectedAssocProducts[element.childSettings[i].config.id]; // Added
  8.             if(element.config){
  9.                 this.state[element.config.id] = false;                   
  10.             }
  11.         }
  12.     }
  13. },

d) Add to end of file
  1. function intersect(ar) // ar can be an array of arrays or an asssociative array
  2. {
  3.     if (ar == null) return false;
  4.        
  5.     var a = new Array();
  6.    
  7.     if (ar.length == undefined) // Associate Array
  8.     {       
  9.         for (var i in ar)
  10.          a.push(ar[i]);       
  11.     }     
  12.     else
  13.      a = ar;
  14.    
  15.     if (a.length == 1) return false; // Single array ? Nothing to intersect with
  16.  
  17.     var common = new Array();
  18.     function loop(a, index, s_index, e_index)
  19.     {               
  20.         if (index == null) index = 0;
  21.         if (s_index == null) s_index = 0;
  22.         if (e_index == null) e_index = a[index].length;
  23.         if (index == a.length - 1) return;           
  24.        
  25.         for (var i = s_index; i < e_index; i++)
  26.         {
  27.             if (common.indexOf(a[index][i]) != -1) continue;
  28.             for (var j = 0; j < a[index + 1].length; j++)
  29.             {
  30.                 if (a[index][i] != a[index+1][j]) continue;                       
  31.                 loop(a, index + 1, j, j + 1);
  32.                 if (index + 1 == a.length - 1) { common.push(a[index][i]); break; }                       
  33.             }
  34.         }           
  35.     }       
  36.  
  37.     loop(a);
  38.     return common;
  39. }

On a configurable product’s view page, in order to display the associated product’s image after an option has been 

Tuesday, October 16, 2012

Change Position of bundle product option and custom options

<!--Additional block for bundle product type-->

    <
PRODUCT_TYPE_bundle>
        <
reference name="head">
            <
action method="addItem"><type>skin_js</type><name>js/bundle.js</name></action>
        </
reference>
        <
reference name="product.info">
            <
block type="bundle/catalog_product_view_type_bundle" name="product.info.bundle" as="product_type_data" after="-" template="bundle/catalog/product/view/type/bundle.phtml">
                <
action method="addPriceBlockType"><type>bundle</type><block>bundle/catalog_product_price</block><template>bundle/catalog/product/price.phtml</template></action>
                <
block type="bundle/catalog_product_price" name="bundle.prices" as="bundle_prices" template="bundle/catalog/product/view/price.phtml" />
            </
block>
        </
reference>

        <
reference name="product.info.options.wrapper">
            <
block type="bundle/catalog_product_view_type_bundle" name="product.info.bundle.options" as="type_bundle_options" after="-" template="bundle/catalog/product/view/type/bundle/options.phtml">
                <
action method="addRenderer"><type>select</type><block>bundle/catalog_product_view_type_bundle_option_select</block></action>
                <
action method="addRenderer"><type>multi</type><block>bundle/catalog_product_view_type_bundle_option_multi</block></action>
                <
action method="addRenderer"><type>radio</type><block>bundle/catalog_product_view_type_bundle_option_radio</block></action>
                <
action method="addRenderer"><type>checkbox</type><block>bundle/catalog_product_view_type_bundle_option_checkbox</block></action>
            </
block>
            <
action method="append"><block>product.info.bundle.options</block></action>
        </
reference>
        <
reference name="product.info.options.wrapper.bottom">
            <
remove name="product.tierprices" />
            <
block type="bundle/catalog_product_view" name="bundle.tierprices" as="tierprices" before="-" template="bundle/catalog/product/view/tierprices.phtml"/>
        </
reference>
        <
reference name="product.clone_prices">
            <
action method="addPriceBlockType"><type>bundle</type><block>bundle/catalog_product_price</block><template>bundle/catalog/product/view/price.phtml</template></action>
        </
reference>
    </
PRODUCT_TYPE_bundle>

Adding Confirm E-mail Address Field to Magento Frontend Forms

Adding Confirm E-mail Address Field to Magento Frontend Forms

If you are thinking of adding a confirmation of e-mail address to the front-end registration pages of your store e.g the Checkout billing page or the customer account registration, the little snippets below could be of use to you
For the Checkout billing page
1. Locate the magento checkout billing page (billing.phtml) which can be found in app/design/frontend/default/ /template/checkout/onepage
2. Add code 1 below where situable;
Code 1

<div class="field"><label for="billing:confirm_email" class="required"><em>*</em><?php echo $this->__('Confirm Email Address') ?></label>
<div class="input-box">
<input type="text" name="billing[confirm_email]" title="<?php echo $this->__('Confirm Email') ?>" id="billing:confirm_email" class="input-text required-entry validate-cemail" />
</div>
For the validation of this email confirmation field with the actual email field
3. Locate the Javascript file which Magento uses for validation (validation.js) in /js/prototype
4. Add code 3 where suitable e.g immediately after this line(code 2) in validation.js
Code 2
1
2
return !(pass.length < 7);
    }],
Code 3

['validate-cemail', 'Please make sure your emails match.', function(v) {
var conf = $$('.validate-cemail')[0];
var pass = false;
if ($('email')) {
pass = $('email');
}
var emailElements = $$('.validate-email');
for (var i = 0; i < emailElements.size(); i++) {
var emailElement = emailElements[i];
if (emailElement.up('form').id == conf.up('form').id) {
pass = emailElement;
}
}
if ($$('.validate-admin-email').size()) {
pass = $$('.validate-admin-email')[0];
}
return (pass.value == conf.value);
}],
Then that should just do exactly what you want.
For the Customer Account Registration page
1. Locate the magento account register page ,register.phtml in
app/design/frontend/ /default/template/persistent/customer/form/
2. Include code 4 where suitable
Code 4

<div class="field">
<label for="confirm_email" class="required"><em>*</em><?php echo $this->__('Confirm Email Address') ?></label>
<div class="input-box">
<input type="text" name="confirm_email" title="<?php echo $this->__('Confirm Email') ?>" id="confirm_email" class="input-text required-entry validate-cemail" />
</div>
</div>

Sunday, October 14, 2012

Tell a Friend in pop-up


Change the send a friend layout to popup


        <reference name="root">
           <action method="setTemplate"><template>page/popup.phtml</template></action>
        </reference>

 
Use this script in catalog page(id you are using colorbox)

   <?php if ($this->helper('customer')->isLoggedIn()): ?>
          <p class="email-friend"><a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>" rel="fancybox" class="group2 cboxElement"><?php echo $this->__('Email to a Friend') ?></a></p>
     <?php else: ?>
          <p class="email-friend"><a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>"><?php echo $this->__('Email to a Friend') ?></a></p>
     <?php endif; ?>
<?php endif; ?> 

Friday, October 12, 2012

Enable Custom option in bundle product


As a quick solution to add Custom Options to bundled products with dynamic prices you may try to tweak prepareProductSave method in app/code/core/Mage/Bundle/Model/Observer.php, namely just comment some code out as follows: 
/*
        if ($product->getPriceType() == '0' && !$product->getOptionsReadonly()) {
            $product->setCanSaveCustomOptions(true);
            if ($customOptions = $product->getProductOptions()) {
                foreach (array_keys($customOptions) as $key) {
                    $customOptions[$key]['is_delete'] = 1;
                }
                $product->setProductOptions($customOptions);
            }
        }
*/
To get rid of “Bundle with dynamic pricing cannot include custom defined options. Options will not be saved.” message you should hack app/design/adminhtml/default/default/template/catalog/product/edit/options.phtml template
//show error message
/*
if ($('price_type')) {
    if ($('price_type').value == '0' && $('dynamic-price-warrning')) {
        $('dynamic-price-warrning').show();
    }
}
*/