PHP/CSS & Alignment of Columns - php

I started learning PHP/CSS/HTML5 & Java a month ago and I'm currently setting up an online shop for my new home business. I'm using opencart, but i'm having difficulty with transforming some of the PHP in terms of getting it to display side by side.
This is how I would like it to look.
Price: $000.00000
<table width="200" border="0">
<tr>
<td>Option 1</td>
<td>Option 2</td>
</tr>
<tr>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
</tr>
</table>
I've figured out how to do this in CSS, but the required radio radio buttons (see the code below) is the same code for option 1 & 2.
It currently looks like this
Price $000.0000
Option 1
1
2
3
Option 2
1
2
3
<?php if ($price) { ?>
<div class="price">
<span class="text-price"><?php echo $text_price; ?></span>
<?php if (!$special) { ?>
<span class="price-new"><?php echo $price; ?> <span style="font-size:10px;">pp</span></span>
<?php } else { ?>
<span class="price-new"><?php echo $special; ?></span><span class="price-old"><?php echo $price; ?></span>
<?php } ?>
<?php if ($tax) { ?>
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $tax; ?></span>
<?php } ?>
<?php if ($points) { ?>
<span class="reward"><small><?php echo $text_points; ?> <?php echo $points; ?></small></span>
<?php } ?>
<?php if ($discounts) { ?>
<div class="discount">
<?php foreach ($discounts as $discount) { ?>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?><br />
<?php } ?>
</div>
<?php } ?>
</div>
<?php } ?>
<?php if ($profiles): ?>
<div class="option">
<h2><span class="required">*</span><?php echo $text_payment_profile ?></h2>
<br />
<select name="profile_id">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($profiles as $profile): ?>
<option value="<?php echo $profile['profile_id'] ?>"><?php echo $profile['name'] ?></option>
<?php endforeach; ?>
</select>
<br />
<br />
<span id="profile-description"></span>
<br />
<br />
</div>
<?php endif; ?>
<?php if ($options) { ?>
<div class="options">
<h2><?php echo $text_option; ?></h2>
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<label><?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b></label>
<select name="option[<?php echo $option['product_option_id']; ?>]">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
</div>
<?php } ?>
<?php if ($option['type'] == 'radio') { ?>
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<label>
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b></label>
<?php foreach ($option['option_value'] as $option_value) { ?>
<label class="radio" for="option-value-<?php echo $option_value['product_option_value_id']; ?>">
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="option-value-<?php echo $option_value['product_option_value_id']; ?>" /><?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
</label>
<?php } ?>

Why don't you display your table dynamically and then simply style it in CSS using nth-child(#)? You can simply loop through an array and display echo each row before closing out the table after.

Related

Grouped Product won't be added to cart and there is a message "Please specify the quantity of product(s)."

I am developing a store and the product I tried to add is a grouped product which I had done some design and configuration on the front end. Then, I added sample grouped product and when I click "Add to cart" , there is message "Please specify the quantity of product(s)."
Please see the website (Sorry the website is in Thai but you can try to increase the Quantity of each product and then click add to cart - Pink button)
http://www.preciosathailand.com/eyeline-0001.html
This is PHP code that I made the configuration
<?php if ($_hasAssociatedProducts): ?>
<?php foreach ($_associatedProducts as $_item): ?>
<?php $_finalPriceInclTax = $this->helper('tax')->getPrice($_item, $_item->getFinalPrice(), true) ?>
<tr>
<td width="80%"><span class="product-<?php echo $_item->getId() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></span></td>
<?php if ($this->getCanShowProductPrice($_product)): ?>
<td class="a-right">
<?php if ($this->getCanShowProductPrice($_item)): ?>
<?php echo $this->getPriceHtml($_item, true) ?>
<?php echo $this->getTierPriceHtml($_item) ?>
<?php endif; ?>
</td>
<?php endif; ?>
<?php if ($_product->isSaleable()): ?>
<td class="a-center" width="20%">
<?php if ($_item->isSaleable()) : ?>
<div class="qty-tools">
<div class="minus-qty minus-<?php echo $_item->getId() ?>"><a class="click-to-minus" id="minus-<?php echo $_item->getId() ?>" href="#" data-id-p="<?php echo $_item->getId() ?>">-</a></div>
<div class="input-qty-wrapper">
<input type="text" name="super_group[<?php echo $_item->getId() ?>]" data-qty-product-id="<?php echo $_item->getId() ?>" maxlength="12" value="<?php echo $_item->getQty()*1 ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" />
</div>
<div class="plus-qty plus-<?php echo $_item->getId() ?>"><a class="click-to-plus" href="#" id="plus-<?php echo $_item->getId() ?>" data-id-p="<?php echo $_item->getId() ?>">+</a></div>
</div>
<?php else: ?>
<p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="<?php if ($_product->isSaleable()): ?>4<?php else : ?>3<?php endif; ?>"><?php echo $this->__('No options of this product are available.') ?></td>
</tr>
<?php endif; ?>
This is jQuery that I have done.
jQuery(document).ready(function(){
jQuery('.click-to-minus').click(function(){
var IDInput = jQuery(this).data('id-p');
var CurrentVal = jQuery('input[name="super_group['+IDInput+']"]').val();
var minusedVal = CurrentVal-1;
jQuery('input#'+IDInput).val(minusedVal);
});
jQuery('.click-to-plus').click(function(){
var pIDInput = jQuery(this).data('id-p');
var CurrentPlusVal = jQuery('input[name="super_group['+pIDInput+']"]').val();
/* if ( CountPlus == 0){
var plusedVal = 1;
}else{
jQuery('input#'+pIDInput).val('');
var plusedVal = CurrentPlusVal+1;
}*/
var plusedVal = +CurrentPlusVal+1;
jQuery('input[data-qty-product-id="'+pIDInput+'"]').val(plusedVal);
});
});
Did I do anything wrong?
Are you trying to group configurable products, then you should know that magento doesnt allow it.
you can check this answer here

Super filter attribuites to display as dropdown instead of checkbox

I am using Opencart 2.2.0 on Journal theme. I am using super filter to display attributes. The problem is - this filter only displays as check box. I need it to display as drop down. The theme maker told me that module only shows in check box option, but I am wondering if I can make it display as drop down instead. The code for super_filter_attributes.tpl is:
<div class="box sf-attribute sf-attribute-<?php echo $attribute['attribute_id']; ?> sf-<?php echo $attribute['type']; ?>">
<div class="box-heading"><?php echo $attribute['attribute_name']; ?></div>
<div class="box-content">
<ul class="<?php echo $this->journal2->settings->get('filter_show_box') ? '' : 'hide-checkbox'; ?>">
<?php foreach ($attribute['values'] as $value) { ?>
<li><label><input data-keyword="<?php echo $value['keyword']?>" type="checkbox" name="attribute[<?php echo $attribute['attribute_id']?>]" value="<?php echo $value['text']; ?>"><?php echo $value['name']; ?></label></li>
<?php } ?>
</ul>
</div>
I edited a bit and now my code looks like this:
<div class="box sf-attribute sf-attribute-<?php echo $attribute['attribute_id']; ?> sf-<?php echo $attribute['type']; ?>">
<div class="box-heading"><?php echo $attribute['attribute_name']; ?></div>
<div class="box-content">
<ul class="<?php echo $this->journal2->settings->get('filter_show_box') ? '' : 'hide-checkbox'; ?>">
<div class="box sf-attribute sf-attribute-<?php echo $attribute['attribute_id']; ?> sf-<?php echo $attribute['type']; ?>">
<div class="box-heading"><?php echo $attribute['attribute_name']; ?></div>
<div class="box-content">
<ul class="<?php echo $this->journal2->settings->get('filter_show_box') ? '' : 'hide-checkbox'; ?>">
<?php foreach ($attribute['values'] as $value) { ?>
<select>
<option><?php echo $value['name']; ?></option>
<?php foreach ($value['filter'] as $filter) { ?>
<?php if (in_array($filter['filter_id'], $filter_category)) { ?>
<option value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>" selected>
<?php echo $filter['name']; ?>
</option>
<?php } else { ?>
<option value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>">
<?php echo $filter['name']; ?>
</option>
<?php } ?>
<?php } ?>
</select>
<?php } ?>
</ul>
</div>
I am not doing everything good, because I can see only partial drop down now, and all is mixed up.
Any suggestions to edit my code? Thank you all in advance!
Put select tag outside foreach. This may help.
<select> <?php foreach ($attribute['values'] as $value) { ?>
<option><?php echo $value['name']; ?></option>
<?php foreach ($value['filter'] as $filter) { ?>
<?php if (in_array($filter['filter_id'], $filter_category)) { ?>
<option value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>" selected>
<?php echo $filter['name']; ?>
</option>
<?php } else { ?>
<option value="<?php echo $filter['filter_id']; ?>" id="filter<?php echo $filter['filter_id']; ?>">
<?php echo $filter['name']; ?>
</option>
<?php } ?>
<?php } ?>
<?php } ?>
</select>

Format opencart select option value

I have the option named artwork which has 3 values (We Design Single, We Design Double, Upload Artwork).
I want to edit the view product.tbl to format the "We Design Single" and "We Design Double" So it only shows as "We Design".
I think this is the part of the code i need to edit but unsure how
<div id="option-<?php echo $option['product_option_id']; ?>" class="option">
<?php if ($option['required']) { ?>
<span class="required">*</span>
<?php } ?>
<b><?php echo $option['name']; ?>:</b><br />
<select name="option[<?php echo $option['product_option_id']; ?>]">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>">
?php echo $option_value['name']; ?> <?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><span id="newPrice"><?php echo
$option_value['price']; ?></span>)
<?php } ?>
</option>
<?php } ?>
</select>
</div>
I think you would use an if statement to determine if the 'product_option_value_id' == 'We Design Single' || 'product_option_value_id'=='We Design Single' then use substr() to display only part of 'product_option_value_id'.
Any Ideas?
<?php if ($option_value['name'] == 'We Design Single' || $option_value['name'] == 'We Design Double') { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo "We Design" ?>
<?php } else { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
<?php } ?>
Got it working anyway

