I have added attribute Is Child Associated and make it Yes/No field in product create page in magento admin.
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; ?>
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?