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

Tuesday 8 September 2015

Latest products come first in category magento


Latest products come first in category magento

In magento there is by default product position sort order ASC so the newly added product goes to last and old product remains first. But people wants to latest products first when they visit any category of the site. Here i have used small trick to display newly product in DESC order.

Go to app\code\core\Mage\Catalog\Block\Product\List\Toolbar.php

Find the below function in this file

public function setCollection($collection)
{
    $this->_collection = $collection;

    $this->_collection->setCurPage($this->getCurrentPage());

    // we need to set pagination only if passed value integer and more that 0
    $limit = (int)$this->getLimit();
    if ($limit) {
        $this->_collection->setPageSize($limit);
    }
   
    $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
   

    return $this;
}


And replace this to below one

public function setCollection($collection)
{
    $this->_collection = $collection;

    $this->_collection->setCurPage($this->getCurrentPage());

    // we need to set pagination only if passed value integer and more that 0
    $limit = (int)$this->getLimit();
    if ($limit) {
        $this->_collection->setPageSize($limit);
    }
    if ($this->getCurrentOrder()) {
      if(($this->getCurrentOrder())=='position'){
          $this->_collection->setOrder('entity_id','desc');
      }
      else {
       $this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
      }
    }
    return $this;
}

Monday 7 September 2015

Get category thumbnail image magento


Get category thumbnail image magento

Just try to use below code :

<?php echo Mage::getBaseUrl('media').'catalog/category/'.Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail(); ?>

Example :

<img class="img-responsive" src="<?php echo Mage::getBaseUrl('media').'catalog/category/'.Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail(); ?>"  />

Get all categories with sub-categories in Magento


Get all categories with sub-categories in Magento

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php if (count($_categories) > 0): ?>
    <ul class="nav navbar-nav">
        <?php foreach($_categories as $_category): ?>
            <li class="dropdown dropdown100">
                <a href="<?php echo $_helper->getCategoryUrl($_category) ?>" class="dropdown-toggle">
                    <?php echo $_category->getName() ?>
                </a>
                <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                <?php $_subcategories = $_category->getChildrenCategories() ?>
                <?php if (count($_subcategories) > 0): ?>
                    <ul class="dropdown-menu">
                    <li>
                       <div class="header-navigation-content">
                           <div class="row">
<?php foreach($_subcategories as $_subcategory): ?>
                                    <div class="col-md-2">
                                            <h3><?php echo $_subcategory->getName() ?></h3>
                                            <?php $_subcategories = $_subcategory->getChildrenCategories() ?>
                                            <?php if (count($_subcategories) > 0): ?>
                                                <ul>
                                                    <?php foreach($_subcategories as $_subcategory): ?>
                                                            <li>
                                                                <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
                                                                    <?php echo $_subcategory->getName(); ?>
                                                                </a>  
                                                            </li>
                                                    <?php endforeach; ?>
                                                </ul>
                                            <?php endif; ?>
                                         </div>  
                      <?php endforeach; ?>
                                 </div>  
                            </div>
                        </li>  
                    </ul>
                <?php endif; ?>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>

Friday 28 August 2015

Change discount label shopping cart magento


Change discount label shopping cart magento

Open app\code\core\Mage\SalesRule\Model\Quote\Discount.php and find the below function and change the label where i have changed.

 public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        $amount = $address->getDiscountAmount();

        if ($amount != 0) {
            $description = $address->getDiscountDescription();
            if (strlen($description)) {
                $title = Mage::helper('sales')->__('Total Discount (%s)', $description);
            } else {
                $title = Mage::helper('sales')->__('Total Discount');
            }
            $address->addTotal(array(
                'code'  => $this->getCode(),
                'title' => $title,
                'value' => $amount
            ));
        }
        return $this;
    }

Tuesday 18 August 2015

After add to cart event magento


After add to cart event magento

Sometime we want to give discount after add to cart product or unset/set session after add to cart product for this situation i have created a small script.

Put below code in your module/any module config.xml file after <models> block
<global>
    <events>
        <checkout_cart_product_add_after>
            <observers>
                <Setblue_Banner_Model_Observer>
                    <type>singleton</type>
                    <class>Setblue_Banner_Model_Observer</class>
                    <method>addtocartEvent</method>
                </Setblue_Banner_Model_Observer>
            </observers>
        </checkout_cart_product_add_after>
    </events>
</global>

Next we need to create observer file to read this code. Create Observer.php in /yourmodule/Model/Observer.php and put the below code :

class Setblue_Banner_Model_Observer
{
    public function addtocartEvent(Varien_Event_Observer $observer) {

        // Do something here
        //unset($_SESSION['stitch5']);
/*$event = $observer->getEvent();  //Gets the event
        $product = $event->getProduct();
        $observermsg = "The product added successfully";
        //Adds the message to the shopping cart
        echo Mage::getSingleton('checkout/session')->addSuccess($observermsg);*/
    }

}

Remove custom options shopping cart page magento


Remove custom options shopping cart page magento

