magento output custom options - magento

Is it possible to output the available list of custom options onto the view.phtml page within Magento? Obviously the drop down lists allow you to filter down but I need to list them in a html table and allow the customer to add to cart on each item.

I will show you how to convert dropdown and multi-select options into table format. This is the code that do the trick.
<?php
$product = Mage::Registry('current_product');
$options = $product->getOptions();
//check for option exists
if($options):
foreach ($options as $option) :
//table format allows only for select options
if($option->getType()== Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN ||
$option->getType() == Mage_Catalog_Model_Product_Option::OPTION_TYPE_MULTIPLE):
$require = ($option->getIsRequire()) ? ' required-entry' : '';
if($option->getType()== Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN):
$value_name = 'options['.$option->getid().']';
else:
$value_name = 'options['.$option->getid().'][]';
endif;
?>
<table border="1" style="width:500px;margin-bottom:30px">
<thead>
<tr<?php if ($option->getIsRequire()) echo ' class="required"' ?>>
<th><?php echo $option->getTitle() ?></th>
<th><?php if ($option->getIsRequire()) echo '<em>*</em>' ?></th>
</tr>
</thead>
<tbody id="<?php echo 'select_'.$option->getId() ?>" class="<?php echo $require.' product-custom-option' ?>">
<?php
foreach ($option->getValues() as $values) :
$value = $values->getOptionTypeId();
$value_title = $values->getTitle();
?>
<tr>
<td>
<?php
if($option->getType()== Mage_Catalog_Model_Product_Option::OPTION_TYPE_DROP_DOWN):
?>
<input type="radio" name="<?php echo $value_name; ?>" class="radio_option" id="<?php echo 'radio_option_'.$value ?>" value="<?php echo $value; ?>" />
<?php
else:
?>
<input type="checkbox" name="<?php echo $value_name; ?>" class="checkbox_option" id="<?php echo 'checkbox_option_'.$value ?>" value="<?php echo $value; ?>" />
<?php
endif;
?>
</td>
<td><?php echo $value_title; ?></td>
</tr>
<?php
endforeach;
?>
</tbody>
</table>
<?php
endif;
endforeach;
endif;
?>
Here for dropdown options, we are using radio button to show their values. For multiselect options, checkbox inputs are used. So if checkbox appears in the table, that means it a multi select option and hence more than one checkboxes can have tick at a time. Since radio buttons are used for dropdown options, it is important to make sure that, only one radio button is checked at a time. (We need to use javascript for ensure this).
So if we are set some custom options for a product through admin like this..
The output correspond to our code will be look like this
Note: Please note that, the code is in very basic format. You may require additional css and javascripts make it more user frontly. This is for giving you a basic idea and additional css, js are hence out of box topic.
For more information about code, check out my blog
Hope it helps

Related

Outputting the product atribute table within the product page (catalog/product/view.phtml)

I'm attempting to place the product attribute table within a div on my product page, seperately from the content of the usual collateral tabs.
I've located the code from my attributes.phtml and i've tried to just copy and paste this code into the appropriate part of my view.phtml, resulting in the following:
<div class="spec-table">
<?php if($_additional = $this->getAdditionalData()): ?>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
</div>
When this didn't work, I tried invoking the attributes.phtml from within my view.phtml using:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('catalog/product/view/attributes.phtml')->toHtml();?>
but sadly neither of these approaches seems to work, and I just end up with a blank div.
What's the best way to inject my attributes.phtml (or for that matter, the contents of any given .phtml file) into my product page at some arbitrary point?
Managed to get this to work using the following
<?php echo $this->getLayout()->createBlock('catalog/product_view_attributes')->setTemplate('catalog/product/view/attributes.phtml')->toHtml();?>

Fetch the entered quantity box values from multiple quantity box to cart page in magento

