Wednesday, 17 December 2014

Show product discount percent in Magento

Open app/design/frontend/yourpackage/yourtheme/template/catalog/product/price.phtml


Find

<?php endif; /* if ($_finalPrice == $_price): */ ?>


Add above it:

<?php // Discount percents output start ?>
    <?php if($_finalPrice < $_price): ?>
    <?php $_savePercent = 100 - round(($_finalPrice / $_price)*100); ?>
        <p class="special-price yousave">
            <span class="label"><?php echo $this->__('You Save:') ?></span>
            <span class="price">
                <?php echo $_savePercent; ?>%
            </span>
        </p>
    <?php endif; ?>
<?php // Discount percent output end ?>

Friday, 28 November 2014

magento set shipping estimate on cart page and get the shipping rates

<?php
$zipcode = '2000'; // Your zipcode
$country = 'GB'; // Your country Id
$cart = Mage::getSingleton('checkout/cart');
$address = $cart->getQuote()->getShippingAddress();
$address->setCountryId($country)->setPostcode($zipcode)->setCollectShippingrates(true);
$cart->save();

$rates = $address->collectShippingRates() ->getGroupedAllShippingRates();
if($rates) {
?>
<form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>" >
<?php
foreach ($rates as $carrier) {
    foreach ($carrier as $rate) {
//echo '<pre>';   print_r($rate->getData()); echo '</pre>';
if($rate->getCode() == "express_express") {  // Only show your custom shipping module
?>
<input name="estimate_method" type="checkbox" value="<?php echo $rate->getCode(); ?>" id="s_method_express_express" onclick="getShipppingCost();"  <?php if($rate->getCode()===$address->getShippingMethod()) echo ' checked="checked"' ?> class="radio">
             <label for="s_method_express_express"><?php echo $this->escapeHtml($rate->getMethodTitle()) ?>
<span class="price"> <?php echo  Mage::helper('core')->currency($rate->getPrice()); ?></span>
</label>
<?php  
}
    }
}

?>
<script>
function getShipppingCost()
{
var methodid= document.getElementById("s_method_express_express");
if(methodid.checked == true)
{ document.getElementById('co-shipping-method-form').submit(); }
else { methodid.value="freeshipping_freeshipping"; methodid.checked = true; document.getElementById('co-shipping-method-form').submit(); }

}

</script>

</form>
<?php } ?>

Thursday, 30 October 2014

magento set all image to thumbnail image

UPDATE catalog_product_entity_media_gallery AS mg,
       catalog_product_entity_media_gallery_value AS mgv,
       catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE  mg.value_id = mgv.value_id
AND mg.entity_id = ev.entity_id
AND ev.attribute_id IN (85,86,87)
AND mgv.position = 1;

Friday, 24 October 2014

php create word document from html

<html
    xmlns:o='urn:schemas-microsoft-com:office:office'
    xmlns:w='urn:schemas-microsoft-com:office:word'
    xmlns='http://www.w3.org/TR/REC-html40'>
    <head>
        <title>My Word Document</title>
       
    <xml>
        <w:WordDocument>
            <w:View>Print</w:View>
            <w:Zoom>100</w:Zoom>
            <w:DoNotOptimizeForBrowser/>
        </w:WordDocument>
    </xml>
 
    <style>
        p.MsoFooter, li.MsoFooter, div.MsoFooter{
            margin: 0cm;
            margin-bottom: 0001pt;
            mso-pagination:widow-orphan;
            font-size: 12.0 pt;
            text-align: right;
        }


        @page Section1{
            size: 29.7cm 21cm;
            margin: 2cm 2cm 2cm 2cm;
            mso-page-orientation: landscape;
            mso-footer:f1;
        }
        div.Section1 { page:Section1;}
    </style>
</head>
<body>
    <div class="Section1">
        <h1>Hello World! This My First</h1>
 
    </div>
</body>
</html>
<?php
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=myfirst.doc");
?>

Friday, 10 October 2014

Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Category_Flat_Collection::joinUrlRewrite() in app/code/local/Mage/Catalog/Block/Navigation.php on line 213

Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Category_Flat_Collection::joinUrlRewrite() in app/code/local/Mage/Catalog/Block/Navigation.php on line 213



This error is coming after upgrade magento to 1.9 CE.



 public function getCurrentChildCategories($sort_by = 'position', $sort_order = 'asc')

    {

        $layer = Mage::getSingleton('catalog/layer');

        $category   = $layer->getCurrentCategory();

        $collection = Mage::getModel('catalog/category')->getCollection();

        $collection->addAttributeToSelect('url_key')

            ->addAttributeToSelect('name')

            ->addAttributeToSelect('image')

            ->addAttributeToSelect('is_anchor')

            ->addAttributeToFilter('is_active', 1)

            ->addAttributeToSort($sort_by, $sort_order)

            ->addIdFilter($category->getChildren())

            ->joinUrlRewrite()

            ->load();



        $productCollection = Mage::getResourceModel('catalog/product_collection');

        $layer->prepareProductCollection($productCollection);

        $productCollection->addCountToCategories($collection);

        return $collection;

    }




