Your Ad Here

Thursday, May 29, 2014

How to get url of a category or product in magento .phtml file

For category url by category ID:

<?php echo Mage::getModel("catalog/category")->load(5)->getUrl() ?>


To load products of a specific category:

<?php                       
$cat_id 
8// set desired category id$category Mage::getModel('catalog/category')->load($cat_id);$products $category->getProductCollection()->addCategoryFilter($category)->addAttributeToSelect('*');?>
<?php 
foreach ( $products as $_product ): ?>
    
<a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" width="135" height="135" title="<?php echo $_product->getName() ?>" alt="<?php echo $_product->getName() ?>" /></a>
<?php endforeach; ?> 

Retrieve current product, category and CMS page in Magento

Here are the quick snippet scripts for pulling out the current product, category and cms page from inside script or template files in Magento.

Get Current category

$_category = Mage::registry('current_category');


Get Current Product

$_product = Mage::registry('current_product');

Get Gurrent CMS Page

$_cmspage = Mage::registry('cms_page')

Thursday, May 22, 2014

how to get skin url, get media url, get base url, get store url in magento

Magento Mage Core, Admin Static Blocks, or Phtml edits are usually includes getting url path such images, javascript, base url, media and store url. There are different ways to retrieve mentioned URL paths depending on where section you’re editing.

To Retrieve URL path in STATIC BLOCK
To get SKIN URL

{{skin url='images/sampleimage.jpg'}}

To get Media URL

{{media url='/sampleimage.jpg'}}

To get Store URL

{{store url='mypage.html'}}

To get Base URL

{{base url='yourstore/mypage.html'}}

TO Retrieve URL path in PHTML

Note: In editing PHTML don't forget to enclode the following code with PHP tag Not secure Skin URL:
<?php echo $this->getSkinUrl('images/sampleimage.jpg') ?>

Secure Skin URL

<?php echo $this->getSkinUrl('images/ sampleimage.gif', array('_secure'=>true)) ?>

Get  Current URL

$current_url = Mage::helper('core/url')->getCurrentUrl();

Get Home URL

$home_url = Mage::helper('core/url')->getHomeUrl();

Get Magento Media Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);

Get Magento Media Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);

Get Magento Skin Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);

Get Magento Store Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);

Get Magento Js Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);

WooCommerce shipping method filter based on shipping-class and ship to state.

WooCommerce shipping method filter based on shipping-class and ship to state.
<?php
add_filter( 'woocommerce_available_shipping_methods', 'custom_shipping_methods' );
function custom_shipping_methods( $available_methods ) {
$carrier = 'ups';
foreach ( WC()->cart->cart_contents AS $item ) {
if ( has_term( 'large-item', 'product_shipping_class', $item['product_id'] ) ) {
$carrier = 'usps';
continue;
}
}
$states = array( 'AK', 'HI' );
if ( ! in_array( WC()->customer->get_state(), $states ) ) {
$available_methods = wp_filter_object_list( $available_methods, array( 'method_id' => $carrier ), 'NOT' );
}
return $available_methods;
}
Add this code in your theme function.php file.