Magento display a 3rd price on the product page - magento

I would like to add a third price to my products like "MSRP" on the latest version but not available on mine (Magento 1.4.1.1).
I would like to display it on the product page and it has to change according to the selected option.
So, I started by creating a new attribute called "msrp".
I managed to get it for every child product on my view.phtml file with the following code:
<?php
if($_product->isConfigurable())
{
$_associatedProducts = $_product->getTypeInstance()->getUsedProducts();
foreach($_associatedProducts as $assProducts)
{
$msrp = $assProducts->getData("msrp");
echo "MSRP: ".$msrp."<br />" ;
}
}
?>
Now the question is how to show it only one at a time and which corresponds to the selected option?
(Just like the normal price changes when we select an option.)
Maybe with a piece of javascript in this file?
/app/design/frontend/[...]/[...]/template/catalog/product/view/type/options/configurable.phtml
Thanks for your help !

Related

Magento - Add attribute if the product qty is zero

I want to insert this attrribute that I have created into the product page above the add to cart button but only if the qty is ZERO. Basically an estimated arrival date. Items that are available on back order only have a note above the add to cart button of when the product will actually be available from. I have put the below in and it works but I don't want it to show for products already available.
<p><font color="red">AVAILABLE FROM: <?php echo $_product->getResource()->getAttribute('due_date')->getFrontend()->getValue($_product); ?></font></p>
Can someone let me know what I need to add please.
Most appreciated
Anthony
You should be able to get the stock quantity on the product page by using:
Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()
You can then use that in a conditional to show the piece of code that you want. However, I'm not sure you need all of that to show the due date. Because you're already loading the product when you are on the product page, you should just be able to use:
<p class="red">AVAILABLE FROM: <?php echo $_product->getDueDate(); ?></p>
If that doesn't work, make sure that you have your due date attribute set to be visible on the product page. It'll be the one called, "Visible on Product View Page on Front-end".
Full code block could look something like this:
<?php
$qty = Mage::getModel(cataloginventory/stock_item)->loadByProduct($_product)->getQty();
if ($qty <= 0): ?>
<p class="red">AVAILABLE FROM: <?php echo $_product->getDueDate(); ?></p>
<?php endif; ?>
If you allow backorders, it's important you check for <= 0, rather than == 0. This is because if someone backorders it, your stock will go negative.
Also, it's more clean to remove the font tag and use CSS to style the text.

Magento: Display price twice on product pages

This is the code that generates the price on product pages:
<?php echo $this->getPriceHtml($_product) ?>
in *app/design/frontend/default/CUSTOM_TEMPLATE/template/catalog/product/view.phtml*
I have a simple product with a few custom options. When the customer selects one of the option, the price increases. All works fine until here.
My question is how can i display the price twice on the same page (need this for deign purposes)?
I tried to copy and paste the above code in two locations on the same page, but the problem is that the second price will not update when the product options are selected. Only one price updates, the second won't. Any ideas on how can i make it work?
There is most likely a JavaScript on the page that either calculates the new price, or fetches it with AJAX. So the price outputted with:
<?php echo $this->getPriceHtml($_product) ?>
Will get overwritten by the new one. Solving this requires that you find the Javascript and locate where it does this. You should also check what HTML element surrounds the getPriceHtml-call. I guess the template might have something like this:
<p class="totalProductPrice"><?php echo $this->getPriceHtml($_product) ?></p>
If you surround the output of your second price output with an element with identifiable classname or ID, you should be able to modify the Javascript to output the newly calculated price to that element as well as the original one.
EDIT:
After checking my own codebase, I think that the file you are looking for is located at /js/varien/Product.js. Inside the function reloadPrice: function(), check line 481 for this:
if($('product-price-'+this.config.productId)){
$('product-price-'+this.config.productId).innerHTML = price;
}
And modify the script to also update your second price element.
The solution for me was:
Copy the price_clone.phtml to price_clone2.phtml and change:
<?php echo $this->getPriceHtml($_product, false, '_clone2') ?>
Add the block in the catalog.xml
<block type="catalog/product_view" name="product.clone_prices2" as="prices2" template="catalog/product/view/price_clone2.phtml"/>
And in the product.js change the initPrices function
initPrices: function() {
this.containers[0] = 'product-price-' + this.productId;
this.containers[1] = 'bundle-price-' + this.productId;
this.containers[2] = 'price-including-tax-' + this.productId;
this.containers[3] = 'price-excluding-tax-' + this.productId;
this.containers[4] = 'old-price-' + this.productId;
this.containers[5] = 'product-price-' + this.productId+'_clone2';
},

