Sanjoy Roy

[MCM, MCP, SCJP] – Senior Programmer, Sites n Stores Pty Ltd.

Monthly Archives: August 2011

Linux – Kill all processes for a user

To kill all processes for a single user, use the following command: pkill -u username

Magento – how to display a page title and contents from backend

$terms_condtn_title = Mage::getModel(‘cms/page’)->load(‘terms-and-conditions’, ‘identifier’)->getTitle(); $terms_condtn_content = Mage::getModel(‘cms/page’)->load(‘terms-and-conditions’, ‘identifier’)->getContent(); echo $terms_condtn_content;

Add a New system variable in Magento

SQL: INSERT INTO `amwsales_db`.`core_config_data` ( `config_id` , `scope` , `scope_id` , `path` , `value` ) VALUES ( NULL , ‘default’, ’0′, ‘design/footer/terms_condtn_txt’, ‘terms and condition text here’ PHP: $terms_condtn_txt = Mage::getStoreConfig(‘design/footer/terms_condtn_txt’);

How to getBaseUrl in Magento

When developing in Magento and playing arround with Magento Themes there is some functions you should know. If you want to get the source url of an image, javascript or file, call one of this functions adding your own path at the end. Under every function there is an example of the output value: //http://example.com/ [...]

Deactivate Magento store using .htaccess temporarily

Here is quick snippet of code that we use all the time when upgrading or moving a Magento store. This will stop people from creating accounts, placing orders, etc… while you are in the middle of heavy database work. Add this to your .htaccess file in your root directory and only your IP address will [...]

jQuery Cookie Plugins

$.cookie(‘term_condtn’, ‘accepted’, { expires: 1 }); jQuery.cookie = function(name, value, options) { if (typeof value != ‘undefined’) { // name and value given, set cookie options = options || {}; if (value === null) { value = ”; options.expires = -1; } var expires = ”; if (options.expires && (typeof options.expires == ‘number’ || options.expires.toUTCString)) [...]

PHP Mobile Detection Library

Download this ZIP: click MobileESP_Samples.zip include(“mp/php_redirect_sample/code/mdetect.php”); $iphoneTierHomePage = ‘http://m.xyz.com.au/index.php?page=m’; $genericMobileDeviceHomePage = ‘http://m.xyz.com.au/index.php?page=m’; $desktopHomePage = ‘index.php’; $uagent_obj = new uagent_info(); function AutoRedirectToProperHomePage(){ global $uagent_obj, $iphoneTierHomePage, $genericMobileDeviceHomePage, $desktopHomePage; if ($uagent_obj->isTierIphone == $uagent_obj->true) header (‘Location: ‘.$iphoneTierHomePage); else if ($uagent_obj->DetectMobileQuick() == $uagent_obj->true) header (‘Location: ‘.$genericMobileDeviceHomePage); else header (‘Location: ‘.$desktopHomePage); } AutoRedirectToProperHomePage();

How to user FirePHP

*Install FirePHP FireFox add-ons (get a console like firebug), bottom status console bar in FF * Copy FirePHP.class.php to the root file location require(“FirePHP.class.php”); $firephp = FirePHP::getInstance(true); $firephp->log($doc->load($url), ‘doc’);

how to upgrade cms ms

define(‘CUSTOMER_FOLDER’, ‘/var/www/vhosts/’); define(‘WEB_FOLDER’, ‘httpdocs/websitedesign’); if (PHP_SAPI != “cli”) exit; if ($argc != 2){ echo ‘this command needs 1 argument’.”\n”; exit; } if (!file_exists(CUSTOMER_FOLDER.$argv[1].’/’.WEB_FOLDER.’/version.php’)){ echo CUSTOMER_FOLDER.$argv[1].’/’.WEB_FOLDER.’/version.php’.”\n”; echo ‘Check the folder name’.”\n”; exit; } $sitename = $argv[1]; $path = CUSTOMER_FOLDER.$sitename.’/'; $owner = ‘thehost5′; $group = ‘psacln’; chdir(‘/var/www/vhosts/’.$sitename.’/'); if (!file_exists($path.’backup’)){ mkdir($path.’backup’); } else { echo ‘backup folder exists’.”\n”; [...]

how to display products group price B2B CreLoaded Store

$products_group_price = getSpecialPrices($product_info['products_id']); function getSpecialPrices($products_id){ $m_value = ”; $sql = “SELECT `customers_group_price` FROM `products_groups` WHERE `products_id` =’”.$products_id.”‘”; $m_query = tep_db_query($sql); while ($m_rows = tep_db_fetch_array($m_query)) { $m_value = $m_rows['customers_group_price']; } return $m_value; }

show all categories expanded

$aa = 0; $info_box_contents = array(); // $info_box_contents[] = array(‘text’ => ” . BOX_HEADING_CATEGORIES4 . ”); // new infoBoxHeading($info_box_contents); // $categories_string4 = ”; if(!$_SESSION['sppc_customer_group_id']) { $customer_group_id = ‘G’; } else { $customer_group_id = $sppc_customer_group_id; } $categories_query = tep_db_query(“SELECT c.categories_id, cd.categories_name, c.parent_id from ” . TABLE_CATEGORIES . ” c, ” . TABLE_CATEGORIES_DESCRIPTION . ” cd WHERE [...]

oscommerce – 30 minutes cleanup from cart baskets

include_once(“includes/configure.php”); $conn = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD); mysql_select_db(DB_DATABASE); $sql = “SELECT `customers_basket_id`,`customers_id`,`products_id`,`customers_basket_quantity`,`final_price`,`customers_basket_date_added`,`auction_product`,`customers_basket_datetime` FROM `customers_basket` ORDER BY `customers_basket_id` ASC”; $result = mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $products_id = $row["products_id"]; $customers_id = $row["customers_id"]; $customers_basket_quantity = $row["customers_basket_quantity"]; $total_minutes = 0; $customers_basket_datetime = $row["customers_basket_datetime"]; $total_minutes = date_diff($customers_basket_datetime); if ($total_minutes >= 30){ $sql = “update products set products_quantity = products_quantity [...]

creloaded 6.2 – osCommerce – shopping cart check/uncheck all – remove items from cart

HTML: <input type="button" value="CHECK ALL" onclick="checkUncheck(true);" />&nbsp;<input type="button" value="UNCHECK ALL" onclick="checkUncheck(false);" /> JS: function checkUncheck(flag) { for (var i=0;i<document.forms[0].elements.length;i++) { var e = document.forms[0].elements[i]; if ( (e.name != 'cart_delete') && (e.type=='checkbox') && (!e.disabled) ) { if(flag) document.forms[0].elements[i].checked = true; else document.forms[0].elements[i].checked = false; } } }

Creloaded 6.2 – osCommerce – Cross sell products

$categories = array(); $sql = “SELECT `categories_id` FROM `products_to_categories` WHERE `products_id` = ‘”.$HTTP_GET_VARS['products_id'].”‘”; $result = tep_db_query($sql); while ($row = mysql_fetch_assoc($result)) { $categories[] = $row["categories_id"]; } $categories_str = ”; if (sizeof($categories)){ $categories_str = implode(“‘,’”, $categories); } $products = array(); $sql = “SELECT `products_id` FROM `products_to_categories` WHERE `categories_id` IN (‘”.$categories_str.”‘)”; $result = tep_db_query($sql); while ($row = mysql_fetch_assoc($result)) [...]

Magento Easy Lightbox

This small extension will help to install Lightbox widget. Installation and configuration will take approximately 5 minutes. http://www.magentocommerce.com/magento-connect/TemplatesMaster/extension/1487

Magento – How to create multiple store?

Here is a very good video tutorial: http://www.magentocommerce.com/magento-on-the-fly/multiple-sites/

Magento – Creating a Configurable Product

The following link will demonstrate, how you can add product attributes and set the difference prices in additions to the product price. http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-configurable-product

Magento – How to get a product attribute value?

I have created an extra attribute ‘enquiry_only’ in the back-end, this is how I can retrieve the attribute value in the product info template page: \public_html\app\design\frontend\base\default\template\catalog\product\ $enquiry_only = Mage::getModel(‘catalog/product’) ->load($_product->getId()) ->getAttributeText(‘enquiry_only’); Alternatively we can use like: $prod = Mage::getModel(‘catalog/product’)->load($_product->getEntityId()); $prod = $prod->getData(); $enquiry_only = ‘No’; $attribute = Mage::getModel(‘eav/config’)->getAttribute(‘catalog_product’, ‘enquiry_only’); foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){ [...]

osCommerce – Vouchers or coupons when assigned to specific products

Filename: includes/modules/order_total/ot_coupon.php $c_restrict_to_products = $coupon_result['restrict_to_products']; $logs .= 'c_restrict_to_products: '.$c_restrict_to_products; $c_restrict_to_categories = $coupon_result['restrict_to_categories']; $logs .= 'c_restrict_to_categories: '.$c_restrict_to_categories; $valid_coupon_product_id_exists = 'false'; if($c_restrict_to_products !=''){ $db_product_ids = split(“[,]“, $c_restrict_to_products); for ($i=0; $i products); $i++) { $logs .= 'products_id: '.$order->products[$i]['id']; if (in_array($order->products[$i]['id'], $db_product_ids)) { $valid_coupon_product_id_exists = 'true'; } } }else if($c_restrict_to_categories !=''){ $db_category_ids = split(“[,]“, $c_restrict_to_categories); for ($i=0; $i products); [...]

Magento – Terms & Condition Popup for Category Page Link

jQuery Library include: CSS: css/ui-lightness/jquery-ui-1.8.16.custom.css JS: js/jquery-1.6.2.min.js js/jquery-ui-1.8.16.custom.min.js Javascript code: $(document).ready(function(){ TERMS_CONDT_CNT = 0; $(‘.category-box a’).click(function() { //$( “#dialog:ui-dialog” ).dialog( “destroy” ); console.log(this); vlink = this.href; console.log(vlink); if (TERMS_CONDT_CNT == 0){ $( “#dialog-confirm” ).dialog({ resizable: false, height:500, width:500, modal: true, buttons: { “Accept”: function() { TERMS_CONDT_CNT++; debugger; $( this ).dialog( “close” ); document.location = vlink; [...]

magento Couldn’t resolve host ‘magento-community’

See the setting is not “Beta” and…. Try to use the link: “http://connect20.magentocommerce.com/community/” before the extension key. e.g http://connect20.magentocommerce.com/community/J2T_TNT_Module This should work.

TNT API Documentation

TNT_v2_iConnections_Tracking TNT_v2_iConnections_Shipping TNT_v2_iConnections_Pricing From Direct Link: http://tntna.com/ec/ http://www.tnt.com/express/en_gb/site/home/shipping_tools/shipping_systems/expressconnect/registration_details.html Demo Link: https://www.tntexpress.com.au/rtt/demonstration.asp 1. System Overview The External RTT application provides an interface for TNT customers to retrieve a list of TNT’s available operational services, their cutoff times, estimated delivery dates and prices. This service has been designed for integration into the software or websites of TNT customers. [...]

Follow

Get every new post delivered to your Inbox.