Magento Special price validation - magento

Sorry that I'm a total newbie in magento.
I have a multi-vendor magento site where vendors can create product. But when setting product price some users often do some mistakes. Some times special prices are higher than original price. I like to check this mistake. I want a validation script so that when vendors (who have limited admin access) create a new product then they should keep a minimum difference between special price and original price where special price is always lower than original price.
Can any body give some hints?
Thanks

Hope following code will help you
<?php
$product= Mage::getModel('catalog/product')->load(product_id);
$price = $product->getPrice();
$webprice = $product->getwebprice();
$specialprice = $product->getFinalPrice();
if($specialprice==$price)
{?>
<span>$<?php echo number_format($price,2);?></span>
<?php } else if($specialprice<$price) { ?>
<div>
<span>Regular Price:</span>
<span>$ <?php echo number_format($price,2); ?></span>
</div>
<div>
<span>Web Special:</span>
<span>$ <?php echo number_format($specialprice,2); ?> </span>
</div>
<?php } ?>

Even if the user set special prices more than original price,Magento takes cares of it by not displaying that special price .However if you want to do some customization ,the path for price display is :app/design/frontend/default/default/template/catalog/product/price.phtmlIt would be wise if you copy the structure, paste it on your custom theme and continue with your modification.can add your javascript in list.phtml (same product folder).Hope it gives some hint.

Related

phtml code for magento product page

I want to insert some text directly below the tier price html if there is tier price info for item. So I am looking for code for a if then. This is what I have so far but it is not working. I am getting TEST for every product and not just for the tier price products.
<?php if ($this->getTierPriceHtml()):?>
<h2><?php echo $this->__('TEST') ?></h2>
<?php endif; ?>
If you inspect the value returned by
$this->getTierPriceHtml()
when it is empty you will see that it is returning blank html with lots of spaces.Thats why when you cneck for
if ($this->getTierPriceHtml()):
always return true because there is blank spaces.
So first check like below
$tier = $this->getTierPriceHtml();
$string = preg_replace('/\s+/', '', $tier);//This will remove all spaces
if($string!=""){
echo $this->__('TEST');
}
Hope this will help.

How to display two currency in magento cart

I want to display two currencies in Magento's cart and invoice. I have make it in product page by this code
<div class="currency">
<?php if( Mage::app()->getStore()->getCurrentCurrencyCode() == 'USD'): ?>
<span class="price">(<?php echo round(Mage::helper('directory')->currencyConvert( $_product->getFinalPrice(), 'USD', 'AUD'), 2 ); ?>) AUD</span>
<?php else: ?>
<span class="price">(<?php echo round(Mage::helper('di`enter code here`rectory')->currencyConvert( $_product->getFinalPrice(), 'AUD', 'USD'), 2 ); ?>) USD</span>
<?php endif; ?>
</div>
and now I want to display this in the email invoice.
in the email template ti has this line
{{layout handle="sales_email_order_items" order=$order}}
looking up sales layouts we find app\design\frontend[package][theme]\layout\sales.xml
from there you can see the .phtml files used to render the items section of the email, edit the ones you need, keep in mind that these are also used on the front end.
if you want to separate the .phtml files so that the frontend and email template can use different files, copy/paste/rename sales_email_order_items in the .xml file and change the template= parts to the new templates, be sure that in your email template you change the handle stated above to what you renamed the layout to otherwise it'll use the original one.
your code should work fine, you may just need to change $_product->getFinalPrice() if it doesn't work and $_product may not be in the template or be a different class since your dealing with the the collection that deals with sales_flat_order rather than catalog_product

How to add products with price as "Contact for Pricing" in magento