How to show sort by most popular(most sold) products on product listing page in Magento?

I am using following tutorial to display the most sold product sort by option(Filtering) to display on product listing page in magento?
Tutorial
/app/code/local/Mage/Catalog/Model/Resource/Product/collection.php
<?php
public function sortByReview($dir){
$table = $this->getTable('review/review');
$entity_code_id = Mage::getModel('review/review')->getEntityIdByCode(Mage_Rating_Model_Rating::ENTITY_PRODUCT_CODE);
$cond = $this->getConnection()->quoteInto('t2.entity_pk_value = e.entity_id and ','').$this->getConnection()->quoteInto('t2.entity_id = ? ',$entity_code_id);
$this->getSelect()->joinLeft(array('t2'=>$table), $cond,array('review' => new Zend_Db_Expr('count(review_id)')))
->group('e.entity_id')->order("review $dir");
}
?>
But I want to sort products which are most sold from every category.
How can I do this?
Is there any free extension available for this?
I did the following thing as the client did not want automatically filter most sold product.
I created an attribute "popular" as drop down and give values from 1 to 5.Then marked "Used for Sorting in Product Listing" to Yes.
After this the attribute was visible under sorting options.

Add additional product price with mangento base product price

I want to add additional price with product(simple) price, I am trying to do this with the help of custom attributes. I add a custom attribute "Margin Price" and I want to add up this custom attribute value (margin price) with the base price of the product in the template file.
I am updating all product price after each 5 minutes by cron job, thats why I think I have to do add margin price with base product price by this way.
I added it successfully in product list page and in product view page, but have problem with how to add this margin price with base price in the cart and onepage checkout?
Here is the code on the product list page and same for the product detail page which works fine for me in magento 1.6.x.
$regularPrice = number_format($_product->getFinalPrice(), 2);
//echo $regularPrice = $this->getPriceHtml($_product, true
$priceWithoutComma = str_replace(",", "",$regularPrice);
settype($priceWithoutComma, "float");
$marPrice = $_product->getMarginPrice();
settype($marPrice, "integer");
$finalPrice = $priceWithoutComma + $marPrice;
echo $finalPrice.Mage::app()->getLocale()->currency(Mage::app()->getStore()->
getCurrentCurrencyCode())->getSymbol();
I am doing this right way or I have to changes the whole process?
Looks like you might need to consider a different approach. The reason being that echoing the price from a template file does not modify the price of the item in any way. It simply outputs a calculation.
You'll need to learn a bit about event listeners for this one to work.
Here's a blog post of mine on how to do this.

How can I add "Quantity" to a VirtueMart "Browse" page?

My VirtueMart shop.browse page has the typical columns of SKU, Name, Price, and "Update" (which contains the Add to Cart button). I would like to add a Quantity column between Price and Update so that a buyer can choose a quantity prior to pressing the "Add to Cart" button.
Though I don't know HOW to do this, I think I know WHERE to do it:
/public_html/components/com_virtuemart/themes/default/templates/browse/includes/browse_listtable.tpl.php
Lines 67-72 of that file tell the program how to build the table, but what I DON'T know how to do is modify the code source to tell it to include quantity as an element for the table. Here's the code:
// Loop through each row and build the table
foreach($data as $key => $value) {
$table->addRow( $data[$key], 'class="sectiontableentry'.$i.'"', 'td', true );
$i = $i == 1 ? 2 : 1;
}
Which include file is actually being called in this foreach loop, and what code would I add to reference quantity data?
You should not modify your core code. If you just need to put quantity box inside your browse template use variable $form_addtocart
It will give you quantity box and add to cart button.
All variables for browse page and for flypage template you can find here:
http://virtuemart.net/documentation/Developer_Manual/Modifying_the_Layout.html
If this is not what you are trying to get, please be more specific, or show your web page.

Resources