Customers can remove custom options which assigned to product while purchase product. Put below code in your template/checkout/cart/item/default.phtml file

<div class="add_btn l">
 <a href="<?php echo $this->getUrl('checkout/cart/'); ?>?id=<?php echo $_item->getId(); ?>"><span class="remove_icon l"></span>REMOVE OPTIONS</a>
</div>

if($_item->getOptions() != ''){
    foreach ($_item->getOptions() as $opt)
    {
        if($_item->getId() == $_REQUEST['id'])
        {
            $opt->delete();
            Mage::app()->getResponse()->setRedirect($this->getUrl('checkout/cart'));
        }
    }
    $_item->setHasOptions(0)->save();
 }

Thats it enjoy chandresh rana coding... :)

Monday 10 August 2015

Shopping Cart Price Rule should not apply discounted products magento


It is obvious things that coupon code should not apply on discount products. But there is no rule and conditions for that in magento. Here i have use a small trick and its work for me. I hope it will be use for needed people also.

Go to shopping cart price rule and click on Actions tab and follow the below image condition.


Friday 7 August 2015

Get category as thery are shown in admin magento


Get category as thery are shown in admin magento

<?php
$categoryCollection = Mage::getModel('catalog/category')->getCollection()->addAttributeToFilter('parent_id', 2)->addAttributeToSort('position');
    foreach($categoryCollection as $_subcategoryCollection):
        $categoryId = $_subcategoryCollection->getEntityId();
        $categoryName = Mage::getModel('catalog/category')->load($categoryId);
        if($categoryName->getIsActive() == 1){
?>
           <li><a href="<?php echo $categoryName->getUrl(); ?>"><?php echo $categoryName->getName(); ?></a></li>

<?php   endif;
endforeach;
?>

Wednesday 5 August 2015

Email To friend does not send mail with Amazon SES Magento


Email To friend does not send mail with Amazon SES Magento

Open app\code\core\Mage\Sendfriend\Model\Sendfriend.php file and find the below code

$sender  = array(
            'name'  => $this->_getHelper()->escapeHtml($this->getSender()->getName()),
            'email' => $this->_getHelper()->escapeHtml($this->getSender()->getEmail())
        );

Replace the above code with below code

$sender  = array(
            'name'  => Mage::getStoreConfig('general/store_information/name'),
            'email' => Mage::getStoreConfig('trans_email/ident_general/email');
        );
     
     
Now check Send to friend email works perfectly. 

Saturday 25 July 2015

Custom tab in customer account navigation magento


Custom tab in customer account navigation magento

If you want to add menu in My account navigation, put below code in your any module layout.xml Magento


Suppose we have My Jobs module...

<customer_account>
   <reference name="customer_account_navigation">
     <action method="addLink" translate="label"

module="quote"><name>quote</name><path>quote/jobs</path><label>My Jobs</label></action>
   </reference>
</customer_account>

<quote_jobs_index translate="label">
    <label>Customer My Account My Wishlist</label>
    <update handle="customer_account"/>
    <reference name="my.account.wrapper">
           <block type="quote/quote" name="quote" template="quote/jobs.phtml"/>
    </reference>
    <reference name="right">
           <action method="unsetChild"><name>quote_customer_sidebar</name></action>
    </reference>
</quote_jobs_index>

Then create JobsController in Your module

That's it... Enjoy Chandresh rana's Coding.... :)

Remove my product reviews from navigation magento


Remove my product reviews from navigation magento

Open the review.xml of your theme layout and comment out below code

<customer_account_index>
    <!-- Mage_Review -->
    <reference name="customer_account_dashboard">
        <block type="review/customer_recent" name="customer_account_dashboard_info1" as="info1" template="review/customer/recent.phtml"/>
    </reference>

</customer_account_index>

Thursday 23 July 2015

Difference between catalog price rules and shopping cart price rules magento


Difference between catalog price rules and shopping cart price rules magento

Catalog Price Rules

Catalog price rules use for products discounts or products sale under certain conditions. Catalog price rules do not use coupon codes, because they are applied after the product add to cart. Discount appears on products.

Shopping Cart Price Rules

Shopping cart price rules can be use for product discount/sale, Customer group wise discount, Attribute wise discount, Country wise discount under the certain conditions. Shopping cart price rules use coupon code but not necessary, you can also create rule without coupon code. Shopping cart price rules always apply on shopping cart when conditions are met. Discount appears on the shopping cart page under the subtotal.

Tuesday 21 July 2015

How to clean log through database Magento


How to clean log through database Magento

Execute this SQL query in to your database

SET foreign_key_checks = 0;
TRUNCATE adminnotification_inbox;
TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;
TRUNCATE catalog_compare_item;
SET foreign_key_checks = 1;

Monday 20 July 2015

INR currency convert issue with CitrusPay payment method in magento


INR currency convert issue with CitrusPay payment method in magento

CitrusPay Only support INR currency so all people have the issue that if customer order in other currency then currency does not convert at CitrusPay page.

