Friday, November 21, 2014

Free Dhtml scripts, Jquery plugins ,Javascript, CSS, CSS3, Html5 Library

If you need best Free Dhtml scripts, Jquery plugins ,Javascript, CSS, CSS3, Html5 Library

I will recommend you this link: http://www.htmldrive.net/

Really awesome example and echo friendly code. You should use it and improve your work performance.


What is array serialization ?

 As arrays are complex data types, you cannot see their contents directly. If you try printing out the value of an array, you will see PHP just outputs "Array", which means that passing the value of an array through a link requires a lot of work. Luckily, PHP comes to the rescue with four functions that do all the hard work for you: serialize(), unserialize(), urlencode(), and urldecode().

Serialize() converts an array, given as its only parameter, into a normal string that you can save in a file, pass in a URL, etc. Unserialize() is the opposite of serialize() - it takes a serialize()d string and converts it back to an array.

Urlencode() and urldecode() also work in tandem, and convert the string that is sent to them as their only parameter into a version that is safe to be passed across the web. All characters that aren't letters and numbers get converted into web-safe codes that can be converted back into the original text using urldecode().
Passing arrays across pages is best done using urlencode() and urldecode(), however you should consider using them both on any data you pass across the web, just to make sure there are no incompatible characters in there

string serialize ( mixed value)
mixed unserialize ( string input)
string urlencode ( string text)
string urldecode ( string encoded)

<?php
    $array
["a"] = "Foo";
    
$array["b"] = "Bar";
    
$array["c"] = "Baz";
    
$array["d"] = "Wom";

    
$str = serialize($array);
    
$strenc = urlencode($str);
    print
$str . "\n";
    print
$strenc . "\n"; ?>

That will output two lines (the second of which I've forced to wrap so that it appears properly!):

a:4:{s:1:"a";s:3:"Foo";s:1:"b";s:3:"Bar";s:1:"c";s:3:"Baz";s:1:"d";s:3:"Wom";}
a%3A4%3A%7Bs%3A1%3A%22a%22%3Bs%3A3%3A%22Foo%22%3Bs%3A1%3A%22b%22%3Bs%3A0%3A%22
%22%3Bs%3A1%3A%22c%22%3Bs%3A3%3A%22Baz%22%3Bs%3A1%3A%22d%22%3Bs%3A3%3A%22Wom%22%3B%7D

The first is the direct, serialize()d output of our array, and you can see how it works by looking through the text inside there. The second line contains the urlencode()d serialize()d array, and is very hard to read. Despite being hard to read, the latter is wholly web safe, and there much better to use.
Once your array is in text form, you can do with it as you please. To return back to the original array, it needs to be urldecode()d, then unserialize()d, like this:

<?php
    $arr
= unserialize(urldecode($strenc));
    
var_dump($arr); ?>
 
 
Note: If you want to transfer binary data over the web, you should use rawurlencode() and rawurldecode() as opposed to urlencode() and urldecode(), as the raw versions are binary-safe. 




Friday, April 4, 2014

Make Magento “Continue Shopping” button redirect to the last-added-to-cart product's category

Copy following file 
 /app/code/core/core/Mage/Checkout/Block/Cart.php  
and place under local codepool 
app/code/core/local/Mage/Checkout/Block/Cart.php 
 
Update the following code into function getContinueShoppingUrl() 

public function getContinueShoppingUrl()
    {

      /*
        $url = $this->getData('continue_shopping_url');
        if (is_null($url)) {
            $url = Mage::getSingleton('checkout/session')->getContinueShoppingUrl(true);
            if (!$url) {
                $url = Mage::getUrl();
            }
            $this->setData('continue_shopping_url', $url);
        }
        return $url;

      */
       
            $lastProductAddedToCartId = Mage::getSingleton('checkout/session')->getLastAddedProductId();
            if($lastProductAddedToCartId) {
            $productCategoryIdsArray = Mage::getModel('catalog/product')->load($lastProductAddedToCartId)->getCategoryIds();
            $continueShoppingCategoryUrl = Mage::getModel('catalog/category')->load($productCategoryIdsArray[0])->getUrl();
            }
  
            return $continueShoppingCategoryUrl;
    }


Enjoy the work!!


How to get the customer login, logout, register and checkout url?

Mage::getUrl(‘customer/account/login’); //login url

Mage::getUrl(‘customer/account/logout’); //logout url

Mage::getUrl(‘customer/account’); //My Account url

Mage::getUrl(‘customer/account/create’); // Register url

Mage::getUrl(‘checkout/cart’); //Checkout url

Magento: Check if Customer Logged in

//LOAD MAGENTO
 

require_once 'YOUR_PATH_TO_MAGENTO/app/Mage.php';
umask(0);
Mage::app('YOUR_WEBSITE_CODE', 'website');


//GET SESSION DATA
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));

$customer_data = Mage::getModel('customer/customer')->$session->id);

//CHECK IF LOGGED IN
if($session->isLoggedIn()){
echo 'Welcome ' . $customer_data->firstname . " " . $customer_data->lastname;
}
else {
echo "Access Denied: Sorry, but this page is for registered members only.";
exit;
}

Magento -- How to Use PHTML File in CMS or Static Block

In Magento CMS or Static block, if you want to add PHP code then you can just call any custom .phtml file by using following code. Like here I am including my_custom.phtml.

{{block type="core/template" name="myCustom" template="cms/my_custom.phtml"}}