Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Category Archives: PHP

www redirect issues Fix

How to change to

if ($_SERVER['HTTP_HOST'] != '') header('Location:' . $_SERVER['REQUEST_URI']);

If we use the cart, the cookies will be stored differently if we don’t use it. So, it will be always storing under domain Applied for the client SHE Lights.

PHP Mobile Detection Library

Download this ZIP: click

      $iphoneTierHomePage = '';
      $genericMobileDeviceHomePage = '';
      $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);        
          header ('Location: '.$desktopHomePage);

Magento Fontis ANZ eGate

Provides integration with the ANZ eGate gateway interface. Only payments and refunds are allowed; void or pre-authorisation are not currently included in the extension. For more information, including screenshots, version history and instructions on configuration and usage, please see the Fontis ANZ eGate Magento extension page. To stay up-to-date with the latest releases, follow us on Twitter and subscribe to our blog. If you’d like to link to this extension, please use our extension page rather than this Connect listing. To see the other extensions we have available, visit our Magento extension page for a complete list. The development of this extension is commercially supported by Fontis. We welcome any feedback and suggestions from the community on the ongoing development of the extension. We can also provide customisation and development services upon request.

Magento storing in session

$storage = array('a'=>'b');

// store data so we can fetch it in subtotal methods

// get data
$rbanhShipping = Mage::getSingleton('core/session')->getRbanhShipping(); 
$rbanhShipping = unserialize($rbanhShipping);

Magento auto add product custom options

// *Special note: make sure you check your sql table name, 
//  and change the option title from what i have below.

// rbanh special methods
private function rbanh_get_custom_option_id($product_id)
    $sql = "
            catalog_product_option o
        inner join
            catalog_product_option_title t on t.option_id = o.option_id
            t.title = 'Shipping Description'
            and o.product_id = '".$product_id."'
        limit 1
    $data = Mage::getSingleton('core/resource') ->getConnection('core_read')->fetchAll($sql);
    if (count($data) > 0)
        return current($data[0]);
    return false;

// rbanh special methods
private function rbanh_add_custom_option($product_id)
    // make the option active
    //$write = Mage::getSingleton('core/resource')->getConnection('core_write');
    //$write->query("update catalog_product_entity set has_options = 1 where entity_id='$product_id'"); 
    $write = Mage::getSingleton('core/resource')->getConnection('core_write');
    $sql  = "update catalog_product_entity set has_options = 1 where entity_id=?";
    $write->query($sql, $product_id); 
    $product = Mage::getModel('catalog/product');
    $opt = Mage::getModel('catalog/product_option');
    $option = array(
        'is_delete' => 0,
        'is_require' => false,
        'previous_group' => 'text',
        'title' => 'Shipping Description',
        'type' => 'field',
        'price_type' => 'fixed',
        'price' => '0.0000'
    return $this->rbanh_get_custom_option_id($product_id);

Magento How to add new products

require_once 'app/Mage.php';
// instatiate Product
$product = Mage::getModel('catalog/product');
$product->setSku('rand-sku-' . rand());
$product->setType('Simple Product');
$product->setName('Product Name'.rand(1,200000));
$product->setDescription('The Product Description');
$product->setShortDescription('Brief Description');
// "Stock Item" still required regardless of whether inventory
// control is used, or stock item error given at checkout!
$stockItem = Mage::getModel('cataloginventory/stock_item');
$stockItem->setData('is_in_stock', 1);
header("Location: /checkout/cart/add/product/".$product->getId()."/); 
%d bloggers like this: