Javascript – addslashes and stripslashes

A Javascript function for add slashes: function addslashes(str) { str=str.replace(/\\/g,’\\\\’); str=str.replace(/\’/g,’\\\”); str=str.replace(/\”/g,’\\”‘); str=str.replace(/\0/g,’\\0’); return str; } A Javascript function for strip slashes: function stripslashes(str) {…

Magento get child products for a configurable product

Magento get products childs for a configurable product // $currentProduct = $this->getProduct(); $configurable_products = Mage::getModel(‘catalog/product_type_configurable’)->setProduct($currentProduct); $products_collection = $configurable_products->getUsedProductCollection()->addAttributeToSelect(‘*’)->addFilterByRequiredOptions(); foreach($products_collection as $_product){ echo $_product->getId() . “:…

Magento – Show Quantity Box in Products List

In file ‘list.phtml’ file change the <button> line near line 108 from this: <?php if($_product->isSaleable()): ?> <button class=”form-button” onclick=”setLocation(‘<?php echo $this->getAddToCartUrl($_product) ?<‘)”>>span> <?php echo $this->__(‘Add…

Magento – use singleton database connection

Magento database connection write mode: $db = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’); Magento database connection read mode: $db = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’); Query model $result = $db->query(“SELECT * FROM tablename”); if…

Magento – custom block

Custom block (for CMS pages): {{block type=”core/template” name=”template_name” template=”mydir/mytemplate.phtml” }}

Magento – save and get data from cache

Just a method to save and get data from magento cache $mydataforcache = “My data for cache”; $cache_name = “maycachename”; $CACHEDATA = MAGE::app()->loadCache($cache_name); if (isset($CACHEDATA)…

Javascript – compare two dates

Compare two dates in Javascript: <html> <head> <title>JavaScript – compare two dates</title> </head> <body> <script language=”Javascript” type=”text/javascript”> var date1 = new Date(“22/12/2010”); var date2 =…