Magento - Controller to Ajax Estimate Shipping: Load Block and display phtml - ajax

I copied estimatePostAction and made estimateAjaxPostAction (overriding core - I did not hack the core). The controller action works as well (class Mage_Checkout_CartController).
Now I want to get/create a block for replacing shipping block after estimate shipping with ajax. I tried this:
public function estimateAjaxPostAction()
{
$country = (string) $this->getRequest()->getParam('country_id');
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
$city = (string) $this->getRequest()->getParam('estimate_city');
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');
$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$this->_getQuote()->save();
//$this->_goBack();
$this->loadLayout();
$block = $this->getLayout()->createBlock('Mage_Checkout_Block_Cart_Shipping','checkout.cart.shipping.ajax',array('template' => 'checkout/cart/shipping.phtml'));
if($block) {
$response = array();
$response['shipping'] = $block->toHtml();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
}
The block checkout.cart.shipping.ajax was created. But toHtml() returns nothing.
My JSON returns:
{"shipping":""}
Why toHtml method doesn't work?
Edit: My block code (checkout/cart/shipping.phtml)
<?php /** #var $this Mage_Checkout_Block_Cart_Shipping */ ?>
<div class="row contem-shipping">
<div class="col-xs-10 shipping">
<div class="text-ship">
<h2><?php echo $this->__('Calcular o frete:') ?></h2>
<p><?php echo $this->__('Insira o CEP do endereço<br />no campo ao lado.') ?></p>
</div>
<div class="shipping-form">
<form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form">
<ul class="form-list">
<li class="no-display">
<div class="input-box">
<?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>
</div>
</li>
<?php if($this->getStateActive()): ?>
<li>
<label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
<div class="input-box">
<select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
<option value=""><?php echo $this->__('Please select region, state or province') ?></option>
</select>
<script type="text/javascript">
//<![CDATA[
$('region_id').setAttribute('defaultValue', "<?php echo $this->getEstimateRegionId() ?>");
//]]>
</script>
<input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>" title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
</div>
</li>
<?php endif; ?>
<?php if($this->getCityActive()): ?>
<li>
<label for="city"<?php if ($this->isCityRequired()) echo ' class="required"' ?>><?php if ($this->isCityRequired()) echo '<em>*</em>' ?><?php echo $this->__('City') ?></label>
<div class="input-box">
<input class="input-text<?php if ($this->isCityRequired()):?> required-entry<?php endif;?>" id="city" type="text" name="estimate_city" value="<?php echo $this->escapeHtml($this->getEstimateCity()) ?>" />
</div>
</li>
<?php endif; ?>
<li>
<div class="input-box">
<input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->escapeHtml($this->getEstimatePostcode()) ?>" />
</div>
</li>
</ul>
<div class="buttons-set">
<button id="button-cep" style="width: 100px;" type="button" title="<?php echo $this->__('Get a Quote') ?>" onclick="calculaFreteAjax(jQuery('#postcode').val()); return false;" class="btn btn-2 btn-2a"><?php echo $this->__('Get a Quote') ?></button>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
new RegionUpdater('country', 'region', 'region_id', <?php echo $this->helper('directory')->getRegionJson() ?>);
//]]>
</script>
<?php $_shippingRateGroups = $this->getEstimateRates(); ?>
<?php if ($_shippingRateGroups): ?>
<form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
<dl class="sp-methods">
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dt><?php echo $this->escapeHtml($this->getCarrierName($code)) ?></dt>
<dd>
<ul>
<?php foreach ($_rates as $_rate): ?>
<li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
<?php if ($_rate->getErrorMessage()): ?>
<?php echo $this->escapeHtml($_rate->getErrorMessage()) ?>
<?php else: ?>
<input name="estimate_method" type="radio" value="<?php echo $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio" />
<label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $this->escapeHtml($_rate->getMethodTitle()) ?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</label>
<?php endif ?>
</li>
<?php endforeach; ?>
</ul>
</dd>
<?php endforeach; ?>
</dl>
</form>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
var coShippingMethodForm = new VarienForm('shipping-zip-form');
var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
coShippingMethodForm.submit = function () {
var country = $F('country');
var optionalZip = false;
for (i=0; i < countriesWithOptionalZip.length; i++) {
if (countriesWithOptionalZip[i] == country) {
optionalZip = true;
}
}
if (optionalZip) {
$('postcode').removeClassName('required-entry');
}
else {
$('postcode').addClassName('required-entry');
}
return VarienForm.prototype.submit.bind(coShippingMethodForm)();
}
//]]>
</script>
</div>
</div>
<div class="col-xs-6">
<?php
$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount(); //total items in cart
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
$subtotal = $totals["subtotal"]->getValue(); //Subtotal value
$grandtotal = $totals["grand_total"]->getValue(); //Grandtotal value
if(isset($totals['discount']) && $totals['discount']->getValue()) {
$discount = $totals['discount']->getValue(); //Discount value if applied
} else {
$discount = '';
}
$shipping = Mage::helper('checkout')->getQuote()->getShippingAddress()->getData();
$tax = $shipping["shipping_amount"];
/*if( $totals["tax"]->getValue()) {
$tax = $totals["tax"]->getValue(); //Tax value if present
} else {
$tax = '';
}*/
?>
<table class="totals-cart">
<tr>
<td class="total-tile">
Subtotal do pedido:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($subtotal, true, false); ?>
</td>
</tr>
<tr>
<td class="total-tile">
Frete:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($tax, true, false); ?>
</td>
</tr>
<?php if ($discount):?>
<tr>
<td class="total-tile">
Desconto:
</td>
<td class="total-price">
<?php echo Mage::helper('core')->currency($discount, true, false); ?>
</td>
</tr>
<?php endif;?>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-16">
<div class="grand-total">
<p class="text">Total:</p>
<p class="price"><?php echo Mage::helper('core')->currency($grandtotal, true, false);?></p>
</div>
</div>
</div>
<script type="text/javascript">
function calculaFreteAjax(cep) {
jQuery('.contem-shipping .shipping').html('<span class="remove-frete" style="display: block; margin: 0 auto; width: 20px;" id="login-please-wait"><img src="http://sites.xpd.com.br/cpaps/skin/frontend/xpd/default/images/opc-ajax-loader.gif" class="v-middle" alt=""/></span>');
var param = {'country_id': 'BR','estimate_postcode': cep};
console.log(param);
jQuery.ajax({
type: "GET",
url: '<?php echo Mage::getBaseUrl().'checkout/cart/estimateAjaxPost/'; ?>', //My Custom Controller
data: param,
success: function(response) {
response = jQuery.parseJSON(response);
if(response.shipping) {
jQuery('.contem-shipping').parent().html(response.shipping);
}
else {
alert('Falha ao calcular o frete. Tente novamente.');
}
}
});
jQuery('#co-shipping-method-form dd input.radio').click(function(){
//I will submit the shipping method selected
});
}
</script>

Denis... I have modify code please check
public function estimateAjaxPostAction()
{
$country = (string) $this->getRequest()->getParam('country_id');
$postcode = (string) $this->getRequest()->getParam('estimate_postcode');
$city = (string) $this->getRequest()->getParam('estimate_city');
$regionId = (string) $this->getRequest()->getParam('region_id');
$region = (string) $this->getRequest()->getParam('region');
$this->_getQuote()->getShippingAddress()
->setCountryId($country)
->setCity($city)
->setPostcode($postcode)
->setRegionId($regionId)
->setRegion($region)
->setCollectShippingRates(true);
$this->_getQuote()->save();
$response = array();
$response['shipping']=$this->eastmatesajax();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
}
protected function eastmatesajax()
{
$layout=$this->getLayout();
$layout->getMessagesBlock()->setMessages(Mage::getSingleton('checkout/session')->getMessages(true),Mage::getSingleton('catalog/session')->getMessages(true));
$block = $this->getLayout()->createBlock('checkout/cart_shipping')->setTemplate( 'checkout/cart/shipping.phtml');
return $block->toHtml();
}

Updated block issue solved using $this->_getQuote()->collectTotals(); before $this->_getQuote()->save();

Related

if click default button address should be default

One user multiple shipping address how to make it as default,if click the make as default button,that address should be default and remaining all address shown the make as default button in a particular address box,except default address box.
view page
<?php foreach ($buyer_Address as $row) { ?>
<div class="col-md-4">
<div class="panel panel-default add_min_height">
<div class="panel-heading">Default:</div>
<input type="hidden" name="de" id="de" value="<?php echo $row->b_id; ?>">
<div class="panel-body">
<address><?php echo $row->b_fullname; ?><br>
<?php echo $row->b_street_address; ?>,<?php echo $row->b_locality ?>,<br>
<?php echo $row->b_landmark; ?>,
<?php echo $row->b_city; ?>, <?php echo $row->b_state; ?>,<?php echo $row->b_pincode; ?>
India
Phone number: <?php echo $row->b_mobile_number; ?></address>
</div>
<div class="panel-footer">
<a href="<?php echo base_url(); ?>index.php/welcome/buyereditaddress?id=<?php echo $row->b_id; ?>" >Edit</a>
<i class="fa fa-ellipsis-v"></i>
Delete
<i class="fa fa-ellipsis-v"></i>
<?php if ($row->status == '0') { ?>
<button type="submit" style="color:#337ab7;background: none !important;border: none;" name="default" id="default">Make as deafault</button>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
controller
public function defaultAddress() {
$id = $this->input->post('de');
$this->BuyerProfile_Model->defaultAddress($id);
redirect('welcome/buyeraddresses');
}
model
function defaultAddress($id) {
$this->db->trans_start();
$this->db->query("UPDATE buyer_order_address SET status = '0' WHERE b_id = '$id'");
$this->db->query("UPDATE buyer_order_address SET status = '1' WHERE b_id = '$id'");
$this->db->trans_complete();
}

delete condition if multiple checkbox unchecked in codeigniter

please help me i would like to delete some check box if checkbox unchecked.
My checkbox is automatic show from database my sql. and i would like to delete some checkbox when checkbox in not checked.
PLease Help
its my controller
public function edit_overview($id_product)
{
if ($this->input->post('submit')) {
foreach ($id_overview = $this->input->post('id_overview') as $rm) {
$check_idoverview = $this->Biostar->check_idoverview($id_product, $rm);
if ($check_idoverview==unchecked){
$data['file'] = $check_idoverview;
$this->Biostar->delete_overview($check_idoverview,$id_product);
}else{
if ($check_idoverview > 0) {
} else {
$datafield = array(
'id_product' => $id_product,
'id_overview' => $rm
);
$this->Biostar->saveoverviewproduct($datafield);
$message_success = "Data Has Been Update";
}
}
}
}
$data['message_success'] = #$message_success;
$field = $this->Biostar->get_overview($id_product);
$fieldid_product = $this->Biostar->get_id_product($id_product);
$data['field'] = $field;
$data['id_product'] = $fieldid_product;
$data['content'] = "biostar/edit_overview_product";
$this->load->view('dashboard/index', $data);
}
My Model
function delete_overview($check_overview,$id_product)
{
$sql = "delete from overview_briostar where id_overview='$check_overview' AND id_product='$id_product'";
return $sql;
}
My View
<form method="post" action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $id_product->id_product; ?>">
<div class="box-body">
<?php foreach ($speed as $row){ ?>
<div class="checkbox">
<label>
<input type="checkbox" name="id_overview[]" onClick="EnableSubmit3(this)" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
<!-- /input-group -->
</div>
<div class="box-footer">
<input value="Submit" type="submit" id="submit3" name="submit" class="btn btn-primary">
</div>
</form>
Unchecked checkbox value will not get posted, so you have to use jquery and ajax
Your checkbox
<input class="id_overview" type="checkbox" name="id_overview[]" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
your jquery
<script type="text/javascript">
$(document).ready(function() {
$("form#frm").submit(function(e) { // give a id to your form
e.preventDefault();
var ids = new Array();
$('.id_overview').each(function() {
if ($(this).is(':checked')) {
} else {
ids.push($(this).val());
}
});
$.ajax({
// send ids through your ajax code
});
});
});
</script>
create a new function and call it by ajax to delete the ids.
You can try like this
<form method="post" action="<?php echo base_url(); ?>biostar/add_overview_product/<?php echo $id_product->id_product; ?>">
<div class="box-body">
<?php foreach ($speed as $row){ ?>
<div class="checkbox">
<label>
<input type="hidden" name="all_id[]" value="<?php echo $row['id_overview']; ?>" />
<input type="checkbox" name="id_overview<?php echo $row['id_overview']; ?>" onClick="EnableSubmit3(this)" value="<?php echo $row['id_overview']; ?>"<?php foreach ($field as $wor){ ?> <?php if($row['id_overview']==$wor['id_overview']) echo "checked";?> <?php } ?> ><?php echo $row['title']; ?>
</label>
</div>
<?php } ?>
<!-- /input-group -->
</div>
<div class="box-footer">
<input value="Submit" type="submit" id="submit3" name="submit" class="btn btn-primary">
</div>
</form>
and in you controller
if ($this->input->post('submit')) {
foreach($all_id as $row_id)
{
if($this->input->post('id_overview'.$row_id))
{
//do action where id is present
}
else
{
//do action if unchecked by getting id $row_id
}
}
}

How do I grab only comments posted by current concrete5 logged in user?

This code displays all comments by all members. How can I make this only show comments that the current logged in user posted?
I know this is simple code but for the life of me I can not seem to get it.
The code listed below is the original code from the view.php file located in the guestbook block.
<?php $c = Page::getCurrentPage(); ?>
<h4 class="guestBook-title"><?php echo $controller->title?></h4>
<?php if($invalidIP) { ?>
<div class="ccm-error"><p><?php echo $invalidIP?></p></div>
<?php } ?>
<?php
$u = new User();
if (!$dateFormat) {
$dateFormat = t('M jS, Y');
}
$posts = $controller->getEntries();
$bp = $controller->getPermissionObject();
$dh = Loader::helper('date');
foreach($posts as $p) { ?>
<?php if($p['approved'] || $bp->canWrite()) { ?>
<div class="guestBook-entry<?php if ($c->getVersionObject()->getVersionAuthorUserName() == $u- >getUserName()) {?> authorPost <?php }?>">
<?php if($bp->canWrite()) { ?>
<div class="guestBook-manage-links">
<?php echo t('Edit')?> |
<?php echo t('Remove')?> |
<?php if($p['approved']) { ?>
<?php echo t('Un-Approve')?>
<?php } else { ?>
<?php echo t('Approve')?>
<?php } ?>
</div>
<?php } ?>
<div class="contentByLine">
<!---<?php echo t('Posted by')?>
<span class="userName">
<?php
if( intval($p['uID']) ){
$ui = UserInfo::getByID(intval($p['uID']));
if (is_object($ui)) {
echo $ui->getUserName();
}
}else echo $p['user_name'];
?>
</span>
<?php echo t('on')?>--->
<span class="contentDate">
<?php echo $dh->date($dateFormat,strtotime($p['entryDate']));?>
</span>
</div>
<?php echo nl2br($p['commentText'])?>
</div>
<?php } ?>
<?php }
if (isset($response)) { ?>
<?php echo $response?>
<?php } ?>
<?php if($controller->displayGuestBookForm) { ?>
<?php
if( $controller->authenticationRequired && !$u->isLoggedIn() ){ ?>
<div><?php echo t('You must be logged in for notes.')?> <?php echo t('Login')?> »</div>
<?php }else{ ?>
<a name="guestBookForm-<?php echo $controller->bID?>"></a>
<div id="guestBook-formBlock-<?php echo $controller->bID?>" class="guestBook-formBlock">
<!---<h5 class="guestBook-formBlock-title"><?php echo t('Leave a Reply')?></h5>--->
<form method="post" action="<?php echo $this->action('form_save_entry', '#guestBookForm-'.$controller->bID)?>">
<?php if(isset($Entry->entryID)) { ?>
<input type="hidden" name="entryID" value="<?php echo $Entry->entryID?>" />
<?php } ?>
<?php if(!$controller->authenticationRequired){ ?>
<label for="name"><?php echo t('Name')?>:</label><?php echo (isset($errors['name'])?"<span class=\"error\">".$errors['name']."</span>":"")?><br />
<input type="text" name="name" value="<?php echo $Entry->user_name ?>" /> <br />
<label for="email"><?php echo t('Email')?>:</label><?php echo (isset($errors['email'])?"<span class=\"error\">".$errors['email']."</span>":"")?><br />
<input type="email" name="email" value="<?php echo $Entry->user_email ?>" /> <span class="note">(<?php echo t('Your email will not be publicly displayed.')?>)</span> <br />
<?php } ?>
<?php echo (isset($errors['commentText'])?"<br /><span class=\"error\">".$errors['commentText']."</span>":"")?>
<textarea name="commentText"><?php echo $Entry->commentText ?></textarea><br />
<?php
if($controller->displayCaptcha) {
$captcha = Loader::helper('validation/captcha');
$captcha->label();
$captcha->showInput();
$captcha->display();
echo isset($errors['captcha'])?'<span class="error">' . $errors['captcha'] . '</span>':'';
}
?>
<br/><br/>
<input type="submit" name="Post Comment" value="<?php echo t('Save Note')?>" class="button"/>
</form>
</div>
<?php } ?>
Every $posts ($p) is an array. When you print the array you will notice the ID of the author is present in the array.
If you'd like to show only the comments of the logged in user, you should override the view.php and replace line number 16
<?php if($p['approved'] || $bp->canWrite()) { ?>
to
<?php if(($p['approved'] || $bp->canWrite()) && $u->getUserID() == $p['uID']) { ?>
When you've changed that line of code, a user should only see his/her comments and not the comment of someone else.

Implementing Lightbox in Magento

I already have an existing page which I'm trying to turn into a Magento website. One the pages I'm working on makes use of Lightbox. I tried including the lightbox file through Design in the CMS Page. Same for content but it didn't work there. Is there any way I can include the lightbox javascript from the previous website without having to touch the xml, html and php files? How do I make the lightbox work on the website?
You can always add a javascript file to the page's head by adding the following to the design tab of your CMS page (note that the path is relative to the root js directory). However, if you plan on using lightbox on multiple pages, this would not be the preferred method because you'd have to copy this into the design tab of every page you needed it on.
<reference name="head">
<action method="addJs"><js>custom/lightboxjs</js></action>
</reference>
View.PHTML
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<?php $config = Mage::getStoreConfig('mdloption/product-type-option'); ?>
<?php if($config['product-view-option'] !=2 && $config['product-view-option'] !=3): ?>
<?php $classnNum ='span9'?>
<?php else:?>
<?php $classnNum ='f-fix'?>
<?php endif; ?>
<?php if($config['product-view-option']==3):?>
<?php $classnNum2 = 'left-carousel'?>
<?php endif; ?>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="product-view <?php echo $classnNum; ?>">
<!--<a class="prePage" href="<?php //echo $_SESSION['core']['last_url'];?>"><?php //echo $this->__('Return to Previous Page')?></a>-->
<!--Prev/Next Code Start-->
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
$prev_url = $next_url = $url = $_product->getProductUrl();
if ($this->helper('catalog/data')->getCategory()) {
$category = $this->helper('catalog/data')->getCategory();
} else {
$_ccats = $this->helper('catalog/data')->getProduct()->getCategoryIds();
$category = Mage::getModel('catalog/category')->load($_ccats[0]);
}
$children = $category->getProductCollection();
$_count = is_array($children) ? count($children) : $children->count();
if ($_count) {
foreach ($children as $product) {
$plist[] = $product->getId();
}
$current_pid = $this->helper('catalog/data')->getProduct()->getId();
$curpos = array_search($current_pid, $plist);
$previd = isset($plist[$curpos+1])? $plist[$curpos+1] : $current_pid;
$product = Mage::getModel('catalog/product')->load($previd);
$prevpos = $curpos;
while (!$product->isVisibleInCatalog()) {
$prevpos += 1;
$nextid = isset($plist[$prevpos])? $plist[$prevpos] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
}
$prev_url = $product->getProductUrl();
$nextid = isset($plist[$curpos-1])? $plist[$curpos-1] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
$nextpos = $curpos;
while (!$product->isVisibleInCatalog()) {
$nextpos -= 1;
$nextid = isset($plist[$nextpos])? $plist[$nextpos] : $current_pid;
$product = Mage::getModel('catalog/product')->load($nextid);
}
$next_url = $product->getProductUrl();
}
?>
<!--Prev/Next Code End-->
<div class="product-essential">
<div class="product-img-box span6 <?php echo $classnNum2;?>"> <?php echo $this->getChildHtml('media') ?> </div>
<div class="productDetailBox span6">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field_1" value="" />
</div>
<div class="product-shop">
<div class="product_left f-fix">
<div class="nextPre">
<!-- <a rel="tooltip" data-placement="left" title="<?php echo $this->__('No Products')?>" class="prod-prev disable" href="JavaScript:void(0);">Prev</a>
<a rel="tooltip" data-placement="right" title="<?php echo $this->__('No Products')?>" class="prod-next disable" href="JavaScript:void(0);">NEXT</a>-->
<?php if ($url <> $prev_url):?>
<a class="prod-next" rel="tooltip" data-placement="right" title="<?php echo $this->__('Volgende product')?>" href="<?php echo $prev_url; ?>"><i class="fa fa-angle-right"></i></a>
<?php endif; ?>
<?php if ($url <> $next_url):?>
<a rel="tooltip" data-placement="left" title="<?php echo $this->__('Vorige product')?>" class="prod-prev" href="<?php echo $next_url; ?>"><i class="fa fa-angle-left"></i></a>
<?php endif; ?>
</div>
<div class="product-name">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>
<div class="review"> <?php echo $this->getReviewsSummaryHtml($_product, false, true)?> </div>
<div class="stock_box">
<?php if ($_product->isAvailable()): ?>
<p class="availability in-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('<i class="fa fa-check-circle"></i> Beschikbaar') ?></span></p>
<?php else: ?>
<p class="availability out-of-stock"><?php echo $this->__('Availability:') ?> <span><?php echo $this->__('<i class="fa fa-times-circle"></i> Verkocht') ?></span></p>
<?php endif; ?>
</div>
<?php if ($_product->getShortDescription()):?>
<div class="short-description">
<div class="std"><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></div>
</div>
<?php endif;?>
<div class="pro-left">
<div class="add_to_cart">
<?php if (!$this->hasOptions()):?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php endif; ?>
<div class="price_box">
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getTierPriceHtml()?>
</div>
</div>
<?php endif; ?>
<?php echo $this->getChildHtml('other');?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<div class="price_box">
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getTierPriceHtml()?>
</div>
<?php endif;?>
<div class="clear"></div>
</div>
<div class="f-fix">
<?php echo $this->getChildHtml('extrahint') ?>
<?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
<?php if ($this->canEmailToFriend()): ?>
<p class="email-friend"><a rel="tooltip" data-placement="top" title="<?php echo $this->__('Email to a Friend') ?>" href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>"><i class="fa fa-envelope"></i> <?php echo $this->__('Email to a Friend') ?></a></p>
<?php endif; ?>
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f74bbe87b978120"></script>
<!-- AddThis Button END -->
</div>
</div>
</div>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('static_links')->toHtml() ?>
</div>
</form>
</div>
<div class="product-collateral" id="tabs">
<?php echo $this->getChildHtml('info_tabs') ?>
</div>
</div>
</div>
<?php if($config['product-view-option'] !=2 && $config['product-view-option'] !=3): ?>
<div class="product_right span3">
<?php $config = Mage::getStoreConfig('mdloption/upsellsetting'); ?>
<?php if($config['upsellblocks']==1):?>
<?php echo $this->getChildHtml('upsell_products'); ?>
<?php elseif($config['upsellblocks']==2):?>
<?php if($_product->getUpsellProducts()): ?>
<?php echo $this->getChildHtml('upsell_products'); ?>
<?php else: ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('productBanner')->toHtml() ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product_custom_block')->toHtml() ?>
<?php endif ?>
<?php elseif($config['upsellblocks']==3):?>
<?php echo $this->getChildHtml('upsell_products'); ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('productBanner')->toHtml() ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product_custom_block')->toHtml() ?>
<?php endif;?>
<div class="staticSidebar">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('product-static-box')->toHtml() ?>
</div>
</div>
<?php endif; ?>
<?php //echo $this->getChildHtml('upsell_products'); ?>
<?php //echo $this->getChildHtml('related'); ?>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("a[rel=example_group]").fancybox({
hideOnContentClick : true,
showNavArrows : false,
arrows : false,
showTitle : false,
scrolling : 'no',
'transitionIn' : 'none',
'transitionOut' : 'none',
'titlePosition' : 'over',
'titleFormat' : function(title, currentArray, currentIndex, currentOpts) {
return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' ' + title : '') + '</span>';
}
});
});
</script>

How to insert custom option into Magento theme product view template?

I've created a custom Magento theme for a jewelry store and for a ring that I've
added as a sample product, I created a custom option for ring size (a SELECT field).
How do I insert just that custom option above the 'add to cart' button in my
product view.phtml template file?
Here is the page: http://s1.mynewsitereview.com/fire-opal-ring.html
And here is my view.phtml code:
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>
<script type="text/javascript">
var optionsPrice = new Product.OptionsPrice(<?php echo $this->getJsonConfig() ?>);
</script>
<div id="messages_product_view"><?php echo $this->getMessagesBlock()->getGroupedHtml() ?></div>
<div class="product-view">
<div class="product-essential">
<form action="<?php echo $this->getSubmitUrl($_product) ?>" method="post" id="product_addtocart_form"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<div class="no-display">
<input type="hidden" name="product" value="<?php echo $_product->getId() ?>" />
<input type="hidden" name="related_product" id="related-products-field" value="" />
</div>
<div class="product-img-box">
<?php echo $this->getChildHtml('media') ?>
</div>
<div class="product-shop">
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
<?php if ($_product->getShortDescription()):?>
<p><?php echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description') ?></p>
<?php endif;?>
<?php echo $this->getTierPriceHtml() ?>
<?php echo $this->getChildHtml('alert_urls') ?>
<?php echo $this->getChildHtml('product_type_data') ?>
<?php echo $this->getChildHtml('extrahint') ?>
<p class="email-friend">
<?php if ($this->canEmailToFriend()): ?>
<?php echo $this->__('Email to a Friend') ?><br>
<?php endif; ?>
<?php echo $this->getReviewsSummaryHtml($_product, false, true)?>
</p>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<div><?php if( $this->helper('wishlist')->isAllow() || $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product)): ?>
<?php endif; ?>
<?php endif; ?>
<?php echo $this->getChildHtml('addto') ?>
</div>
</div>
</form>
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
//]]>
</script>
</div>
<div class="product-collateral">
<?php echo $this->getChildHtml('other');?>
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
<?php endif;?>
</div>
</div>
Add this code
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
in your view.phtml file just above the
<?php echo $this->getChildHtml('addtocart') ?>

Resources