Magento override Shipping section template

I have overriden the following core template in checkout process shipping section.
app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml
I have two shipping methods. First one is 'Deliveryrate'. In this module I have overriden the above template file. Second shipping module is 'Store-Pickup'. But when I load the 'Store-Pickup' always loading the Deliveryrate'. I couldn't find the error. Please any suggestions?
following is the edited template file.
<?php if (!($_shippingRateGroups = $this->getShippingRates())): ?>
<p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
<?php else: ?>
<dl class="sp-methods">
<?php $shippingCodePrice = array(); ?>
<?php $_sole = count($_shippingRateGroups) == 1;
foreach ($_shippingRateGroups as $code => $_rates): ?>
<?php
$helper = Mage::helper('deliveryrate');
$isFlorist = $helper->IsCollectFromFlorist();
if(!$isFlorist)
{
?>
<?php if($code == 'deliveryrate') // If the shipping method is deliveryshipping
{?>
<?php
// Get deliveryrate option details.
$all_options = Mage::getModel('deliveryrate/alloptions')->getCollection();
?>
<dt><?php echo $this->getCarrierName($code) ?></dt> <?php //header ?>
<dd>
<ul>
<table id="tbl-delivery-shipping">
<tbody>
<tr>
<td><label for="delivery-options" class="required" style="float:right;"><em>*</em>Delivery Time :</label></td>
<td>Option 1 - Standard Delivery
</tr>
<tr>
<td></td>
<td>
<?php $_sole = $_sole && count($_rates) == 1;
foreach ($_rates as $_rate): ?>
<?php
$option = $_rate->getCode();
$optionArray = explode( '_', $option );
$array_last_index = count($optionArray)-1;
$delivery_option = $optionArray[$array_last_index-1];
if($delivery_option == 1)
{
?>
<li>
<?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
<li>
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages">
<li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li>
</ul>
<?php else: ?>
<?php if ($_sole) : ?>
<span class="no-display">
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" />
</span>
<?php else: ?>
<?php // radio button ?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
<script type="text/javascript">
//<![CDATA[
lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
//]]>
</script>
<?php endif; ?>
<?php endif; ?>
<?php // option name ?>
<label for="s_method_<?php echo $_rate->getCode() ?>">
<?php $option_name = $_rate->getMethodTitle();
$optionNameArray = explode( '(', $option_name );
if(count($optionNameArray)>1)
{
echo $optionNameArray[0];
?>
<br>
<?php
echo '('.$optionNameArray[1];
}
else
{
echo $optionNameArray[0];
}
?>
<?php // echo $_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
$carrier = Mage::getModel('shipping/config')->getCarrierInstance($code);
if($carrier->getFormBlock()){
$block = $this->getLayout()->createBlock($carrier->getFormBlock());
$block->setMethodCode($code);
$block->setRate($_rate);
$block->setMethodInstance($carrier);
echo $block->_toHtml();
}
?>
<?php endif ?>
</li>
<?php } ?>
<?php endforeach; ?>
</td>
</tr>
<tr>
<td><br></td>
<td></td>
</tr>
<tr>
<td></td>
<td>Option 2 - specific Time
<label style="font-size: 12px;font-weight:normal;color:silver;">(There will be an additional delivery charge for specific delivery time.)</label>
</tr>
<tr>
<td></td>
<td>
<ul>
<?php $_sole = $_sole && count($_rates) == 1;
foreach ($_rates as $_rate): ?>
<?php
$option = $_rate->getCode();
$optionArray = explode( '_', $option );
$array_last_index = count($optionArray)-1;
$delivery_option = $optionArray[$array_last_index-1];
if($delivery_option == 2)
{
?>
<?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
<li style="width:250px;float:left;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages">
<li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li>
</ul>
<?php else: ?>
<?php if ($_sole) : ?>
<span class="no-display">
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" />
</span>
<?php else: ?>
<?php // radio button ?>
<?php
foreach($all_options as $opt)
{
$data = $opt->getData();
if($current_category_id == 12)//Cake
{$kk = trim(date("Y-m-d", $tomorrow));
if(trim(date("Y-m-d", $tomorrow)) == trim($order_delivery_date))
{
if(strcmp(trim($_rate->getMethodTitle()),trim($data['delivery_type'])) == 0)
{
$start_time = $data['start_time'];
$end_time = $data['end_time'];
if($delivery_start_time < $start_time)// || (($start_time < $delivery_start_time) && ($delivery_start_time < $end_time)))
{
// Enable option.
?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
}
else
{
?>
<input disabled="disabled" name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
}
}
}
else
{
?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
break;
}
}
else //Rest all products
{
if(trim(date("Y-m-d")) == trim($order_delivery_date))//today's delivery
{
//check the server time to enable option
if(strcmp(trim($_rate->getMethodTitle()),trim($data['delivery_type'])) == 0)
{
$start_time = $data['start_time'];
$end_time = $data['end_time'];
if($server_time < $start_time)// || (($start_time < $server_time) && ($server_time < $end_time)))
{
// Enable option.
?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
}
else
{
?>
<input disabled="disabled" name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
}
}
}
else
{
?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
break;
}
}
}//foreach
?>
<?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
<script type="text/javascript">
//<![CDATA[
lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
//]]>
</script>
<?php endif; ?>
<?php endif; ?>
<?php // option name ?>
<label for="s_method_<?php echo $_rate->getCode() ?>">
<?php $option_name = $_rate->getMethodTitle();
$optionNameArray = explode( '(', $option_name );
if(count($optionNameArray)>1)
{
echo $optionNameArray[0];
?>
<br>
<?php
echo '('.$optionNameArray[1];
}
else
{
echo $optionNameArray[0];
}
?>
<?php // echo $_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
$carrier = Mage::getModel('shipping/config')->getCarrierInstance($code);
if($carrier->getFormBlock()){
$block = $this->getLayout()->createBlock($carrier->getFormBlock());
$block->setMethodCode($code);
$block->setRate($_rate);
$block->setMethodInstance($carrier);
echo $block->_toHtml();
}
?>
<?php endif ?>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>
<div style="clear: both;"></div>
</td>
<tr>
<td><br></td>
<td></td>
</tr>
<tr>
<td style="text-align: right;"><label >Special<br> Instruction : </label></td>
<td><textarea class="textarea-delivery" rows="3" cols="50" name="shipping_deliveryrate[special_instructions]" id="shipping_deliveryrate[special_instructions]" cols="20" rows="4"></textarea></td>
</tr>
<tr>
<td></td>
<td><label style="font-size: 12px;font-weight:normal;font-style:italic;color:silver;">Enter any special instructions or notes about this order<br>
Example: "Call the recipient before the delivery. Try to deliver before 4.00pm"
</label></td>
</tr>
<tr>
<td><br></td>
<td></td>
</tr>
<tr>
<td></td>
<td style="text-align: right;">
<div style="width: 430px;padding-right: 83px;padding-bottom: 4px;">
<div style="float: left;width: 322px;height: 30px;"><a href="#" style="text-decoration: none;"><label style="font-size: 10px;font-weight:normal;color: #839821;">If you need to type our personal message<br>
in Sinhala or Tamil, please use relevant keyboard here</label></a>
</div>
<div style="width: 108px;height: 30px;float: left;padding-bottom: 4px;padding-top: 8px;">
<input type="button" name="sinhala_keyboard" id="sinhala_keyboard" class="button-checkout-language" value="Sinhala" onclick="opensinhalakeyboard();" />
<input type="button" name="tamil_keyboard" id="tamil_keyboard" class="button-checkout-language" value="Tamil" onclick="opentamilkeyboard();" />
</div>
</div>
</td>
</tr>
<tr>
<td><label style="float:right;">Personel <br>Message : </label></td>
<td><textarea class="textarea-delivery" rows="3" cols="50" name="shipping_deliveryrate[msg]" id="shipping_deliveryrate[msg]" cols="20" rows="4"></textarea></td>
</tr>
<tr>
<td></td>
<td><label style="font-size: 12px;font-weight:normal;font-style:italic;color:silver;">Your message will be hand written on a white card & sent with the gift item.</label></td>
</tr>
</tbody>
</table>
</li>
</ul>
</dd>
<?php
break;
}
}//not florist
else
{
// if florist selected
if($code == 'pickup') // If the shipping method is pickup
{
?>
<dt><?php echo $this->getCarrierName($code) ?></dt>
<dd>
<ul>
<?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
<?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
<li>
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<?php if ($_sole) : ?>
<span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" /></span>
<?php else: ?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
<script type="text/javascript">
//<![CDATA[
lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
//]]>
</script>
<?php endif; ?>
<?php endif; ?>
<label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $_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
$carrier = Mage::getModel('shipping/config')->getCarrierInstance($code);
if($carrier->getFormBlock()){
$block = $this->getLayout()->createBlock($carrier->getFormBlock());
$block->setMethodCode($code);
$block->setRate($_rate);
$block->setMethodInstance($carrier);
echo $block->_toHtml();
}
?>
<?php endif ?>
</li>
<?php endforeach; ?>
</ul>
</dd>
<?php
break;
}
} ?>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
//<![CDATA[
<?php if (!empty($shippingCodePrice)): ?>
var shippingCodePrice = {<?php echo implode(',',$shippingCodePrice); ?>};
<?php endif; ?>
$$('input[type="radio"][name="shipping_method"]').each(function(el){
Event.observe(el,'click', function(){
if (el.checked == true) {
var getShippingCode = el.getValue();
<?php if (!empty($shippingCodePrice)): ?>
var newPrice = shippingCodePrice[getShippingCode];
if (!lastPrice) {
lastPrice = newPrice;
quoteBaseGrandTotal += newPrice;
}
if (newPrice != lastPrice) {
quoteBaseGrandTotal += (newPrice-lastPrice);
lastPrice = newPrice;
}
<?php endif; ?>
checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
return false;
}
});
});
//]]>
jQuery(document).ready(function(){
hideShippingAll();
jQuery('input[type="radio"][name="shipping_method"]').click(function(){
hideShippingAll();
var code = jQuery(this).val();
if(jQuery(this).is(':checked')){
showShipping(code);
}
});
jQuery('input[type="radio"][name="shipping_method"]').each(function(){
var code = jQuery(this).val();
if(jQuery(this).is(":checked")){
showShipping(code);
}
});
});
function showShipping(code){
if(jQuery('#'+'shipping_form_'+code).length != 0){
jQuery('#'+'shipping_form_'+code).show();
jQuery(this).find('.required-entry').attr('disabled','false');
}
}
function hideShippingAll(){
jQuery('input[type="radio"][name="shipping_method"]').each(function(){
var code = jQuery(this).val();
jQuery('#'+'shipping_form_'+code).hide();
jQuery(this).find('.required-entry').attr('disabled','true');
});
}
function open_in_new_tab(url)
{
window.open(url, '_blank');
window.focus();
}
</script>
<?php endif; ?>
I found the solution.
Both of the shipping methods have same event observer names. That is why it always execute one observer. So changing the event observer names worked

select option in payment method instead of radion button in magento

This is my methods.phtml file in onepagecheckout in magento,I want the dropdown(select option) button instead of radio button .........so that i could select the payment method to pay the payment.
<?php if (!$methods = $this->getMethods()) : ?>
<p><?php echo $this->helper('checkout')->__('Sorry, no quotes are available for this order at this time.') ?></p>
<?php else : ?>
<dl class="sp-methods">
<?php foreach ($this->getMethods() as $_method): $_code = $_method->getCode() ?>
<dt>
<?php if( sizeof($this->getMethods()) > 1 ): ?>
<input value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->htmlEscape($_method->getTitle()) ?>" onclick="payment.switchMethod('<?php echo $_code ?>')"<?php if($this->getSelectedMethodCode()==$_code): ?> checked="checked"<?php endif; ?> class="radio" />
<?php else: ?>
<span class="no-display"><input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" checked="checked" class="radio" /> </span>
<?php endif; ?>
<label for="p_method_<?php echo $_code ?>"><?php echo $this->htmlEscape($_method->getTitle()) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
</dt>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd>
<?php echo $html; ?>
</dd>
<?php endif; ?>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
//<![CDATA[
<?php echo $this->getChildChildHtml('scripts'); ?>
payment.init();
//]]>
</script>
<?php endif; ?>
You can do the select option dropdown for payment method as setup below code in methods.phtml file.
Also you have to changes in opcheckout.js line no 715 to change "elements[i].checked" to "elements[i].value".
<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php if (empty($methods)): ?>
<dt>
<?php echo $this->__('No Payment Methods') ?>
</dt>
<?php else:
?>
<dt>Select Payment Method:</dt>
<select name="payment[method]" onchange="payment.switchMethod(this.value);">
<?php
foreach ($methods as $_method):
$_code = $_method->getCode();
?>
<option id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" <?php if($this->getSelectedMethodCode()==$_code): ?> selected="selected"<?php endif; ?>>
<?php echo $this->escapeHtml($this->getMethodTitle($_method)) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?>
</option>
<?php endforeach; ?>
</select>
<?php
foreach ($methods as $_method):
$_code = $_method->getCode();
?>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd id="dd_method_<?php echo $_code ?>">
<?php echo $html; ?>
</dd>
<?php endif;
endforeach;
endif;
?>
<?php echo $this->getChildChildHtml('additional'); ?>
<script type="text/javascript">
//<![CDATA[
<?php echo $this->getChildChildHtml('scripts'); ?>
payment.init();
<?php if (is_string($oneMethod)): ?>
payment.switchMethod('<?php echo $oneMethod ?>');
<?php endif; ?>
//]]>
</script>
I used this one to get my select list if helpful
<?php
$ptId1=mysql_query(" some query here")
echo"<select name=ptId>";
while($ptId=mysql_fetch_array($ptId1))
{
echo '<option value="'.$ptId['id'].'">'.$ptId['id'].'</option>';
}
echo '</select>';?>
}

Categories