I am new to Magento.
I am displaying the attributes in table format using foreach in product detail page.
Problem i am facing is when i enter the value in any quantity box, it takes the last quantity value to the cart page since i am using foreach loop to display the quantity box.I need to display the exact value which i have entered in the quantity box.
Code:
<table border="1" style="width:100%;">
<thead>
<tr>
<th>Fabric</th>
<th>Color</th>
<th>Required Qty</th>
<th>Total Cost</th>
<th>Cart</th>
</tr>
</thead>
<?php
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'fabric');
$buttonTitle = $this->__('Add to Cart');
$i=0;foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
$i++;
if($i==1) continue;
?>
<tbody>
<tr>
<td>
<?php echo $attributeArray[$option['value']] = $option['label'];
?>
</td>
<td>
<select name="color" id="color">
<option>Select Color</option>
<?php
$color = Mage::getModel('eav/config')->getAttribute('catalog_product', 'fabric_color');
$j=0;foreach ( $color->getSource()->getAllOptions(true, true) as $option_color){
$j++;
if($j==1) continue;?>
<option value="<?php echo $option_color['value'];?>" price="<?php echo $option_color['price'];?>"><?php echo $option_color['label'];?></option>
<? }
?>
</select>
</td>
<td>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<div class="qty_pan">
<input type="text" name="qty" id="qty<?=$i;?>" maxlength="12" value="1" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>
<?php endif; ?>
</div>
<?php endif; ?>
</td>
<td ><span class="qty<?=$i;?>" id=""><?php echo $_product->getPrice();?></span></td>
<td>
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<!-- <span id='ajax_loader' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>-->
<?php //echo $this->getChildHtml('', true, true) ?>
</td>
</tr>
</tbody>
<?php }?>
</table>
Screenshot:
https://imageshack.us/scaled/large/12/detailpage.png
Any help is appreciated!.
I Got The solution.
We can use Query String to fetch the quantity values to cart.
Yourdomain.com/checkout/cart/add?product=getId();?>&qty=1
You can use the above querystring in href.
Hope this Helps.

remove news item from the joomla newsflash

I am using the joomla newsflash in order to display the 5 most recent items in my home page. the newsflash is attached to my news & events category. now I need that one of the news & events items will not be displayed in my home newsFlash. is it possible?, thanks
For Joomla 1.5.26, a template override might be your best bet. See here for how that's done: http://forum.joomla.org/viewtopic.php?t=145996
In your case, you'd create a new file at
/templates/your_template/html/mod_newsflash/_item.php
You'd put the following code in that file. Be sure to replace "99" with the id of your article. You can get that from the Article Manager table.
<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<?php
$my_article_id = $item->id;
if ($my_article_id !== '99') :
if ($params->get('item_title')) : ?>
<table class="contentpaneopen<?php echo $params->get( 'moduleclass_sfx' ); ?>">
<tr>
<td class="contentheading<?php echo $params->get( 'moduleclass_sfx' ); ?>" width="100%">
<?php if ($params->get('link_titles') && $item->linkOn != '') : ?>
<a href="<?php echo $item->linkOn;?>" class="contentpagetitle<?php echo $params->get( 'moduleclass_sfx' ); ?>">
<?php echo $item->title;?></a>
<?php else : ?>
<?php echo $item->title; ?>
<?php endif; ?>
</td>
</tr>
</table>
<?php endif; ?>
<?php if (!$params->get('intro_only')) :
echo $item->afterDisplayTitle;
endif; ?>
<?php echo $item->beforeDisplayContent; ?>
<table class="contentpaneopen<?php echo $params->get( 'moduleclass_sfx' ); ?>">
<tr>
<td valign="top" ><?php echo $item->text; ?></td>
</tr>
<tr>
<td valign="top" >
<?php if (isset($item->linkOn) && $item->readmore && $params->get('readmore')) :
echo '<a class="readmore" href="'.$item->linkOn.'">'.$item->linkText.'</a>';
endif; ?>
</td>
</tr>
</table>
<?php endif; ?>
The relevant code is in the second and final PHP tags, where I've inserted an IF check which looks for your article ID and skips it if it matches.

Magento view is not showing proper prices

