Practical Web Applications for Daily Living…
Coding
Code Igniter Ajax Form
Sep 5th
$j(document).ready(function(){
$j("form").submit(function(e) {
e.preventDefault();
$j.post("/index.php/home/submitmessage", { firstname: $j("#firstname").val(), lastname: $j("#lastname").val(), address: $j("#address").val(), email: $j("#email").val(), confirmemail: $j("#confirmemail").val() , telephone: $j("#telephone").val(), mobile: $j("#mobile").val(),message: $j("#message").val() }, function (data) {
alert(data);
});
});
});
in application/config/constant
define(‘IS_AJAX’, isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’);
in the controller
{
//load form validation
$this->load->library(‘form_validation’);
//set form rules
$this->form_validation->set_rules(‘firstname’, ‘Firstname’, ‘required’);
$this->form_validation->set_rules(‘lastname’, ‘Lastname’, ‘required’);
$this->form_validation->set_rules(‘email’, ‘Email’, ‘required|valid_email|matches[confirmemail]‘);
$this->form_validation->set_rules(‘confirmemail’, ‘Confirm Email’, ‘required|valid_email’);
$this->form_validation->set_rules(‘address’, ‘Address’, ‘required’);
$this->form_validation->set_rules(‘message’, ‘Message’, ‘required’);
//run form validation
$success = $this->form_validation->run();
//set username variable
$firstname = $this->input->post(‘firstname’);
$lastname = $this->input->post(‘lastname’);
$email = $this->input->post(‘email’);
$address = $this->input->post(‘address’);
$message = $firstname." ".$lastname."\n";
$message .= "Tel:".$this->input->post(‘telephone’)." | Mobile:".$this->input->post(‘mobile’)."\n";
$message .= $address."\n";
$message .= $this->input->post(‘message’);
$msg = $message;
//if the validation was a success
if ((IS_AJAX && $success) || (!IS_AJAX && $success)) {
$this->load->library(‘email’);
$this->email->from($email, $firstname." ".$lastname);
$this->email->to(‘juliusbacosa@gmail.com’);
$this->email->subject(‘Message from Weekee’);
$this->email->message($msg);
$this->email->send();
echo "Congradulations {$firstname}, your form was accepted!";
}
//if validation failed
else { echo strip_tags(validation_errors()); }
}
Copy and Paste Now!!!!
Displaying Product Images of Associated Products with Configurable Products in Magento
Aug 21st
$assoc_product = Mage::getModel(‘catalog/product’)->load($child->getId());
echo $assoc_product->getName();
foreach($assoc_product->getMediaGalleryImages() as $assoc_product_img){ ?>
<div>
<img src=’<?php echo $this->helper(‘catalog/image’)->init($assoc_product, ‘thumbnail’, $assoc_product_img->getFile())->resize(70, 70); ?>‘ />
</div>
<?php } ?>
The complete snippet is here
$product = Mage::getModel(‘catalog/product’);
$parent = $product->load($_product->getId());
$children = Mage::getModel(‘catalog/product_type_configurable’)->getUsedProductCollection($parent);
$xxx = $parent->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($parent);
foreach($children as $child){
$child = $product->load($child->getId()); ?>
<div>
<a href="<?php echo $this->helper(‘catalog/image’)->init($child, ‘image’); ?>" id="<?php echo "link".$child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>">
<img src="<?php echo $this->helper(‘catalog/image’)->init($child, ‘image’); ?>" id="<?php echo "img".$child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>" />
</a>
<?php
$assoc_product = Mage::getModel(‘catalog/product’)->load($child->getId());
echo $assoc_product->getName();
foreach($assoc_product->getMediaGalleryImages() as $assoc_product_img){ ?>
<div>
<img src=’<?php echo $this->helper(‘catalog/image’)->init($assoc_product, ‘thumbnail’, $assoc_product_img->getFile())->resize(70, 70); ?>‘ />
</div>
<?php } ?>
</div>
<?php } ?>
Display more Attribute in Table Grid of Group Product Details in Magento
Aug 21st
Go to frontend/base/default/template/catalog/product/view/type/grouped.html
Add this code to the head of the table
<th class="a-right"><?php echo $this->__(‘Height’) ?></th>
insert this code in the table body:
where ’sign_width’ and ’sign_height’ are attribute names.
<td><?php echo $this->htmlEscape($_item->getData(’sign_height’)); ?></td>
enjoy!!!
How do you use configurable products versus group products in magento?
Zend framework on Saturday
Aug 18th
Currently I am uploading another batch of magento files to be deployed live, and I am so sleepy right now… well… anyway… This friday we don’t to have work because we are going to a company relaxation day, because our skins are turning green already due to work radiation… so after friday, the whole saturday.. I will try to implement a zend application so I can have a taste of it before deploying a heavy weight web app, and also to compare my experience in asp.net mvc development.
I was wondering if there are any tools that can help unit test zend framework apps, of can I even use castle project for them, I don’t know yet. Are zend frameworks applications a test driven design one… opssss… files are almost done uploading in 3, 2, 1, byeeee…..
Code Igniter instead of Magento
Aug 18th
There are some situations where you need to take a cab instead of taking MRT. The other day, I decided to code an online transaction from scratch and it took me 20 hours to do the backend and frontend using code igniter instead of magento, If I use magento to implement it, the complexity in tweaking magento will add me more stress. Thank God to understanding of MVC pattern I rapidly develop the Application in no time at all compared to the complexity and stress magento is giving me everytime a client what some fancy functionality.
I’ve finally appreciated the value of Rapid Application Development tools like Code Igniter.
Zend Framework First Impression
Aug 16th
Got my 30 minutes dive into the zend framework, installed it in my server and got a little play with layouts (masterpages in asp.net), the Bootstrap (not sure with asp.net mvc what is the equivalent for this one), application.ini (asp.net mvc has this) and some structure overview. Zend framework still has the Movel-View-Controller pattern and like any mvc framework i’ve work with, this pattern is very easy to adopt once you have the mindset, is it a little bit weird it you’ve just dive in from a typical object oriented programming structure… anyway… have to go… raining again with a hungry stomach to feed.
Ecommerce designer Singapore
Aug 15th
I tried to search for ecommerce developer in singapore using google search engine, as expected this blog is in the first page results, but when I try to search for ecommerce designer Singapore, this blog is nowhere to be found in the first page.
People might think that I can only do development for them, well… I do both actually from concept design ,analysis of design for integration, existing ecommerce platform, template conversation of design draft in raw psd files , development and script installation to live deployment and payment gateway integration like google checkout and PayPal.
I am expecting this blog to be on the first page of google search engine result for the keyword ecommerce designer singapore.
Product Description HTML break Magento
Aug 14th
to enable the wyswyg in HTML product description in magento 1.4, go to admin panel-> catalog -> attributes -> manageattributes
filter the attribute label description
scroll down, enable wyswyg editor, and works like magic,
Magento surprises me on every corner of what it can do.
How to Load Sub Categories of a Category Magento
Aug 13th
To load subcategories of a category in magento , load the categories first.
$categories->load();
then filter the categories by parent id of a category
$html .= "<ul class=’popular-range’>";
foreach ($categories as $_category):
if($_category->getParentId()==36){
$html .= "<li><a href=’".$_category->getUrlPath()."’>".$_category->getName()."</a></li>";
}
endforeach;
$html .= "</ul>";
$html .= "</div>";
Thats it…. copy the code if you want… I am generous….
