Archive for the ‘How To?’ Category

Cron job not working

Posted: February 4, 2015 in How To?, Magento

Setup the cron job:

Test it by running on the browser

Not working?

  • Open the Magento cron.php file in a text editor.
  • Locate the block
    $disabledFuncs = explode(',', ini_get('disable_functions'));
    $isShellDisabled = is_array($disabledFuncs) ? in_array('shell_exec', $disabledFuncs) : true;
    $isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;
  • Copy the following line of code and paste it after the code block you located in step 2:
    $isShellDisabled = true;
Advertisements

Sort product list by stock

Posted: February 2, 2015 in How To?, Magento
Tags: ,

Use

$this->_productCollection = $layer->getProductCollection()->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id','is_in_stock>=0', 'left')->setOrder('inventory_in_stock','desc');

If you want to just list Out of Stock products use:

$collection->joinField('inventory_in_stock', 'cataloginventory_stock_item', 'is_in_stock', 'product_id=entity_id','{{table}}.is_in_stock=0');

Delete Orders and Data

Posted: January 27, 2015 in Extensions, How To?, Magento
Tags: , ,

Want to delete orders in magento including invoices and shipment info?

Use the wyomind extension at http://www.magentocommerce.com/magento-connect/orders-eraser.html

How to get the remaining amount for free shipping?

On the checkout/cart.phtml add the following function and create a div to put the value.

function getRemainingAmount() {
      // Without TAX
      $total = Mage::getSingleton('checkout/cart')->getQuote()->getSubtotal();

      // With TAX
      $totals = Mage::getSingleton('checkout/cart')->getQuote()->getTotals(); 
      $total = $totals["subtotal"]->getValue();  
     
     // From free shipping method 
     $minimum = Mage::getStoreConfig("carriers/freeshipping/free_shipping_subtotal");

     // From table rate free
     $tablerateColl = Mage::getResourceModel('shipping/carrier_tablerate_collection');
     $minimum = 0;
     foreach ($tablerateColl as $tablerate) {
           $line = $tablerate->getData();
           if ($line['price'] == 0) $minimum = $line['condition_value'];
     }

      // return <0 if already free
      // Format returned value using Mage::helper('checkout')->formatPrice(<remaining value>)
      return $minimum - $total;
}

Search in stock products in Magento

Posted: January 17, 2015 in How To?, Magento
Tags:

Want to setup a checkbox in advanced search for in stock products?

  1. Add the checkbox to the advanced search page (name ‘stock’ to the checkbox)
  2. Clone file /app/code/Mage/CatalogSearch/Model/Advance.php to /app/code/local/Mage/CatalogSearch/Model/Advance.php
  3. In the new file add to function prepareProductCollection the following code (before the return $this; statement)
    if (Mage::app()->getRequest()->getParam('stock')) {
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
    }

For the regular search box:

  1. Add the checkbox to the search block (name ‘stock’ to the checkbox)
  2. Clone file /app/code/Mage/CatalogSearch/Model/Layer.php to /app/code/local/Mage/CatalogSearch/Model/Layer.php
  3. In the new file add to function prepareProductCollection the following code (before the return $this; statement)
    if (Mage::app()->getRequest()->getParam('stock')) {
    Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
    }

Here is how you create and external link in the top links menu in magento:

<reference name="root">
<reference name="top.links">
    <action method="addLink" translate="label title">
        <label>example</label>
        <url>http://myotherexampledomain.com</url> 
        <title>example</title>
        <prepare/>
        <urlParams/> 
        <position>100</position>
        <liParams/>
        <aParams>class="top-link-example"</aParams>
        <beforeText></beforeText>
        <afterText></afterText>
    </action>
</reference>
</reference>

Note that you have to unset prepare so the site url is not appended…

If you offer Free Shipping to your customers, then you may have noticed that the default Shipping Methods are still displayed when the Free Shipping Method activates. This can be confusing for the shopper and they need another click to select the “Free Shipping” over the existing rates.

The following code will hide the other shipping methods from the shopping cart page, the default magento checkout and one page checkout.

The file you need to adjust is: app/ design/ frontend/ default/ YOURTEMPLATE/ template/ checkout/ onepage/ shipping_method/ available.phtml

Place the following code right before the <dl> tag that displays the different options.

<?php
if ( array_key_exists('freeshipping', $_shippingRateGroups )) {
$_shippingRateGroups = array('freeshipping' => $_shippingRateGroups['freeshipping']);
}
?>

You can even just unset specific Shipping Methods such as the “Flat Rate Method” using:

<?php
if ( array_key_exists('freeshipping', $_shippingRateGroups )) {
unset($_shippingRateGroups["flatrate"]);
}
?>

Suppose you want to go from the default magento product listing…

qt_before

to a new one where you include the Sku, Brand and add an input field to allow additional quantities added to the cart.

qt_after

How can you do that?

  1. Edit app/design/frontend/<your theme>/<your theme folder>/template/catalog/product/list.phtml
  2. Add
    <?php echo $_product->getSku(); ?>

    to insert the sku (the attribute must be set to visible on product listing under Manage Attributes).

  3. Add
    <?php echo $_product->getAttributeText('manufacturer'); ?>

    to insert the brand (the attribute must be set to visible on product listing under Manage Attributes)

  4. Add the code to insert the input field
    <div class="qty-wrapper">
     <label for="qty">Qty:</label>
     <input type="text" name="qty" id="qty_<?php echo $_product->getId() ?>" maxlength="12" value="1" title="Qty">
     </div>
  5. On the Add to Cart button insert the following field
    onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>qty/'+(document.getElementById('qty_<?php echo $_product->getId() ?>').value)+'/')"
  6. Enjoy :)!

Have you ever wonder how to create a new link on the Top Link Menu in Magento?

Let’s say you have a CMS page called “Great Stuff” you want to link to on the top link menu.

Here what you should do:

  • Edit you local.xml (if you do not have one create it 🙂
  • Paste the code (or place it inside the default tag)
<default>
<reference name="top.links">
<action method="addLink" translate="label title">
<label>Great Stuff</label>
<url>great-stuff</url>
<title>Great Stuff</title>
<prepare>true</prepare>
<position>2</position>
</action>
</reference>
</default>

Get current store id in magento

Posted: October 30, 2014 in How To?
Tags: ,

Wondering how to get the current store id in php?

<?php echo Mage::app()->getStore()->getStoreId() ?>