Change Zencart regular design to mobile responsive design
If you use bootstrap framework, each template can be modified as follow:
– remove some tables that contain fixed width in the css
– add a new div class=”row”
– add multiple div and assign class=”col-sm-4 col-md-6 col-lg-12″
– moving codes by block
For example: On the product_info_display template page, select the entire block “bof Attributes Module” and “eof Attributes Module”, move it into one of multile div, so that when viewing on mobile or tablet the entire block will be organized vertically
Overwrite Inline Styles with your CSS
Usually we think of inline styles as a way to overwrite styles we set up in the CSS file. 99% of the time, this is the case, and it’s very handy. But there are some circumstances where you need to do it the other way around. As in SugarCRM, WordPress, Joomla, there are inline styles on some markup that you absolutely can’t remove, but you need to overwrite what those styles are. This could be markup that is being inserted onto the page from foreign JavaScript or perhaps generated from the bowels of a CMS framework that you cannot control easily. In this case, we CAN overwrite inline styles directly from the stylesheet. Here’s an example:
<div style="background: red;">
The inline styles for this div should make it red.
</div>
You can write this style in .css file
div[style] {
background: yellow !important;
}
How to add the URL encoded signature to your request
Amazon changed the way they authenticate user who use Product Advertising API. In the REST call, you must have Signature parameter in order to request for a service. Below is the functions that helps you encode the request URL in order to add to your request before calling Amazon API for product search and details. Make sure your server support mHash functionality. On Windows, you can enable mhas.dll extension in your php.ini file. On Linux, you can follow this instruction
//String sample to be encoded:
//AWSAccessKeyId=YOUR-ACCESS-KEY&Operation=ItemLookup&ResponseGroup=ItemAttributes%2COffers%2CImages%2CReviews&SearchIndex=Apparel&Keywords=Shirt&Timestamp=2014-12-20T10%3A04%3A00Z
function amazonEncode($text){
$encodedText = "";
$j = strlen($text);
for($i=0; $i<$j; $i++) {
$c = substr($text,$i,1);
if (!preg_match("/[A-Za-z0-9-_.~]/",$c)) {
$encodedText .= sprintf("%%%02X",ord($c));
}
else { $encodedText .= $c; }
}
return $encodedText;
}
function amazonSign($url,$secretAccessKey) { // 0. Append Timestamp parameter
$url .= "&Timestamp=".gmdate("Y-m-dTH:i:sZ");
// 1a. Sort the UTF-8 query string components by parameter name
$urlParts = parse_url($url);
parse_str($urlParts["query"],$queryVars);
ksort($queryVars);
// 1b. URL encode the parameter name and values
$encodedVars = array();
foreach($queryVars as $key => $value) {
$encodedVars[amazonEncode($key)] = amazonEncode($value);
}
// 1c. 1d. Reconstruct encoded query
$encodedQueryVars = array();
foreach($encodedVars as $key => $value){
$encodedQueryVars[] = $key."=".$value;
}
$encodedQuery = implode("&",$encodedQueryVars);
// 2. Create the string to sign
$stringToSign = "GET";
$stringToSign .= "n".strtolower($urlParts["host"]);
$stringToSign .= "n".$urlParts["path"];
$stringToSign .= "n".$encodedQuery;
// 3. Calculate an RFC 2104-compliant HMAC with the string you just created,
// your Secret Access Key as the key, and SHA256 as the hash algorithm.
if (function_exists("hash_hmac"))
{
$hmac = hash_hmac("sha256",$stringToSign,$secretAccessKey,TRUE);
}
elseif(function_exists("mhash"))
{
$hmac = mhash(MHASH_SHA256,$stringToSign,$secretAccessKey);
}
else
{
die("No hash function available!");
}
// 4. Convert the resulting value to base64
$hmacBase64 = base64_encode($hmac);
// 5. Use the resulting value as the value of the Signature request parameter
// (URL encoded as per step 1b)
$url .= "&Signature=".amazonEncode($hmacBase64);
return $url;
}
How Zen-Cart login and add to cart forms work
To login to Zen-Cart system either as a customer or a store Admin, Zen-Cart restricts access to a form that contains the securityToken value. This is a must. So if you need to build a log-in form in the outside of Zen-Cart framework, you must find a way to include this securityToken before you submit to data to the Zen-Cart login process.
Beside the log-in mechanism, Zen-Cart has the cart functionality that require the securityToken also. Here’s all the data values that you need to submit to “add to cart” process.
<input name="securityToken" type="hidden" value="blahblahblah...64d7d0acdbe575ca9af8e62822568f92" /> <input maxlength="6" name="cart_quantity" size="4" type="text" value="1" /> <input name="products_id" type="hidden" value="21" />
Modern PHP with Composer
For some of you who may not know about composer for PHP 5.3 and above, I’d like to summarize what I’ve discovered about this powerful tool so far.
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you. (composer.org). To use it, go to the website and download the Composer-Setup.exe for windows or run a terminal to get the latest Composer version by command curl -sS https://getcomposer.org/installer | php
– On windows, point to the php.exe file during your composer settings. If you see some error like .dll not working, try to disable it in php.ini before running composer installation. Once done, open cmd line and type composer in Windows. It should tell you what version you installed and all the available commands.
– To use it, each of your package/library must have a file called “composer.json” in the root of your project. Then cd to your project dir C:/>cd myproject. Then you must run command “composer update“, so that all libraries that you have specified in composer.json will be loaded onto your web server and make them available automatically for you to use in your project.
– Once you run composer update command, the /vendor dir will be automatically created inside your project’s directory by the composer. This is the structure you’ll see in your project directory.
1)YourProjectTest1
1a)lib
1aa)Test\PrintTest.php
1b)vendor
1ba)composer
ClassLoader.php
autoload_classmap.php
autoload_namespaces.php
autoload_psr4.php
autoload_real.php
1bb)autoload.php
1c)composer.json
Next, I’ll show you how to create the first project that use the composer. It’s a powerful tool for PHP so we all need a little time to discover it. It’s new to me, too, so stay tuned. If you find anything missing, please notify me. Happy learning!