cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 1.9 Save manually added field to product page into Database.

Magento 1.9 Save manually added field to product page into Database.

I have added attribute Is Child Associated and make it Yes/No field in product create page in magento admin.

 

screenshot-10.7.0.120-2018-04-07-10-03-08.png

 

On the basis of above field I have displayed one dropdown on product page to select child for that product and save it in the db.

I have added below code in

app/design/frontent/rwd/default/template/catalog/product/view.php
<?php               
if ($_product->getAttributeText('is_child_associated') == "Yes"):

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customer = Mage::getSingleton('customer/session')->getCustomer();
    $customerData = Mage::getModel('customer/customer')->load($customer->getId())->getData();
}

$ch = curl_init("http://localhost/store/child?email=".$customerData['email']); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50); 
curl_setopt($ch, CURLOPT_TIMEOUT, 50); 
$response = curl_exec($ch); 
curl_close($ch);

$result = json_decode($response);

if($result != NULL)
{
    echo("<select name='childen' id='childen'>");
    echo("<option value=''>Select child</option>");
    foreach ($result as $key => $value) 
    {
        echo '<option value="'.$value->ID.'">'.$value->ChildFirstName.' '.$value->ChildLastName.' (Grade '.$value->grades->Grade.')</option>';
    }
    echo("</select><span class='error child-error' style='display:none;'>Please select your child.</span>");
}
endif; ?>

screenshot-10.7.0.120-2018-04-07-10-28-12.png

 

Now I want to save above child field into db. How the operation would I perform exactly? Or there is another way to add field and save it into DB?

 

1 REPLY 1

Re: Magento 1.9 Save manually added field to product page into Database.

Hi @Prash159,

 

I guess that second attribute will show different values based on the customer email. Right?