Pages

Showing posts with label Magento. Show all posts
Showing posts with label Magento. Show all posts

Magento 1.9 - PLP Page sort by ASC order

For Temporary:

Paste below code into Backend Magento category -> Custom Design -> Custom Layout Update section:

 
 <reference name="product_list">  
      <action method="setDefaultDirection"><dir>asc</dir></action>  
 </reference>  
  

For Permanent :

 Add following code to app/design/frontend/default/theme/layout/local.xml

 <?xml version="1.0"?>  
 <layout version="0.1.0">  
   <!-- Change default direction for simple searches -->  
   <catalogsearch_result_index>  
     <reference name="search_result_list">  
       <action method="setDefaultDirection"><dir>asc</dir></action>  
     </reference>  
   </catalogsearch_result_index>  
   <!-- Change default direction for advanced searches -->  
   <catalogsearch_advanced_result>  
     <reference name="search_result_list">  
       <action method="setDefaultDirection"><dir>asc</dir></action>  
     </reference>  
   </catalogsearch_advanced_result>  
   <!-- Change default direction for a category without layered navigation -->  
   <catalog_category_default>  
     <reference name="product_list">  
       <action method="setDefaultDirection"><dir>asc</dir></action>  
     </reference>  
   </catalog_category_default>  
   <!-- Change default direction for a category with layered navigation -->  
   <catalog_category_layered>  
     <reference name="product_list">  
       <action method="setDefaultDirection"><dir>asc</dir></action>  
     </reference>  
   </catalog_category_layered>  
  </layout>  

Magento 1 - Get Payment Methods (code) using Observer.

The following code return payment methods code,
<?php
    class Gta_FindPaymentGateway_Model_Observer
    {
        public function paymenter($Observer)
        {
           $allPaymentMethods = Mage::getModel('payment/config')->getAllMethods();

           foreach($allPaymentMethods as $paymentMethod)
           {
                Mage::log($paymentMethod->getCode(),null,'filter.log',true);
           }
        }
    }
?>

Magento 1.9 - Find what event using in Observer.

Following code return what event used in the observer,

app\etc\modules\Gta_FindPaymentGateway.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Gta_FindPaymentGateway>
            <codePool>local</codePool>
            <active>true</active>
        </Gta_FindPaymentGateway>
    </modules>
</config>

app\code\local\Gta\FindPaymentGateway\etc\config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Gta_FindPaymentGateway>
            <version>1.0.0</version>
        </Gta_FindPaymentGateway>
    </modules>
    <global> 
        <models>
            <gta_findpaymentgateway>
                <class>Gta_FindPaymentGateway_Model</class>
            </gta_findpaymentgateway>
        </models> 
        <events>
            <checkout_cart_product_add_after>
                <observers>
                    <Gta_FindPaymentGateway_Model_Observer>   
                        <type>singleton</type>
                        <class>Gta_FindPaymentGateway_Model_Observer</class>
                        <method>paymenter</method>
                    </Gta_FindPaymentGateway_Model_Observer>
                </observers>
            </checkout_cart_product_add_after>      
        </events>
    </global> 
</config>

app\code\local\Gta\FindPaymentGateway\Model\Observer.php

<?php
    class Gta_FindPaymentGateway_Model_Observer
    {
        public function paymenter($Observer)
        {
            $order = $Observer->getEvent();
            Mage::log($order->getName(),null,'eventsss.log',true);
        }
    }
?>

Magento 1.9 - Find what are all functions overwritten magento core function?

