I have a drop down box that shows the weight of the item and how much extra the heavier items cost. I also have javascript that updates the price on the page based on the value selected in the dropdown. Since the javascript updates the price shown on the page, I would like to remove the additional price shown next to the option choices.
the code is:
<?php if ($options) { ?>
<?php foreach ($options as $option) { ?>
<?php if ($option['type'] == 'select') { ?>
<span id="option-<?php echo $option['product_option_id']; ?>" class="option">
<select name="option[<?php echo $option['product_option_id']; ?>]">
<?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>
</span>
I only want to show the product_option_id in the drop down, I don't want to show the added price for increases; I don't want this part of the code to be visable:
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><span id="newPrice"><?php echo $option_value['price']; ?></span>)
<?php } ?>
however, I have some javascript that updates price based off the $option_value['price']. So I can't just erase it.
Is there a way to keep the output from echoing onto the screen, but still have javascript be able to find it?
Yes:
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><span style="display:none" id="newPrice"><?php echo $option_value['price']; ?></span>)
<?php } ?>
Also you should consider not using an ID on that span, unless you are generating a unique id for each one, as it will cause you problems when you try to grab it with document.getElementById()
Related
I am running Magento v1.9.0.1. I want to disable Cash on Delivery for specific products. I have installed COD extension from magento commerce.
I am new to Magento structure and no nothing to little about it. Tried some debugging on it but it is going up above my head.
Also, I have search every where over the internet but no one has ever provided the code for Magento v1.9.0.1.
Create a custom attribute with attribute code as cod and assign it to General of attribute sets.
Now as per you requirement change your methods.phtml (if there is no custom code included in this) as follows.
<?php
$methods = $this->getMethods();
$oneMethod = count($methods) <= 1;
?>
<?php if (empty($methods)): ?>
<dt>
<?php echo $this->__('No Payment Methods') ?>
</dt>
<?php else:
foreach ($methods as $_method):
$_code = $_method->getCode();
?>
<dt>
<?php
//cod verification starts
$attr_cod = array();
$cartItems = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach ($cartItems as $item) {
$attr_cod[] = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getCod();
}
if(in_array('1', $attr_cod) && $_code == 'cashondelivery') {continue; }
//cod verification ends
?>
<?php if(!$oneMethod): ?>
<input id="p_method_<?php echo $_code ?>" value="<?php echo $_code ?>" type="radio" name="payment[method]" title="<?php echo $this->escapeHtml($_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 $oneMethod = $_code; ?>
<?php endif; ?>
<label for="p_method_<?php echo $_code ?>"><?php echo $this->escapeHtml($this->getMethodTitle($_method)) ?> <?php echo $this->getMethodLabelAfterHtml($_method) ?></label>
</dt>
<?php if ($html = $this->getPaymentMethodFormHtml($_method)): ?>
<dd>
<?php echo $html; ?>
</dd>
<?php endif; ?>
<?php 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 have tested this and works fine.
COD is already in magento you didn't need to install it.
There are two way
create a new config setting in which you can enter ids of products
for which you didn't want COD option.
You can create product attribute too for checking COD option.
and check these ids (if you create config settings ) with the
product id or check for the product attribute on
app\design\frontend\base\default\template\checkout\onepage\payment\methods.phtml.
And by simple if else conditions you can avoid COD option for these
products.
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
I am using onestepcheckout in Magento. I have added in some extra flat rates and I am using two of them. I want to be able to only show one of the flat rates depending on the subtotal of the cart.
I have got the subtotal into a variable but the code has a foreach through each shipping method available so I need a way to say if $total is over 500 only show the second shipping method, if the total is under 500 only show the first shipping method.
<?php $total = Mage::getSingleton('checkout/session')->getQuote()->getSubtotal(); ?>
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<dd><?php echo $this->getCarrierName($code) ?></dd>
<?php foreach ($_rates as $_rate): ?>
<dt style="margin-bottom: 5px;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<input name="shipping_method" type="radio" class="validate-one-required-by-name" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> />
<label for="s_method_<?php echo $_rate->getCode() ?>"><!--<b><?php echo $this->getCarrierName($code) ?>:</b>--> <?php echo $_rate->getMethodTitle() ?>
<strong>
<?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; ?>
</strong>
</label>
<?php endif ?>
</dt>
<?php endforeach; ?>
<?php endforeach; ?>
Just do ...
//first method here by default
if($total>500){
//second method here
}
Something tells me you already know how to do this though
I can't decipher, what the first and second method are in your code, otherwise I would've posted a more complete code
Hi i am in new in opencart. I have code in product.tpl. i want remove the "price" in the option box selection....
If i remove the "price" in option box, it affect in price calculation i.e., finalpricevalue in header.tpl
I want solution
hide the "price" in the option box (OR)
Change the colour of "price" in the option box (OR)
remove the "price" in product.tpl and assign value to "finalpricevalue" in header.tpl
product.tpl---->
<select name="option[<?php echo $option['product_option_id']; ?>]" width="300"style="width:200px">
<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>
header.tpl----->
var position1 = newPriceValue.indexOf("(");
var position2 = newPriceValue.indexOf(")");
position1 = position1+3;
var **finalPriceValue** = newPriceValue.substring(position1, position2);
var txt = newPriceValue;
txt = txt.replace(/,/g, '');
array=txt.match(/(?!$)\d+(\.\d+)/g);
Please help me......
In product.tpl there are several instances of $option_value['price'] correlating to different types of options you can have on a product. First make a copy of product.tpl for a backup then to make the price "disappear" search product.tpl for each instance of:
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
and enclose it with a html comment like this:
<!--
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)
<?php } ?>
-->
That shouldn't effect the header total which is what I assume you mean by:
If i remove the "price" in option box, it affect in price calculation
To change the color of the price; find the same code blocks and make it something like this:
<?php if ($option_value['price']) { ?>
<span class="price_color">(<?php echo $option_value['price_prefix']; ?><?php echo $option_value['price']; ?>)</span>
<?php } ?>
Then make a backup copy of /catalog/view/theme/your_theme/stylesheet/stylesheet.css and add:
.price_color {color: #000000}
or whatever color you want it to be. Just enclosing it in a span for styling. There may be better ways to do what you're trying to do. You might put the styling in a new css so its not overwritten when updating the template if it's not your own.
Using OpenCart as an ecommerce solution I'm trying to edit the cart page so that I can update option values in addition to quantity and have run into a bit of trouble.
My current code takes the correct option that's been chosen and puts it in a select box. Here's the code:
<?php foreach ($product['option'] as $option) { ?>
<div style="float: left; width: 100px;">
<select style=" text-align: left;" class="storeitems" name="option[<?php echo $option['option_id']; ?>]" selected="<?php echo $option['value']; ?>">
<option>
<?php echo $option['value']; ?>
</option>
</select>
</div>
<?php } ?>
Now, I need it to pull in the other options (as seen on the proudct page). Here is that code:
<select style="max-width: 145px;" class="storeitems" name="option[<?php echo $option['option_id']; ?>]" selected="<?php echo $option_value['name']; ?>">
<?php foreach ($option['option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['option_value_id']; ?>"><?php echo $option_value['name']; ?>
</option>
<?php } ?>
</select>
In your second piece of code you have no product identification so opencart doesn't know what product to display options for.