This file (frontend/base/default/template/catalog/product/list.phtml) was edited, now is not showing the proper prices,
http://www.personalproducts4u.co.uk/hotel-toiletries/au-lait
I changed the third table tag (ONLY THE THIRD TABLE TAG)on the file above AND THE PRICES ARE SHOWING ALL THE SAME (ON DISCOUNTED PRICES)
any ideas?
this is the code I changed:(pasted it on the third table tag of the lists file)
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<th class="buy_heading">Buy</th>
<td class="buy_pay_content">1</td>
<?php
/*foreach($tierPrices as $key=>$value)
{
echo "<td class='buy_pay_content'>".number_format($tierPrices[$key]['price_qty'],0)."</td>";
} */
?>
<?php
if(count($tierPrices)):
foreach($tierPrices as $key=>$value)
{
echo "<td class='buy_pay_content'>";
echo number_format($tierPrices[$key]['price_qty'],0);
if($key == $count-1)
{
echo "+";
}
echo "</td>";
}
else:
echo '<td class="buy_pay_content">5</td>
<td class="buy_pay_content">10+</td>';
endif;
?>
<td class="buy_pay_content">Quantity</td>
</tr>
<tr>
<th class="pay_heading">Pay</th>
<td class="buy_pay_content"><?php echo $this->getPriceHtml($_product) ?><?php //echo Mage::helper('core')->currency($_product->getPrice()) ; ?>
<?php //echo Mage::helper('core')->currency($_product->getPrice()) ; ?> <?php //echo $this->getPriceHtml($_product, true)
?>
</td>
<?php
$specialprices = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
if($specialprices)
{
$specialprice =$specialprices;
}
else
{
$specialprice = 0;
}
if(count($tierPrices)):
foreach($tierPrices as $key=>$value)
{
if($specialprice < $tierPrices[$key]['price'] && $specialprice != '0'):
//echo 'special less'.$specialprice;
?>
<td class='buy_pay_content'><div class="price-box">
<p class="old-price"><span id="old-price-182" class="price"> <?php echo Mage::helper('core')->currency($tierPrices[$key]['price']) ?> </span> </p>
<p class="special-price"> <span id="product-price-182" class="price"><?php echo Mage::helper('core')->currency($specialprice) ?></span></p>
</div></td>
<?php
else:
?>
<td class='buy_pay_content'><?php echo Mage::helper('core')->currency($tierPrices[$key]['price']) ?></td>
<?php
endif;
?>
<?php }
else:
echo "<td class='buy_pay_content'>".$this->getPriceHtml($_product, true)."</td>";
echo "<td class='buy_pay_content'>".$this->getPriceHtml($_product, true)."</td>";
endif;
?>
<td class="buy_pay_content"><input type="text" class="input-text qty" title="Qty" value="" maxlength="12" id="qty" name="qty"></td>
</tr>
</table>
Well the issue seems to be the fact that getSpecialPrice() returns what ever is in the Special Price field. I could be mistaken but I don't believe you can supply special tiered prices in Magento. You can still add a static special price but as you have already experienced it will display the same price for each iteration.
You will probably need some sort of custom extension or template logic to display such sales properly.
I am not sure how you currently manage your tiered pricing, but if it is a fixed percentage for each tier you could set your tiered prices to the calculated sale prices and calculate and display the original tier prices by dividing each tiered discount percentage and display that number.

JToolbar frontend submit value on click

I'm building a joomla component and I can't find a solution to the following. In my front end I'm using the joomlas build in class JToolbar to handle events on click like edit, delete so one.
<form action="<?php echo JRoute::_('index.php');?>" method="post"
name="termForm" id="adminForm">
<table class="stripeMe">
<tbody>
<thead>
<tr>
<th>Begriff</th>
<th>Definition</th>
<?php if ($user->authorize('com_glossary', 'edit', 'glossary', 'all')): ?><th>Published</th> <?php endif; ?>
</tr>
</thead>
<?php foreach($this->items as $i => $item): ?>
<tr>
<td>
<span class="title"><?php echo $item->tterm; ?></span>
<?php if ($user->authorize('com_glossary', 'edit', 'bearbeiten', 'all')):?>
<?php echo $this->getEdit(); ?><?php endif; ?>
</td>
<td><?php echo $item->tdefinition; ?></td>
<?php if ($user->authorize('com_glossary', 'edit', 'bearbeiten', 'all')): ?>
<td><?php echo $this->getPublished(); ?></td> <?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div>
<input type="hidden" name="task" value="" /> <input type="hidden"
name="id" value="" onclick="submitbutton(<?php echo count( $item->id ); ?>);" /> <input type="hidden"
name="option" value="com_glossary" /> <input type="hidden"
name="controller" value="bearbeiten" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
I would like to pass to id of the selected row to the sub-controller on button event and I don't really know how to do it
Here you have some useful tips about using JToolbar on the frontend http://docs.joomla.org/How_to_use_the_JToolBar_class_in_the_frontend
I have done it once in the past, and from what I remember I did some tricks in order to make it work.
1.) Firstly remove the "id" input and add the following one at the end of your form:
<input type="hidden" name="boxchecked" value="0" />
2.) Secondly make sure Mootools is attached to the source
3.) Finally: There, where you started your foreach loop, after "tr" tag add another table column:
<td><?php echo JHTML::_('grid.id', $i, $item->id ); ?></td>
Don't forget to create a column heading in thead for this column.
These steps will create a checkbox in the first cell of every row and make the form able to send selected field's id with request.
edit:
tbody tag is in wrong place, it's supposed to be after thead tag. Also there is no use of attaching events to hidden input as they won't be triggered
Cheers
Peter

Resources