Create file into your Magento root folder with the name of find.php and run,


 <?php  
 $foldersToCheck = array('app/code/local/', 'app/code/community/');  
 $configFiles = array();  
 foreach ($foldersToCheck as $folder){  
   $files = glob($folder.'*/*/etc/config.xml');//get all config.xml files in the specified folder  
   $configFiles = array_merge($configFiles, $files);//merge with the rest of the config files  
 }  
 $rewrites = array();//list of all rewrites  
 foreach ($configFiles as $file){  
   $dom = new DOMDocument;  
   $dom->loadXML(file_get_contents($file));  
   $xpath = new DOMXPath($dom);  
     $path = '//rewrite/*';//search for tags named 'rewrite'  
     $text = $xpath->query($path);  
     foreach ($text as $rewriteElement){  
       $type = $rewriteElement->parentNode->parentNode->parentNode->tagName;//what is overwritten (model, block, helper)  
       $parent = $rewriteElement->parentNode->parentNode->tagName;//module identifier that is being rewritten (core, catalog, sales, ...)  
       $name = $rewriteElement->tagName;//element that is rewritten (layout, product, category, order)  
       foreach ($rewriteElement->childNodes as $element){  
         $rewrites[$type][$parent.'/'.$name][] = $element->textContent;//class that rewrites it  
       }  
     }  
 }  
 echo "<pre>";print_r($rewrites);  
 ?>  

Magento 1.9 - Add Discount Percentage Below Price

Copy price.phtml from :

app/design/frontend/base/default/template/catalog/product/price.phtml

Paste price.phtml to :

app/design/frontend/default/theme/template/catalog/product/price.phtml

Find :

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

Add above it:

    <!-- start custom code  -->

     <?php // Discount percents output start 
     $_finalPrice=$_product->getFinalPrice(); 
     $_price=$_product->getPrice();?>

    <?php if($_finalPrice < $_price): ?>
    <?php $_savePercent = 100 - round(($_finalPrice / $_price)*100); ?>
    <?php echo "Your Savings ".$_savePercent; ?>%
    <?php endif; ?>
    <?php // Discount percent output end ?>


    <!-- end custom code  -->





How to fix Magento 1.9 Email sending problem

In the latest Magento versions, all emails are being sent via CRON job.
Every email will be queued and sent will depend on the set interval.


By default, Magento has already set CRON jobs at 
System -> Configuration -> Advanced -> System -> Advanced -> Cron


If the CRON job is not working properly, please follow the following steps to send instant emails.


Copy Template.php file from 
app -> code -> core -> Mage -> Core -> Model -> Email


Create folder structure like 
app -> code -> local ->  Mage -> Core -> Model -> Email


Paste Template.php file in an Email folder


