Tuesday, February 5, 2013

Magento : find out which xml fails

Magento : find out which xml fails

If you’ve been working with Magento extensions or layout, you might have encountered the frustration of trying to find out which XML generates the following error, potentially harming the whole magento installation :
01Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 61: parser error : StartTag: invalid element name  in C:\aa_work\RueDeSiam\www\lib\Varien\Simplexml\Config.php on line 502
02 
03#0 C:\aa_work\RueDeSiam\www\lib\Varien\Simplexml\Config.php(502): mageCoreErrorHandler(2, 'simplexml_load_...', 'C:\aa_work\RueD...', 502, Array)
04#1 C:\aa_work\RueDeSiam\www\lib\Varien\Simplexml\Config.php(489): Varien_Simplexml_Config->loadString('?????? ...', 'Mage_Core_Model...')
05#2 C:\aa_work\RueDeSiam\www\app\code\core\Mage\Adminhtml\Model\Config.php(102): Varien_Simplexml_Config->loadFile('?????? ...', 'Mage_Core_Model...')
06#3 C:\aa_work\RueDeSiam\www\app\code\core\Mage\Adminhtml\Model\Config.php(63): Mage_Adminhtml_Model_Config->_initSectionsAndTabs('C:\aa_work\RueD...')
07#4 C:\aa_work\RueDeSiam\www\app\code\core\Mage\Adminhtml\controllers\System\ConfigController.php(70): Mage_Adminhtml_Model_Config->getSections()
08#5 C:\aa_work\RueDeSiam\www\app\code\core\Mage\Core\Controller\Varien\Action.php(367): Mage_Adminhtml_System_ConfigController->editAction(NULL)
09#6 C:\aa_work\RueDeSiam\www\app\code\core\Mage\Core\Controller\Varien\Router\Admin.php(143): Mage_Core_Controller_Varien_Action->dispatch()
10#7 C:\aa_work\RueDeSiam\www\app\code\core\Mage\Core\Controller\Varien\Front.php(158): Mage_Core_Controller_Varien_Router_Admin->match('edit')
11#8 C:\aa_work\RueDeSiam\www\app\Mage.php(457): Mage_Core_Controller_Varien_Front->dispatch(Object(Mage_Core_Controller_Request_Http))
12#9 C:\aa_work\RueDeSiam\www\index.php(66): Mage::run()
13#10 {main}
the problem with this kind of error is that it doesn’t tell you which file is causing the error. To find out, work with your local installation
  • set the developer mode in index.php : Mage::setIsDeveloperMode(true);
  • open the app/code/core/Mage/Adminhtml/Model/Config.php and let the _initSectionsAndTabs tell you which xml is being loaded in the modules loop, just after $configFile is defined : echo $configFile;
  • the last file that pops before the error is thrown out is likely to cause the breakout !

Wednesday, December 19, 2012

Add First name and last name in newsletters

  >> First add two fields ( subscriber_firstname, subscriber_lastname) in newsletter_subscriber table and app\design\frontend\THEME\default\template\newsletter\subscribe.phtml.

    >> Now edit this page : app\code\core\Mage\Newsletter\controllers\SubscriberController.php
        Here you'll find "public function newAction()"
            Add this Code:-
   
            if ($this->getRequest()->isPost() && $this->getRequest()->getPost('subscriber_firstname'))
            {
                 $email  = (string) $this->getRequest()->getPost('email');
                 $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
                 $name     = (string) $this->getRequest()->getPost('subscriber_firstname');
                 $id  =  $subscriber->getId();
                 $write = Mage::getSingleton('core/resource')->getConnection('core_write');
                 $resource = Mage::getSingleton('core/resource');
                 //$table_prefix = Mage::getConfig()->getTablePrefix();   
                 $productWriteTable = $resource->getTableName('newsletter_subscriber');
               
                 $sql="UPDATE ".$productWriteTable . " SET subscriber_firstname='".$name."' WHERE subscriber_id=$id";
                 $write->query($sql);
            }
            Do same for field Last Name....


    >> The above code will effect your frontend. If you want to see the information from Admin too, you have to implement a little bit.

    Go to this link : app\code\core\Mage\Adminhtml\Block\Newsletter\Subscriber\grid.php

    Add this code :

    $this->addColumn('subscriber_firstname', array(
            'header'    => Mage::helper('newsletter')->__('Subscriber First Name'),
            'index'     => 'subscriber_firstname',
            'default'   =>    '----'
        ));   

Monday, November 19, 2012

IE9 issues with magento checkout disabled credit card fields fix

The fix:
Browse to your /skin/frontend/..template folder (if you’ve got one, if not, browse to the /skin/frontend/default/default/js/ folder). Open up the opcheckout.js file. Around lines 641 AND 647, (inside the switchMethod function), replace :
1
var elements = form.select('input', 'select', 'textarea');
with
1
var elements = form.select('input').concat(form.select('select'), form.select('textarea'));
These 2 lines should fix your IE9 issues, as well as be compatible and work with Chrome/Firefox, earlier builds of IE, and others.

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>