Custom Search

Php

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!!!!

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

Product Description HTML break Magento

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

To load subcategories of a category in magento , load the categories first.

$categories =  Mage::getModel(‘catalog/category’)->getCollection()->addAttributeToSelect(‘*’);  
$categories->load();

then filter the categories by parent id of a category

$html .= "<div style=’float:left;’>";    
        $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….

Manipulating Magento Catalog Navigation

How to manipulate Magento Catalog so you can display it anywhere you want in your UI

//Catalog Navigation
<ul>
<?php
$cats = new Mage_Catalog_Block_Navigation();
$maincats       = $cats ->getStoreCategories();
$currentcat     = $cats ->getCurrentCategory();
 
$currentcat     = (is_object($currentcat) ? $currentcat->getName() : );
 
foreach ($maincats as $cat) {
        if ($cat->getName() == $current_cat) {
                echo ‘<li class="active"><a href="’.$this->getCategoryUrl($cat).‘">’.$cat->getName()."</a>\n<ul>\n";
                foreach ($obj->getCurrentChildCategories() as $subcat) {
                        echo ‘<li><a href="’.$this->getCategoryUrl($subcat).‘">’.$subcat->getName()."</a></li>\n";
                }
                echo "</ul>\n</li>\n";
        } else {
                echo ‘<li><a href="’.$this->getCategoryUrl($cat).‘">’.$cat->getName()."</a></li>\n";
        }
}
?>
</ul>

Payroll system Singapore

We are currently arming for a payroll system which is going to be deployed in Linux servers,  my first choice is asp.net mvc but I am not sure if it is supported on the engine that can run asp.net apps to Linux (forgot the name of the engine). So the second choice is PHP, since it is the closest language I am fluent in using next to c#. But building payroll system from scratch is a total pain how much more if I code everything from zero. I have to pick a reliable framework for this. I have a little  experience in cakephp and code igniter but I think this frameworks are still babys frameworks, I need a framework that has proven record and is used in enterprise level of applications. Enter Zend framework,  used by varien to build there magento ecommerce platform, hmmmm…. so I made my choice, zend.

I downloaded the manual documentation and yep, it is in mvc pattern.  So this thing is pretty easier for me.

Now the business analysis part, I am not an accounting Guy, I need to research on how payrolls flow, I really don’t care about this stuffs before.

I will be posting here the codes and scenarios as I move along with this project. Stay tune.

Switch Product Pictures in Product Details of Configurable Products using the configurable Dropdown list

<script language="javascript">
                                       
  var selObjgx = document.getElementById(‘attribute<?php echo $_attribute->getAttributeId() ?>’);
  selObjgx.onchange = function(){                                                
        switchPrimary(selObjgx.options[selObjgx.selectedIndex].text);
   };
</script>
function switchPrimary(numx){
         var primeImage = document.getElementById(‘img’+numx);
         var primeLink = document.getElementById(‘link’+numx);
          $(‘image’).src = primeLink.href; $(‘imagex’).src = primeLink.href; return false;
}

Where,

$(‘image’).src = primeLink.href; $(‘imagex’).src = primeLink.href; return false;

is a jquery script to switch Image , Good Luck1

Magento, Google Chrome, Windows 7 Admin Login Glitch

I have a magento project that is working just fine in Google Chrome browsers on top of windows xp PCs. Last week I upgraded my Operating system to Windows 7. Early this morning, I can’t login to magento admin panel and I think the problem is caused by my Windows 7 upgrade but I don’t know the reason why. Logging in to Firefox is ok, problem is only in Chrome and Internet Explorer.

So I searched the internet, And I found a solution.

1. Log in to admin panel using firefox
2. Go to admin->configuration->web , extend the cookie to 86400.

3. Go to header.html in your theme folder and put this code.

if(!isset($_COOKIE[‘frontend’]))
{
    setcookie("frontend",session_id(),time()+60*60*24,"/","");    
}

4. go to app\design\adminhtml\default\default\template\login.phtml and
put this code.

if(!isset($_COOKIE[‘adminhtml’])):
setcookie(‘adminhtml’,session_id(),time()+24*60*60,"/");
endif;

Thanks. :D

Retrieving Products using Product Attributes of Configurable Products , Magento – Solved

I managed to solve my own problem in retrieving Products using Product Attributes of Configurable Products in Magento,

using the same code that I have in the last post,

<?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()); ?>
 
   
       
        <!– onclick="$(’image’).src = this.href; $(’imagex’).src = this.href; return false;" –>
    <div style="display:none;">
       
        <a href="<?php echo $child->getImageUrl(); ?>" id="<?php echo "link".$child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>"><img src="<?php echo $child->getImageUrl(); ?>" id="<?php echo "img".$child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>" /></a>
       
        </div>
       
<?php } ?>

I added a line of code

$xxx = $parent->getResource()->getAttribute(’Color’)->getFrontend()->getValue($parent);

just before the foreach starts looping.

This is just to trigger the Attributes inside the configurable product so that when the foreach loop start rendering the color attributes of the Configurable Products children,
It will start on the correct Associated Product.

I don’t really know what is the correct explanation for this, maybe I am just lucky I can code things that I don’t understand.

Magento retrieving Product Attributes (’Color’) Problems

I am currency implementing a color swatcher for my Magento Project,
I’ve search for extension in magento connect but can’t find the desired functionality that I want,

currently my product setup is Configurable Product with three attributes in the attribute set name: Color, Size, Occasion.

Now I want to retrieve the Images of the Products associated with the main Configurable product.
I successfully retrieve them, I put ID to them according to the colors.

Now my problem is, why is the first associated product returns no color name, it will just display ‘No’ while the succeeding
Associated Products returns thier color names correctly.

Here is my code.

$product = Mage::getModel(’catalog/product’);
$parent = $product->load($_product ->getId());
$children = Mage::getModel(’catalog/product_type_configurable’)->getUsedProductCollection($parent);

foreach($children as $child){
        $child = $product->load($child->getId());
       
        ?>
        <?php echo $child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>
        <!– onclick="$(’image’).src = this.href; $(’imagex’).src = this.href; return false;" –>
        <div style="display:none;">
        <a href="<?php echo $child->getImageUrl(); ?>" id="<?php echo "link".$child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>"><img src="<?php echo $child->getImageUrl(); ?>" id="<?php echo "img".$child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>" /></a>
</div>

If a Configurable product’s name is Lebron23

then the associated products are
1. Lebron23 RED
2. Lebron23 BLACK
3. Lebron23 GREEN

I want to get the color name and use it for the anchor elements ID,
example: ID=”RED”

in my code, the expected output should be

ID=”RED”
ID=”BLACK”
ID=”GREEN”

but unfortunately the output looks like this.

ID=”NO” <--- it displays "no" and I don't know why?
ID=”BLACK”
ID=”GREEN”

If you happen to knowthe solution for this, please advice…

I am still working on this code as of the moment.. daymmmm….