I have a Magento site.
I have a number of products to add.
But some have price as "Contact for Pricing" or "Call for Pricing" so cant to add.
Because there has validation for the price.
So how can I add such products?
If there is any module for such products?
I need to display such product's price as "Contact for Pricing" or "Call for Pricing".
if there is an extension for "call for price" download free?
Josh's answer slightly improved. Thanks Josh for the Idea of using attributes!
Create the attribute code 'call_4_price' for this example. Like Josh suggested, make it a Yes/No attribute. Default Value "No". Add it to attribute sets where you'll need to hide prices.
Find all .phtml files where "prices & add to cart buttons" are (template > catalog > product > view.phtml, price.phtml, list.phtml, etc)
Paste this code Before the price code.
<!-- Call For Price - begin -->
<?php $attribute = $_product->getResource()->getAttribute('call_4_price'); ?>
<?php $attribute_value = $attribute ->getFrontend()->getValue($_product); ?>
<?php if ($attribute_value == 'Yes'): ?>
//Please Call for pricing
<?php else: ?>
And this after the add to cart button.
<?php endif; ?>
<!-- Call For Price - end -->
Create an Yes/No attribute for Call For Price. When creating products, put something into the price field just to get past validation.
Now modify your template files to not show the price if it Call For Price is set to 'Yes'.

How to call mycart product names in sidebar

I'm using magento 1.6.1.0. I included new sidebar in my cart page where it'll show product title, total amount & proceed to checkout button as one by one. I included total amount by calling <?php echo $this->getChildHtml('totals'); ?> and proceed to checkout button by calling <?php echo $this->getChildHtml('methods') ?>
But i don't know how to call Product name.
Anyone know how to call my cart products name which are currently added in basket? Please share your idea to do this!
Thanks
You can get access to your cart object via Mage::getSingleton('checkout/cart').
Calling Mage::getSingleton('checkout/cart')->getItems() will get you your current cart item collection that you can iterate through to get product names as well as other details.
$items = Mage::getSingleton('checkout/cart')->getItems();
foreach ($items as $item) {
echo $item->getName();
}

Magento - Unable to Refresh Product Stock Status on the Product Page

One of our Vendors has a real time inventory system and we would like to implement it into our site. When a person clicks on the product, it should check the inventory and update as necessary. This works ok at best. The problem is when the product switches to in/out of stock. It updates properly in the backend, but I am unable to get the addtocart button to be added/removed. This is my code for updating the stock:
//$_stockQTY is the realtime inventory result
$stockData = Mage::getModel('cataloginventory/stock_item');
$stockData->loadByProduct($_product->getId());
$stockData->setData('qty', $_stockQTY);
$stockData->setData('is_in_stock',($_stockQTY > 0) ? 1 : 0);
if ($stockData->dataHasChangedFor('qty')) {
$stockData->save();
$_product = Mage::getModel('catalog/product')->load($_product->getId());
}
As you can see, I am force reloading the product when qty is changed. This seems to work for everything but the addtocart button. It shows the previous result (In stock or out of stock before the reload.)
I have 2 questions:
Is there a better way to reload a product other than reassigning it as I am doing above:
$_product = Mage::getModel('catalog/product')->load($_product->getId());
And why is it that everything is updating properly, but the addtocart which uses the same
$_product->isSaleable()
call that our availability, etc uses.
Compare:
<?php if($_product->isSaleable()): ?>
<p class="availability in-stock"><img src="<?php echo $this->getSkinUrl('images/stock.png') ?>"> <span><?php echo $this->__('In stock') ?></span>
...
?>
To
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
<?php endif; ?>
<?php echo $this->getChildHtml('alert_urls') ?> //Only Shows up if addtocart does not.
Refreshing the page will update the product properly, but doing a meta refresh or anything of the sorts is out of the question. I appreciate any advice that could be given as I would like to get this resolved and on to the next task.
Unless I'm misunderstanding your question, it appears the thorn in your side is the stock status index.
Try this:
Mage::getSingleton('cataloginventory/stock_status')->updateStatus($_product->getId());
(I haven't tested this, but it looks like it ought to work)

Resources