Skip to content

Instantly share code, notes, and snippets.

@pierreandreroy
pierreandreroy / get_all_categories.php
Created December 23, 2013 18:24
Get all Magento categories.
<?php
$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('url_key')
->addAttributeToSelect('url')
->addAttributeToSelect('is_active');
foreach ($categories as $category)
{
@pierreandreroy
pierreandreroy / getUrlParameter.js
Created October 9, 2013 14:58
Get URL parameter
function getURLParameter(sParam){
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam){
return sParameterName[1];
}
}
}
@pierreandreroy
pierreandreroy / call_magento_extern_file.php
Created August 16, 2013 17:57
Call Magento model (function) from an external file.
<?php
//include Magento app
require_once 'app/Mage.php';
//initialize Magento
Mage::app();
//call Magento model or functions (this example get unsubscription link for customer)
$email = "test@test.com";
$unSubLink = Mage::getModel('newsletter/subscriber')->loadByEmail($email)->getUnsubscriptionLink();
@pierreandreroy
pierreandreroy / all_attribute_options
Last active December 24, 2019 15:46
Get all possible value (dropdown options) of a product attribute in Magento.
<?php
//Possible color value
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color'); //"color" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach ($allOptions as $instance) {
$id = $instance['value']; //id of the option
$value = $instance['label']; //Label of the option
}
?>
@pierreandreroy
pierreandreroy / newslettre_templates
Created August 16, 2013 17:45
Get list of newsletter template in Magento.
<?php
$template_info = array();
$template_collection = Mage::getResourceSingleton('newsletter/template_collection');
if(!empty($template_collection)){
$cnt = 0;
foreach($template_collection as $template){
$template_info[$cnt]['id'] = $template->getTemplateId();
$template_info[$cnt]['code'] = $template->getTemplateCode();
$cnt++;
}
@pierreandreroy
pierreandreroy / image_product_recently_viewed
Created August 16, 2013 15:38
Add image to product recently viewed block in Magento
<?php if ($_products = $this->getRecentlyViewedProducts()): ?>
<div class="block block-list block-viewed">
<div class="block-title">
<strong><span><?php echo $this->__('Recently Viewed Products') ?></span></strong>
</div>
<div class="block-content">
<ol id="recently-viewed-items">
<?php foreach ($_products as $_item): ?>
<li class="item">
<p><img class="product-image" src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(50, 50) ?>" width="50" height="50" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /> </p>