change "->joinUrlRewrite()" to "->addUrlRewriteToResult()".

Then it will work fine!!!!!!!!!!!!!!

Thursday, 9 October 2014

Magento Call to a member function toHtml()

magento Call to a member function toHtml() on a non-object in app/code/core/Mage/Core/Model/Layout.php on line 555


Navigate to

\app\design\frontend\default\themename\layout\page.xml


Find
<block type="core/profiler" output="toHtml"/>
Replace with
<block type="core/profiler" output="toHtml" name="core_profiler"/>


Then refresh magento cache, and enjoy!!!!!!!!!!!!



Tuesday, 30 September 2014

Fatal error: Call to a member function toOptionArray() on a non-object in app/code/core/Mage/Adminhtml/Block/System/Config/Form.php on line 463

Go to app\code\core\Mage\Adminhtml\Block\System\Config\Form.php

find the following on line 463

$optionArray = $sourceModel->toOptionArray($fieldType == 'multiselect');
and replace it with the following:

if(is_object($sourceModel)){
$optionArray = $sourceModel->toOptionArray($fieldType == 'multiselect');

Magento Order of loading configure of modules

*Mage_All.xml will be loaded first, and it's module configure in this file will be loaded first
*Mage_*.xml
*.xml
And rest file.xml will be loaded according to the order of the rest file’s name.

Model-View-Controller (MVC)

=> Model
Model is the classes providing data, service related to data and business logic. This class works directly with data and provides data for other elements. In a module, these classes are contained in Model folder.
=> View
View is the classes which define data presented method. These classes are contained in the folder Block of module.
=> Controller
Controller is the classes which control application stream. They receive input which is requirement of users through HTTP request, transfer those requests to the classes which process the requests directly. From the link, Router will get to Controller which controls that link. In Magento module, these classes are contained in controller folder.








How to redirect non-WWW URL to WWW URL

Add the following code on .htaccess file

RewriteEngine On
RewriteCond %{HTTP_HOST}  ^debendramagentoblogspot.com/ [nocase]
RewriteRule ^(.*)         http://www.debendramagentoblogspot.com/$1 [last,redirect=301]

It above one code not worked then add the following code on .htaccess fole

RewriteCond %{HTTP_HOST} ^(?!www\.)(.+) [NC]
RewriteRule ^(.*) http://www.%1/$1 [R=301,NE,L]







Sunday, 31 August 2014

Magento change currency position

See the current format


Changes format

i. Go from your root folder to magento/lib/Zend/Locale/Data
ii. Find the lenguage file. In my case en.xml
iii. Look for <currencyFormatLength>


Before
<currencyFormatLength>
<currencyFormat>
<pattern>¤#,##0.00;(¤#,##0.00)</pattern>
</currencyFormat>
</currencyFormatLength>
After

<currencyFormatLength>
<currencyFormat>
<pattern>#,##0.00¤;(#,##0.00¤)</pattern>
</currencyFormat>
</currencyFormatLength>

Refresh the Magento Cache and enjoy...

Monday, 25 August 2014

Magento How to Display All Products in One Page?

Add the following line on your CMS page where you want to show all products.


{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}




Friday, 22 August 2014

Display the OutofStock configurable products in the frontend - Magento

Display the OutofStock configurable products in the frontend

Go to - app\code\core\Mage\Catalog\Block\Product\View\Type\ Configurable.php

Find the following function -

public function getAllowProducts()
    {
        if (!$this->hasAllowProducts()) {
            $products = array();
            $skipSaleableCheck = Mage::helper('catalog/product')->getSkipSaleableCheck();
            $allProducts = $this->getProduct()->getTypeInstance(true)
                ->getUsedProducts(null, $this->getProduct());
            foreach ($allProducts as $product) {
                if ($product->isSaleable() || $skipSaleableCheck) {
                    $products[] = $product;
                }
            }
            $this->setAllowProducts($products);
        }
        return $this->getData('allow_products');
    }


Replace with -

public function getAllowProducts() {
        $allProducts = $this->getProduct()->getTypeInstance()->getUsedProducts();
        $this->setAllowProducts($allProducts);
        return $this->getData('allow_products');
    }

Magento Add a “mode” to Toolbar and Product Listing

Have done it by myself.

Go to - app/code/core/Mage/Adminhtml/Model/System/Config/Source/Catalog/ListMode.php

Add the highlighted code in this function :


class Mage_Adminhtml_Model_System_Config_Source_Catalog_ListMode
{
    public function toOptionArray()
    {
        return array(
            //array('value'=>'', 'label'=>''),
            array('value'=>'grid', 'label'=>Mage::helper('adminhtml')->__('Grid Only')),
            array('value'=>'list', 'label'=>Mage::helper('adminhtml')->__('List Only')),
array('value'=>'listnew', 'label'=>Mage::helper('adminhtml')->__('List New Only')),
            array('value'=>'grid-list-listnew', 'label'=>Mage::helper('adminhtml')->__('Grid (default) / List / List New')),
            array('value'=>'list-grid-listnew', 'label'=>Mage::helper('adminhtml')->__('List (default) / Grid / List New')),
array('value'=>'listnew-list-grid', 'label'=>Mage::helper('adminhtml')->__('List New (default) / Grid / List')),
        );
    }
}


then go to app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

Add the highlighted code in this function :

 protected function _construct()
    {
        parent::_construct();
        $this->_orderField  = Mage::getStoreConfig(
            Mage_Catalog_Model_Config::XML_PATH_LIST_DEFAULT_SORT_BY
        );

        $this->_availableOrder = $this->_getConfig()->getAttributeUsedForSortByArray();

        switch (Mage::getStoreConfig('catalog/frontend/list_mode')) {
            case 'grid':
                $this->_availableMode = array('grid' => $this->__('Grid'));
                break;

            case 'list':
                $this->_availableMode = array('list' => $this->__('List'));
                break;

case 'listnew':
                $this->_availableMode = array('listnew' => $this->__('List New Only'));
                break;

            case 'grid-list-listnew':
                $this->_availableMode = array('grid' => $this->__('Grid'), 'list' =>  $this->__('List'), 'listnew' =>  $this->__('List New Only'));
                break;

            case 'list-grid-listnew':
                $this->_availableMode = array('list' => $this->__('List'), 'grid' => $this->__('Grid'), 'listnew' =>  $this->__('List New Only'));
                break;


case 'listnew-list-grid':
                $this->_availableMode = array('listnew' =>  $this->__('List New Only'), 'list' => $this->__('List'), 'grid' => $this->__('Grid'));
                break;
        }
        $this->setTemplate('catalog/product/list/toolbar.phtml');
    }

Then select the list mode in admin panel

Admin - System - Configuration - Catalog - Frontend
change the list mode there.







Friday, 18 July 2014

Magento Delete all orders and customer data

Please make sure that keep backup of your magento database before running this query.



SET FOREIGN_KEY_CHECKS=0;
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;
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;
TRUNCATE `eav_entity_store`;
ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

Sunday, 6 April 2014

Magento admin panel template hints

1st Time

INSERT INTO core_config_data (scope, scope_id, path, value)
VALUES ('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1);


Deactivate
_______________________________
UPDATE core_config_data set value = 0 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints';


2nd Time
____________________________
UPDATE core_config_data set value = 1 where scope = 'default' and scope_id = 0 and path ='dev/debug/template_hints';

Thursday, 27 March 2014

How to set minimum quantity in magento cart?

Go to app\design\frontend\base\default\template\checkout\onepage\link.phtml


Put this code in this page


<?php if ($this->isPossibleOnepageCheckout()):?>
<?php if(Mage::helper('checkout/cart')->getCart()->getItemsQty() >= 3):?>
    <button type="button" title="<?php echo $this->__('Proceed to Checkout') ?>" class="button btn-proceed-checkout btn-checkout<?php if ($this->isDisabled()):?> no-checkout<?php endif; ?>"<?php if ($this->isDisabled()):?> disabled="disabled"<?php endif; ?> onclick="window.location='<?php echo $this->getCheckoutUrl() ?>';"><span><span><?php echo $this->__('Proceed to Checkout') ?></span></span></button>
<?php else:?>
<font style="color:red;">You must order a quantity of 3 or more to proceed.</font>
<?php endif?>
<?php endif?>


Then put this code into header.phtml page

<input type="hidden" id="get_cart" value="<?php echo Mage::helper('checkout/cart')->getCart()->getItemsQty(); ?>" />
<script type='text/javascript'>
        jQuery(document).ready(function() {
if(document.getElementById("get_cart").value < 3) {
jQuery(".top-link-checkout").attr("href", "javascript:void(0);")
}
        });

</script>

Then enjoy!!!!!!!!!!!!!!

Thursday, 13 March 2014

magento index.php was not found on this server error


If the magento installed under /magento or directory then add the following rules into ” /home/username/public_html/magento/.htaccess ” file.


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /magento/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /magento/index.php [L]
</IfModule>


Now Enjoy!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




Tuesday, 18 February 2014

Magento Configuration product wrong price issues in create new order


1) Go to app\code\core\Mage\Sales\Model\Quote\Item\ then open Abstract.php page.
2) Write the following code in the public function getPrice() (line no - 484)


$_Pdetails = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->_getData('sku'));
 return $_Pdetails->getFinalPrice();


Code should be


public function getPrice()
    {
$_Pdetails = Mage::getModel('catalog/product')->loadByAttribute('sku',$this->_getData('sku'));
                return $_Pdetails->getFinalPrice();  // Debendra on 17/02/2014
       /* Orginal Code
return $this->_getData('price');
*/
    }



Now the correct product price is going to show in the admin panel, when you create one order (Phone order).

Wednesday, 22 January 2014

Magento Tax Round Issue

Go to app\code\core\Mage\Core\Model\Store.php

Find the following function


 public function roundPrice($price)
    {
        return round($price, 2);
    }

Change to:-


public function roundPrice($price)
    {
        return round($price, 4);
    }



Enjoy..........