Here i have fixed small patch in magento, Just open app\code\community\CitrusPay\Moto\Block\Form\Pay.php file

Find the below line and comment it out

$amount = $order->getGrandTotal();  // Comment it out

Put instead of below line

$amount = $order->getBaseGrandTotal();

Thats it.... Enjoy Chandresh rana's Coding... :)

Friday 17 July 2015

MSP Cash On Delivery charges not add in the grand total Magento


MSP Cash On Delivery charges not add in the grand total Magento

Go to app\code\community\MSP\CashOnDelivery\Model\Quote\Total.php and overwrite the below two function...

public function collect(Mage_Sales_Model_Quote_Address $address)
{
$_helper = Mage::helper('msp_cashondelivery');
if (!$_helper->getSession()->getQuoteId()) return $this;

parent::collect($address);
$_model = Mage::getModel('msp_cashondelivery/cashondelivery');
$quote = $address->getQuote();
$baseAmount = $_model->getBaseExtraFee();
$amount = $_model->getExtraFee();
$baseAmountInclTax = $_model->getBaseExtraFeeInclTax();
$amountInclTax = $_model->getExtraFeeInclTax();
$data = Mage::app()->getRequest()->getPost('payment', array());

if (
($data['method'] == $_model->getCode()) &&
($address->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
) {
$address->setGrandTotal($address->getGrandTotal() + $amount);
$address->setBaseGrandTotal($address->getBaseGrandTotal() + $baseAmount);

$address->setMspCashondelivery($amount);
$address->setMspBaseCashondelivery($baseAmount);
$address->setMspCashondeliveryInclTax($amountInclTax);
$address->setMspBaseCashondeliveryInclTax($baseAmountInclTax);
$quote->setMspCashondelivery($amount);
$quote->setMspBaseCashondelivery($baseAmount);
$quote->setMspCashondeliveryInclTax($amountInclTax);
$quote->setMspBaseCashondeliveryInclTax($baseAmountInclTax);
}

return $this;
}
 
public function fetch(Mage_Sales_Model_Quote_Address $address)
{
$_helper = Mage::helper('msp_cashondelivery');
if (!$_helper->getSession()->getQuoteId()) return $this;

parent::fetch($address);
$_model = Mage::getModel('msp_cashondelivery/cashondelivery');

$amount = $_model->getExtraFeeForTotal();
$data = Mage::app()->getRequest()->getPost('payment', array());

   if ($amount > 0 &&
($data['method'] == $_model->getCode()) &&
($address->getAddressType() == Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
) {
       $address->addTotal(array(
           'code'  => $_model->getCode(),
           'title' => $_helper->__('Cash On Delivery'),
           'value' => $amount,
       ));
}

   return $this;
}

Thursday 16 July 2015

Magento SQLSTATE[22003]: Numeric value out of range: 1690 BIGINT UNSIGNED value is out of range in '(`DATABASE`.`q`.`items_count` - 1)'


Magento SQLSTATE[22003]: Numeric value out of range: 1690 BIGINT UNSIGNED value is out of range in '(`DATABASE`.`q`.`items_count` - 1)'

First of all take the backup of Database and then follow the below steps

(1) Log in to PhpMyAdmin
(2) Select your Magento database
(3) Select the table sales_flat_quote
(4) Select the column ‘items_count’ and remove the ‘UNSIGNED’ attribute
(5) Save the table and re-index your catalog

After the completed to delete products, Re-assigned the  ‘UNSIGNED’ value and Re-index the catalog.

Wednesday 15 July 2015

How to get data from System Configuration Magento


How to get data from System Configuration Magento

You can get the SectionName, GroupName and FieldName in etc/system.xml file of your module.

<?php echo  Mage::getStoreConfig('Section/Group/Field'); ?>

Friday 3 July 2015

Add image on product detail API magento


Add image on product detail API magento

Go to app/code/core/Mage/Catalog/Model/Product/Api.php and replace the below function

public function info($productId, $store = null, $attributes = null, $identifierType = null)
{
    // make sku flag case-insensitive
    if (!empty($identifierType)) {
        $identifierType = strtolower($identifierType);
    }

    $product = $this->_getProduct($productId, $store, $identifierType);
 
    /* Code by chand */
    $GalleryImages = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages();
     if(count($GalleryImages)) {
       foreach($GalleryImages as $simplemediagalleryimage) {
           $image[] = $simplemediagalleryimage->url;
         }
     }
    /* End Code by chand */
 
    $result = array( // Basic product data
        'product_id' => $product->getId(),
        'sku'        => $product->getSku(),
        'set'        => $product->getAttributeSetId(),
        'type'       => $product->getTypeId(),
        'categories' => $product->getCategoryIds(),
        'image' => $image,
        'websites'   => $product->getWebsiteIds()
    );

    foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
        if ($this->_isAllowedAttribute($attribute, $attributes)) {
            $result[$attribute->getAttributeCode()] = $product->getData(
                                                            $attribute->getAttributeCode());
        }
    }

    return $result;
}