Custom Search

Model View Controller

Code Igniter Ajax Form

var $j = jQuery.noConflict();
     $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);
                        });
                });

        });

<form id="ajax-form" action="/home/submitmessage" method="post">

  // form field here

<INPUT class="ordersubmitbutton" TYPE="image" SRC="<?php echo base_url();?>jimages/submitform.jpg" BORDER="0" ALT="Submit Form">
</form>

in application/config/constant

// Define Ajax Request
define(‘IS_AJAX’, isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’);

in the controller

function submitmessage()
        {
               
               
                //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!!!!

JQUERY JSON Codeigniter

Jquery snippet to call a method with a json p=output

jQuery("#getjson").click(function(){
         jQuery.getJSON("index.php/welcome/jjson/", function(json){
                        jQuery(‘#json’).html("<a href=’http://www.google.com’ target=’_blank’>" + json.glossary.title + "</a>:"+ json.glossary.GlossDiv.title + ":" + json.glossary.GlossDiv.GlossList.GlossEntry.ID);
                });
         });

where
json.glossary.GlossDiv.title
is the from json = the variable containing the data
glossary = is an array item from the json data
Glossdiv… etc…

here is the controller that writes this data.

function jjson()
        {

               
                $results[‘jsonx’] = ‘{
                 "glossary": {
            "title": "example glossary",
                        "GlossDiv": {
               "title": "S",
                                "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                                        "SortAs": "SGML",
                                        "GlossTerm": "Standard Generalized Markup Language",
                                        "Acronym": "SGML",
                                        "Abbrev": "ISO 8879:1986",
                                        "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                                                "GlossSeeAlso": ["GML", "XML"]
                    },
                                        "GlossSee": "markup"
                }
                    }
           }
                 }
                }’
;
                $this->load->view(‘Json_record’,$results);
               
        }

then the view to render the data.

<?php print $jsonx; ?>

Jquery Ajax Codeigniter

In your View

<script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
         jQuery(‘#x’).click(function(){
                jQuery("#content").empty().html(‘<img src="http://juliusbacosachronicles.com/wp-content/themes/mystique/images/workstation.jpg" />’);
                var num = 8;
                jQuery(‘#content’).load("index.php/welcome/jajax/"+num,function(str){});                                                                 
        });
               
  });
  // Code that uses other library’s $ can follow here.
</script>

then the div to hold the content

<div id="content">
</div>

In your Controller

function Welcome()
        {
                parent::Controller();  
                $this->load->helper(‘url’);
        }
       
        function index()
        {
               
                $this->load->view(‘welcome_message’);
        }
       
        function jajax($num)
        {
                 $results[‘xxx’] = $num*111;
                $this->load->view(‘Ajax_record’,$results);
                 //get the record from the database
        }

then for the view Ajax_record

<?php print $xxx; ?>

Retrieving data from Model and accessing the database is still the same.
Byeee….

Setting Up Contact Form within Static Block in Magento

Just put this within your static block

<form id="contactForm" action="contacts/index/post/" method="post"> <fieldset class="group-select">
<ul>
<li>
<div class="input-box">
<div><label for="name">Name <span class="required">*</span></label> <input id="name" class="required-entry input-text" title="Name" name="name" type="text" /></div>
<div class="input-box"><label for="email">Email <span class="required">*</span></label></div>
<div><input id="email" class="required-entry input-text validate-email" title="Email" name="email" type="text" /></div>
<div class="input-box"><label for="telephone">Telephone</label><br /> <input id="telephone" class="input-text" title="Telephone" name="telephone" type="text" /></div>
<div class="input-box"><label for="comment">Comment</label><br /> <textarea id="comment" class="input-text" style="height: 150px; width: 525px;" title="Comment" cols="50" rows="5" name="comment"></textarea></div>
</div>
</li>
</ul>
</fieldset>
<div class="button-set">
<p class="required">* Required</p>
<input id="hideit" style="display:none !important;" name="hideit" type="text" /> <button class="form-button"><span>Submit</span></button></div>
</form>
<script type="text/javascript">// <![CDATA[
   var contactForm = new VarienForm(‘contactForm’, true);
// ]]></script>

And adding fields just put normal fields like how to do it in normal html forms,
then add the variables in the Email Template that you will be using
which can be found at system>email transaction>

next thing is to go to system>Generals>Contacts> setup where the email should be sent.

Configurable Product Magento, switch view more images solved

Once again, I’ve managed to solve one fuzzy client request and stayed the weekend to kick this functionality into action.

My confidence in building website functionalities in the web is bursting that there is no impossible for me already, it just depends in time and of course your budget :D

well…. as usual I am sharing some code snippet that could help some fellow developers out there.

This is to replace the contents within the .more-views class in media.phtml of the product details.

$j(‘.more-views’).html(($j(‘.’+numx)).html());

where numx is the color attribute of the configurable product. this numx also is what I named the class populated hidden within the product detail page.

And is being rendered by this code

<?php

$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 style="display:none;">
        <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>
 </div>
       
        <div style="display:none;">
        <div class=’<?php echo $child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>‘>
            <h2><?php echo $this->__(‘mouse over image to zoom’) ?></h2>
                <ul>
        <li>
        <?php
        $assoc_product = Mage::getModel(‘catalog/product’)->load($child->getId());      
       
        foreach($assoc_product->getMediaGalleryImages() as $assoc_product_img){ ?>
       
                <a href="<?php echo $this->helper(‘catalog/image’)->init($assoc_product, ‘image’, $assoc_product_img->getFile()); ?>" title="<?php echo $assoc_product->getName();?>" onclick="$(’image’).src = this.href; $(’imagex’).src = this.href; return false;">        
 
  <img src="<?php echo $this->helper(‘catalog/image’)->init($assoc_product, ‘thumbnail’, $assoc_product_img->getFile())->resize(70, 70); ?>" alt="<?php echo $this->htmlEscape($assoc_product_img->getLabel()) ?>" title="<?php echo $this->htmlEscape($assoc_product_img->getLabel()) ?>"/>  
</a>
       </li>
        <?php } ?>
        </div>
        </div>
       
<?php } ?>

Ofcourse only demi Gods can understand this without proper explaination. Just PM me if you need something like this.

As I have search the web, I can’t find any solution in magento with this functionality.
This whole project is way beyond the clients budget. Lucky Him

Displaying Product Images of Associated Products with Configurable Products in Magento

<?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 } ?>

The complete snippet is here

<?php

$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

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->__(‘Width’) ?></th>
  <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_width’)); ?></td>
<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

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…..

Zend Framework First Impression

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

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.