Open Template.php file and go to line number 407 or search for the following code 
 if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {


Replace above code with following
 if (!($this->hasQueue()) && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {


This trick works perfectly on Magento Version 1.9.2.0

Difference between Mage::getResourceModel() vs Mage::getModel() vs Mage::getSingleton() in Magento


Mage::getSingleton()

Mage::getSingleton() will first check if the same class instance exists or not in the memory. If the instance exists then it will return the same object from the memory. So Mage::getSingleton() is faster than Mage::getModel().

Example

$product1 = Mage::getSingleton('catalog/product');
$product2 = Mage::getSingleton('catalog/product');
$product1 and $product2 both will share same memory of OS and return only one instance each time.

Mage::getModel()

Mage::getModel() will create a new instance of an object each time even such an object exists in the configuration.

Example

$product1 = Mage::getModel('catalog/product');
$product2 = Mage::getModel('catalog/product');
$product1 and $product2 both have different instant of same object and also occupy different memory

Mage::getResourceModel()

As far as I know, all collections in Magento are resource models. They are instantiated by

Mage::getResourceModel()

or

Mage::getModel()->getCollection()

It doesn't really matter which function you use; the latter one simply calls the first one. The Magento team simply chose to make collections part of the resource, probably because collections need to query the database a lot. Usually, you will not have to call Mage::getResourceModel() for anything else than collections.

Mahento 1.9 : Check Available Shipping Methods with website filter

Check Available Shipping Methods with website filter



<?php
require_once('app/Mage.php');
umask(0);
Mage::app();

### Start website filter ###
$website_id = Mage::app()->getWebsite(2)->getDefaultGroup()->getDefaultStoreId();
Mage::app()->setCurrentStore($website_id);
### End website filter ###

$methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
$shipMethods = array();
foreach ($methods as $shippigCode=>$shippingModel)
{
$shippingTitle = Mage::getStoreConfig('carriers/'.$shippigCode.'/title');
$shipMethods[$shippigCode] = $shippingTitle;
}
Mage::log($shipMethods, null, 'logfile.log');
?>

Mage::log : Magento Log Test

Save below file as test.php into the root folder and run with cmd finally check the log file

 <?php

require 'app/Mage.php';

Mage::app();

Mage::log('Hy observer called', null, 'obZ_logfile.log');

?>

Magento Current Stock Status PHP Script

<?php
ini_set("display_error",1);
// error_log("auto");
error_reporting(E_ALL);
$dabas = mysqli_connect("localhost","root","","dbname");

if($dabas == false)
{
die("Error: Could Not Connect." .mysqli_connect_error());
}

$sql = "SELECT cpe.sku AS Sku, cpev.value AS NAME, cssi.qty AS Qty, cssi.stock_status AS STATUS
FROM cataloginventory_stock_status_idx cssi
JOIN catalog_product_entity_varchar cpev ON cssi.product_id = cpev.entity_id
JOIN catalog_product_entity cpe  ON  cssi.product_id = cpe.entity_id
WHERE cpev.attribute_id = 98 AND cpev.store_id = 4 limit 10 ";
  if($res = mysqli_query($dabas, $sql)){
if(mysqli_num_rows($res) > 0){
echo "<table>";
echo "<tr>";
echo "<th>Sku :</th>";
echo "<th>Name : </th>";
echo "<th>Qty : </th>";
echo "<th>Stock Status : </th>";
echo "</tr>";


while($row = mysqli_fetch_array($res)){
echo "<tr>";
echo "<td>".$row['Sku']."</td>";
echo "<td>".$row['NAME']."</td>";
echo "<td>".$row['Qty']."</td>";
echo "<td>".$row['STATUS']."</td>";
}
echo "</table>";
mysqli_free_res($res);
}

else {
echo "No Matching Record are Found";
}
}
else {
echo "Error : Could not be able to excute $sqlgta. " .mysqli_error($dabas);
}
mysql_close($dabas);
?>

magento site: Most Downloaded FREE Magento Extensions

magento site: Most Downloaded FREE Magento Extensions: MagentoConnect Manager 253356 Modern Theme 93723 Fontis WYSIWYG Editor 48093 Magento Community Modules – German (Germany) Lang...

Developer's Group: How to get category id by category name in magent...

Developer's Group: How to get category id by category name in magent...: <&#63php $category = Mage::getResourceModel('catalog/category_collection')->addFieldToFilter('name','cateNam...

Developer's Group: how to upload any file in magento

Developer's Group: how to upload any file in magento: Step 1 :- cretae html form for upload file Upload File Upload File Step 2 :- Write Script for upload file <...

Developer's Group: Disable admin notification popup in Magento

Developer's Group: Disable admin notification popup in Magento: Every time you log in to the Magento Admin Panel, you see an admin notification popop message telling you there's a new Magento version...

Developer's Group: Add Product Images In Magento Transactional Emails...

Developer's Group: Add Product Images In Magento Transactional Emails...: In order to add the order Image to the transaction email templates (order), you need to play with the following two files: 1.) Edit the fil...

Developer's Group: How to Show product options in product list page i...

Developer's Group: How to Show product options in product list page i...: In this article, we will recommend some effective methods to show options for the configurable and product options in product list. Check th...

Developer's Group: How to send custom attribute in magento Order emai...

Developer's Group: How to send custom attribute in magento Order emai...: Recently i was working on a project and my client want to send a custom shipping note in order email. So lets's see how to achieve thi...