Wednesday, 29 August 2012

Magento: Category Flat Data reindexing

Magento: Category Flat Data reindex


 

 

 

The reason for this issue is because the dabase migration cross over the server, the index was changed during the migration. 


ALTER TABLE catalog_category_entity ENGINE=INNODB;
ALTER TABLE core_store ENGINE=INNODB;

How to solve indexing problem?

DROP TABLE IF EXISTS `index_process_event`;
DROP TABLE IF EXISTS `index_event`;
DROP TABLE IF EXISTS `index_process`;


CREATE TABLE `index_event` (
`event_id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`type` VARCHAR(64) NOT NULL,
`entity` VARCHAR(64) NOT NULL,
`entity_pk` BIGINT(20) DEFAULT NULL,
`created_at` DATETIME NOT NULL,
`old_data` MEDIUMTEXT,
`new_data` MEDIUMTEXT,
PRIMARY KEY (`event_id`),
UNIQUE KEY `IDX_UNIQUE_EVENT` (`type`,`entity`,`entity_pk`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

CREATE TABLE `index_process` (
`process_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`indexer_code` VARCHAR(32) NOT NULL,
`status` ENUM('pending','working','require_reindex') NOT NULL DEFAULT 'pending',
`started_at` DATETIME DEFAULT NULL,
`ended_at` DATETIME DEFAULT NULL,
`mode` ENUM('real_time','manual') NOT NULL DEFAULT 'real_time',
PRIMARY KEY (`process_id`),
UNIQUE KEY `IDX_CODE` (`indexer_code`)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

INSERT INTO `index_process`(`process_id`,`indexer_code`,`status`,`started_at`,`ended_at`,`mode`) VALUES (1,'catalog_product_attribute','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(2,'catalog_product_price','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(3,'catalog_url','pending','2010-02-13 19:12:15','2010-02-13 19:12:15','real_time'),(4,'catalog_product_flat','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(5,'catalog_category_flat','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(6,'catalog_category_product','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(7,'catalogsearch_fulltext','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time'),(8,'cataloginventory_stock','pending','2010-02-13 00:00:00','2010-02-13 00:00:00','real_time');

CREATE TABLE `index_process_event` (
`process_id` INT(10) UNSIGNED NOT NULL,
`event_id` BIGINT(20) UNSIGNED NOT NULL,
`status` ENUM('new','working','done','error') NOT NULL DEFAULT 'new',
PRIMARY KEY (`process_id`,`event_id`),
KEY `FK_INDEX_EVNT_PROCESS` (`event_id`),
CONSTRAINT `FK_INDEX_EVNT_PROCESS` FOREIGN KEY (`event_id`) REFERENCES `index_event` (`event_id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `FK_INDEX_PROCESS_EVENT` FOREIGN KEY (`process_id`) REFERENCES `index_process` (`process_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=INNODB DEFAULT CHARSET=utf8;

My Top Project

1. www.pochaleather.com.au
2. www.coachmkt.com
   (A)www.outdoorcompanion.com
   (B)www.giftsandknickknacks.com
   (C)www.allwaysadeal.com
   (D)www.decoratorsartgallery.com
   (E)www.wristwatchuniverse.com


3. www.wbscience.com
   (A)www.willowdalebotanicalscience.com
   (B)www.celluvati.com


4. http://www.pochaleather.com.au

5. http://www.groupmarketingservices.com.au/
6. http://distinctiveconfectionery.com/
7. http://rebellowines.com.au/
8. http://www.acupressuremat.com.sg/
9. http://lanakin.com/
10. https://sayuripreview3.gostorego.com
11. http://alizasboutique.com/
12. http://trinitystarelectronics.gostorego.com/
13. http://www.gbwearcanada.com/
14. http://grindz.gostorego.com/

Wednesday, 22 August 2012

Display Price Or Special Price

 Display Price Or Special Price  :-

  1. htmlEscape($_product->getSpecialPrice()), 2) ?>

   2. htmlEscape($_product->getPrice()), 2) ?>

 

Active Class in magento


Active Class In Menu :-

class="getCurrentUrl(),'home') != false ) :?>active"

-------------------------------------------------------------------------------------------------------------------------------

Match URL :-

http://www.sainisamaj.co.in/home.php

 if (strpos(Mage::helper('core/url')->getCurrentUrl(),'home') != false )
  {
 
  echo "Yes";
 
 } else {

 echo "No";

  } ?>

Tuesday, 21 August 2012

How to connection database

 
    $resource   = Mage::getSingleton('core/resource');
    $conn       = $resource->getConnection('externaldb_read');
    $results    = $conn->query('SELECT * FROM tblName');
 
    print_r($results)
 
?>

Thursday, 16 August 2012

How to Add Custom Field in the Billing and Shipping Address of Onepage Checkout in Magento

I have created the module for adding the new custom field in the Billing and Shipping address of the Onepage checkout. All the code of the module is given below.
Step: – 1
Add Custom Field into Billing Address tab of the Onepage Checkout in Frontend.
app\design\frontend\[Package_name]\[Theme_name]\template\checkout\onepage\billing.phtml


1
  • class="wide">
  • 2
    3
    class="input-box">
    4"text" id="billing:jobtitle" name="billing[jobtitle]" value="htmlEscape($this->getAddress()->getJobtitle()) ?>" title="__('Job Title') ?>" class="input-text" />
    5
    6
                     

    Step: – 2
    Add Custom Field into Shipping Address tab of the Onepage Checkout in Frontend.
    app\design\frontend\[Package_name]\[Theme_name]\template\checkout\onepage\shipping.phtml


        1
  • class="wide">
  • 2
    3
    class="input-box">
    4"text" id="shipping:jobtitle" name="shipping[jobtitle]" value="htmlEscape($this->getAddress()->getJobtitle()) ?>" title="__('Job Title') ?>" class="input-text" onchange="shipping.setSameAsBilling(false);" />
    5
    6
     

    Step: – 3
    Add Custom Field into Customer Address Edit tab in Frontend.
    app\design\frontend\[Package_name]\[Theme_name]\template\customer\address\edit.phtml



    1
  • class="wide">
  • 2
    3
    class="input-box">
    4"text" name="jobtitle" id="jobtitle" title="__('Job Title') ?>" value="htmlEscape($this->getAddress()->getJobtitle()) ?>" class="input-text" />
    5
    6


    Step: – 4


    I have made some changes to the Address Templates in Magento Admin. if you are using Magento Version 1.3.2.4 then you have to made changes in the following file.
    app/code/core/Mage/Customer/etc/config.xml
    and if you are using Magento Upper Version than 1.3.2.4 then you can chage from the Admin panel of the Magento as given following path.
    System->Configuration->Customers->Customer Configurations->Address Templates
    Add following code in the “Text” Textarea.
    01{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}
    02    {{depend company}}{{var company}}{{/depend}}
    03    {{depend jobtitle}}{{var jobtitle}}{{/depend}}
    04    {{if street1}}{{var street1}}
    05    {{/if}}
    06    {{depend street2}}{{var street2}}{{/depend}}
    07    {{depend street3}}{{var street3}}{{/depend}}
    08    {{depend street4}}{{var street4}}{{/depend}}
    09    {{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}
    10    {{var country}}
    11    T: {{var telephone}}
    12    {{depend fax}}F: {{var fax}}{{/depend}}
    Step: – 5
    I have made some changes to the Address Templates in Magento Admin. if you are using Magento Version 1.3.2.4 then you have to made changes in the following file.
    app/code/core/Mage/Customer/etc/config.xml
    and if you are using Magento Upper Version than 1.3.2.4 then you can chage from the Admin panel of the Magento as given following path.
    System->Configuration->Customers->Customer Configurations->Address Templates
    Add following code in the “HTML” Textarea.
    01{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}<br/>
    02{{depend company}}{{var company}}<br />{{/depend}}
    03{{depend jobtitle}}{{var jobtitle}}<br />{{/depend}}
    04{{if street1}}{{var street1}}<br />{{/if}}
    05{{depend street2}}{{var street2}}<br />{{/depend}}
    06{{depend street3}}{{var street3}}<br />{{/depend}}
    07{{depend street4}}{{var street4}}<br />{{/depend}}
    08{{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}<br/>
    09{{var country}}<br/>
    10{{depend telephone}}T: {{var telephone}}{{/depend}}
    11{{depend fax}}<br/>F: {{var fax}}{{/depend}}


    Step: – 6



    I have made some changes to the Address Templates in Magento Admin. if you are using Magento Version 1.3.2.4 then you have to made changes in the following file.
    app/code/core/Mage/Customer/etc/config.xml
    and if you are using Magento Upper Version than 1.3.2.4 then you can chage from the Admin panel of the Magento as given following path.
    System->Configuration->Customers->Customer Configurations->Address Templates
    Add following code in the “PDF” Textarea.
    01{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}|
    02{{depend company}}{{var company}}|{{/depend}}
    03{{depend jobtitle}}{{var jobtitle}}|{{/depend}}
    04{{if street1}}{{var street1}}
    05{{/if}}
    06{{depend street2}}{{var street2}}|{{/depend}}
    07{{depend street3}}{{var street3}}|{{/depend}}
    08{{depend street4}}{{var street4}}|{{/depend}}
    09{{if city}}{{var city}},  {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}|
    10{{var country}}|
    11{{depend telephone}}T: {{var telephone}}{{/depend}}|
    12{{depend fax}}<br />F: {{var fax}}{{/depend}}|
    I have created the separate module for adding Custom Field into Billing and Shipping Address in Frontend and Backend of the Magento Store.


    Step: – 7


    app\etc\modules\Tdg_All.xml
    First of all create file with above given name and put following code into that file.
    1xml version="1.0" encoding="UTF-8"?>
    2<config>
    3    <modules>
    4        <Tdg_Check>
    5            <active>true</active>
    6            <codePool>local</codePool>
    7        </Tdg_Check>
    8    </modules>
    9</config>
    Step: – 8
    app\code\local\Tdg\Check\etc\ config.xml
    01xml version="1.0" encoding="UTF-8"?>
    02<config>
    03    <modules>
    04        <Tdg_Check>
    05            <version>1.0.0</version>
    06        </Tdg_Check>
    07    </modules>
    08    <admin>
    09        <fieldsets>
    10            <customer_dataflow>
    11                <jobtitle><billing>1</billing><shipping>1</shipping></jobtitle>
    12            </customer_dataflow>
    13        </fieldsets>
    14    </admin>
    15    <global>
    16        <models>
    17            <check>
    18                <class>Tdg_Check_Model</class>
    19            </check>
    20        </models>
    21        <resources>
    22            <check_setup>
    23                <setup>
    24                    <module>Tdg_Check</module>
    25                </setup>
    26                <connection>
    27                    <use>core_setup</use>
    28                </connection>
    29            </check_setup>
    30            <check_write>
    31                <connection>
    32                    <use>core_write</use>
    33                </connection>
    34            </check_write>
    35            <check_read>
    36                <connection>
    37                    <use>core_read</use>
    38                </connection>
    39            </check_read>
    40        </resources>
    41        <fieldsets>
    42            <sales_copy_order_billing_address>
    43                <jobtitle><to_order>*</to_order></jobtitle>
    44            </sales_copy_order_billing_address>
    45            <sales_copy_order_shipping_address>
    46                <jobtitle><to_order>*</to_order></jobtitle>
    47            </sales_copy_order_shipping_address>
    48            <sales_convert_quote_address>
    49                <jobtitle><to_order_address>*</to_order_address><to_customer_address>*</to_customer_address></jobtitle>
    50            </sales_convert_quote_address>
    51            <sales_convert_order_address>
    52                <jobtitle><to_quote_address>*</to_quote_address></jobtitle>
    53            </sales_convert_order_address>
    54            <customer_address>
    55                <jobtitle><to_quote_address>*</to_quote_address></jobtitle>
    56            </customer_address>
    57            <checkout_onepage_billing>
    58                <jobtitle><to_customer>*</to_customer></jobtitle>
    59            </checkout_onepage_billing>
    60        </fieldsets>
    61    </global>
    62</config>



    Step: – 9
     

    app\code\local\Tdg\Check\sql\check_setup\ mysql4-install-1.0.0.php
    01
    02    /* @var $installer Mage_Customer_Model_Entity_Setup */
    03    $installer = $this;
    04    $installer->startSetup();
    05    /* @var $addressHelper Mage_Customer_Helper_Address */
    06    $addressHelper = Mage::helper('customer/address');
    07    $store         = Mage::app()->getStore(Mage_Core_Model_App::ADMIN_STORE_ID);
    08 
    09    /* @var $eavConfig Mage_Eav_Model_Config */
    10    $eavConfig = Mage::getSingleton('eav/config');
    11 
    12    // update customer address user defined attributes data
    13    $attributes = array(
    14        'jobtitle'           => array(
    15            'label'    => 'Job Title',
    16            'backend_type'     => 'varchar',
    17            'frontend_input'    => 'text',
    18            'is_user_defined'   => 1,
    19            'is_system'         => 0,
    20            'is_visible'        => 1,
    21            'sort_order'        => 140,
    22            'is_required'       => 1,
    23            'multiline_count'   => 0,
    24            'validate_rules'    => array(
    25                'max_text_length'   => 255,
    26                'min_text_length'   => 1
    27            ),
    28        ),
    29    );
    30 
    31    foreach ($attributes as $attributeCode => $data) {
    32        $attribute = $eavConfig->getAttribute('customer_address', $attributeCode);
    33        $attribute->setWebsite($store->getWebsite());
    34        $attribute->addData($data);
    35            $usedInForms = array(
    36                'adminhtml_customer_address',
    37                'customer_address_edit',
    38                'customer_register_address'
    39            );
    40            $attribute->setData('used_in_forms', $usedInForms);
    41        $attribute->save();
    42    }
    43 
    44    $installer->run("
    45        ALTER TABLE {$this->getTable('sales_flat_quote_address')} ADD COLUMN `jobtitle` VARCHAR(255) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`;
    46         ALTER TABLE {$this->getTable('sales_flat_order_address')} ADD COLUMN `jobtitle` VARCHAR(255) CHARACTER SET utf8 DEFAULT NULL AFTER `fax`;
    47        ");
    48    $installer->endSetup();
    49?>

    Add custom field in contact us form in magento


    Steps for adding a custom field in the default Contact Us form are given below:
    Step 1: Update the Contact Us form
    First you have to edit the form.phtml file form template. which is located in (For default theme):
    app/design/frontend/base/default/template/contacts/form.phtml
    Now open the form.phtml file Add the following code in the desired position:
    1. <div class="field">
    2.     <label for="name-frefix" class="required"><em>*</em>('contacts')->
    __('Name Prefix') ?></label>
  •     <div class="input-box">
  •            <select name="name-prefix" id="name-prefix" style="width:200px" class="required-entry">
  •                 <option value="" selected>Please select...</option>
  •                 <option value="mr">Mr.</option>
  •                 <option value="mrs">Mrs.</option>
  •             </select>
  •     </div>
  • </div>
  • Note: Here i used above code for my requirment. You should use code as your requirment. I used class=”required-entry” on the above code. This tells to the javascript validation that this field is required.
    Step 2: Create a custom transactional email template for Contact Form
    Now you need to create a custom email template for contact form with include the new field. To do this-
    Go: System -> Transactional Emails from Magento backend. then follw:
    1. Click on the Add New Template button
    2. From Load default template section, select “Contact Form” from the dropdwn list and click Load Template button.
    3. In the Template Information section, set the Template Name to “Custom Contact Form
    4. In the Template Content field, add the Name Prefix: {{var data.name-prefix}} line which is like:

    Now click on the Save Config button.
    Step 3: Assign the Custom template for Contact Us
    Now you have to assign Custom templete for your Contact Us form. To do this-
    Go: System -> Configuration . Then click on the Contacts tab from left panel under the General.
    In the Email Options section, set the Email Template to “Custom Contact Form”. which like-

    After that click on the Save Config button and you’re all done.

    Delete All Orders and Customers

    SET FOREIGN_KEY_CHECKS=0;
     
    -- Here's where we reset the orders 
    TRUNCATE `sales_flat_order`;
    TRUNCATE `sales_flat_order_address`;
    TRUNCATE `sales_flat_order_grid`;
    TRUNCATE `sales_flat_order_item`;
    TRUNCATE `sales_flat_order_status_history`;
    TRUNCATE `sales_flat_quote`;
    TRUNCATE `sales_flat_quote_address`;
    TRUNCATE `sales_flat_quote_address_item`;
    TRUNCATE `sales_flat_quote_item`;
    TRUNCATE `sales_flat_quote_item_option`;
    TRUNCATE `sales_flat_order_payment`;
    TRUNCATE `sales_flat_quote_payment`;
    TRUNCATE `sales_flat_shipment`;
    TRUNCATE `sales_flat_shipment_item`;
    TRUNCATE `sales_flat_shipment_grid`;
    TRUNCATE `sales_flat_invoice`;
    TRUNCATE `sales_flat_invoice_grid`;
    TRUNCATE `sales_flat_invoice_item`;
    TRUNCATE `sendfriend_log`;
    TRUNCATE `tag`;
    TRUNCATE `tag_relation`;
    TRUNCATE `tag_summary`;
    TRUNCATE `wishlist`;
    TRUNCATE `log_quote`;
    TRUNCATE `report_event`;
     
    ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
    ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
    ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
    ALTER TABLE `tag` AUTO_INCREMENT=1;
    ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
    ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
    ALTER TABLE `wishlist` AUTO_INCREMENT=1;
    ALTER TABLE `log_quote` AUTO_INCREMENT=1;
    ALTER TABLE `report_event` AUTO_INCREMENT=1;
     
    -- Here's where we reset the customers
    TRUNCATE `customer_address_entity`;
    TRUNCATE `customer_address_entity_datetime`;
    TRUNCATE `customer_address_entity_decimal`;
    TRUNCATE `customer_address_entity_int`;
    TRUNCATE `customer_address_entity_text`;
    TRUNCATE `customer_address_entity_varchar`;
    TRUNCATE `customer_entity`;
    TRUNCATE `customer_entity_datetime`;
    TRUNCATE `customer_entity_decimal`;
    TRUNCATE `customer_entity_int`;
    TRUNCATE `customer_entity_text`;
    TRUNCATE `customer_entity_varchar`;
    TRUNCATE `log_customer`;
    TRUNCATE `log_visitor`;
    TRUNCATE `log_visitor_info`;
     
    ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
    ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
    ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
    ALTER TABLE `log_customer` AUTO_INCREMENT=1;
    ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
    ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
     
    -- This is to Reset all the ID counters
    TRUNCATE `eav_entity_store`;
    ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;
     
    SET FOREIGN_KEY_CHECKS=1;