Magento Retrieve simple product price for configurable product - magento

We have a configurable product called with sku TEST and under it are simple products (for example) red-ven1, red-ven2, blue-ven3, etc. The configurable product itself does not have a price but each simple product does. I need to retrieve the price for the simple product based on the attributes that are selected. So I need the price for red product with vendor 2. How do I get this specific price? I am currently trying to dynamically display the price next to the vendor attribute (so vendor attribute is not selected). Will I have to "invisibly" select the vendor attribute value to get the price? Please advise.
Currently Trying:
<?php $_product = $this->getProduct(); ?>
<?php $_price = $_taxHelper->getPrice($_product, $_product->getPrice()) ?>
<script>
var price = <?=$_price ?>;
/...lots of non-applicable code
for(var i=0; i < IDs.length; i++)//traversing the vendor detail nodes
{
//Invisibly make selection of vendor so as to gather correct price
var optionToSelect = $j('option', '#attribute136').filter(function() {
return $j(this).text().indexOf(data[i].vendor_id) != -1;
}).val();
var vals = $j('#attribute136').val() || [];
vals.push(optionToSelect);
$j('#attribute136').val(vals);
$j('.details'+data[i].vendor_id).append('<li class="priceBlock">$'+price+'</li>');
}
});
</script>

After some research I figured out this is pretty hard to solve on your own. If you're willing to spend a few bucks this is a great extension:
http://www.magentocommerce.com/magento-connect/simple-product-pricing.html

Related

Creating slider or carousel for bundle product in magento?

I want to create a bundle products for my estore but the bundle product has more than 50 products
So i want to add carousel or slider to these product. I tried adding some sliders but it is not working??
Please suggest me with some ideas.
Got this code from inchoo, so should work
$bundled_product = Mage::getModel('catalog/product')->load(YOUR_BUNDLED_PRODUCT_ID);
$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
$bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product
);
$bundled_items = array();
foreach($selectionCollection as $option)
{
$bundled_items[] = $option->product_id;
}
print_r($bundled_items);
$bundled_items has all the product ids, so you can simple load the product, and get all the detailed info. So Simply provide the data as per the need of the carousel.
To load the product
Mage::getModel('catalog/product')->load(PUT_ID_HERE);

magento show all discount coupons in shopping cart

<?php $rulesCollection = Mage::getModel('salesrule/rule')->getCollection();
$i=1;
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$totalPrice = 0;
foreach($items as $item) {
$totalPrice+=$item->getPrice();
}
$coll = Mage::getResourceModel('salesrule/rule_collection')->load();
echo '<div class=vip_test>';
foreach($coll as $rule){
$productDetail = $rule->afterLoad();
$discountAmount = $productDetail['discount_amount'];
echo "<div class=ssk><span> You Save : </span>".$totalAmount = $totalPrice-($discountAmount/100*$totalPrice)."</div>";
$ruleID = $productDetail['rule_id'];
}
foreach($rulesCollection as $rule){
$coupon = $rule->getCode();
$couponName = $rule->getName()
?>
In Magento, with this I am getting only the coupon code and coupon name. I want to display if there is any coupon code for particular product in shopping cart, in front of coupon - its showing the saving amount. Is it possible or not? Am I doing Wrong? please help me
First you need to get the collection of products which are in your cart. Then you need to check if there are any active coupons in catalog price rules or shopping cart price rules for the products which are in your cart. If all the above conditions becomes true then you need to display the coupon code of it.
On the next side, you need to calculate the difference amount of it and also you need to display if the user increases his quantity then the savings amount value also has to be increased.

Show qty for tier_price in product list

I need to show qty field for tier_price near regular price in product list (highest qty for lowest tier_price). Now $_product->getTierPrice() in product list gives me array(1) with 'tier_price'=>xxx and 'qty'=>1 (where xxx is lowest of my tier prices). Is it possible to get qty for tier_price in product list?
PS. In product view I can see array of tier prices with $_product->getTierPrice().
Magento CE 1.7.0.2
You can put this code in list.phtml or in view.phtml to show tier prices for each quantity.
$attribute = $_product->getResource()->getAttribute('tier_price');
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$symbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
if ($attribute) {
$attribute->getBackend()->afterLoad($_product);
$tierPrices = $_product->getTierPrice();
foreach($tierPrices as $tierPrice)
{
?>
<span class="priceqty"><?php echo '+'.round($tierPrice["price_qty"], 0);?></span><br>
<span class="pricetitle"><?php echo $symbol.number_format($tierPrice["price"], 2, '.', '');?></span>
<?php
}
}
?>
If you are looking for a Magento way:
$attribute = $_product->getResource()->getAttribute('tier_price');
if ($attribute) {
$attribute->getBackend()->afterLoad($_product);
$tierPrices = $_product->getTierPrice();
}
From /app/code/core/Mage/Catalog/Model/Product/Type/Price.php getTierPrice()
I have tested on Magento 1.4.0.2 (it should work also on other version ) on category pages and it works
In case you want to do it with SQL look here:
Magento: Display tier prices at category listing page

How to get preconfigure price from product view page to listing page in magento

Recently i came across the issue is When i display price of bundle product on listing page which shows either lowest price or highest price total by making total of all product within a bundle.
As i have set few product to default selected within a group so, on the product view page that default poduct price from perticualar group has been calculated in final total. but on price of product listing page count the minimum amount from the group of product.
So, what happens that customer view the product detail from product listing where it shows the lowest price but, on product view page it shows different price because now it counts default product price instead of minimum price from the group.
I want to display pre-configured product price from view page to product listing page.
Thanks in advance!
// load product
$product = new Mage_Catalog_Model_Product();
$product->load(165);
$priceModel = $product->getPriceModel();
// get options
$block = Mage::getSingleton('core/layout')->createBlock('bundle/catalog_product_view_type_bundle');
$options = $block->setProduct($product)->getOptions();
$price = 0;
foreach ($options as $option) {
$selection = $option->getDefaultSelection();
if ($selection === null) {
continue;
}
$price += $priceModel->getSelectionPreFinalPrice($product, $selection, $selection->getSelectionQty());
}

Magento:Getting selected attribute value of product in Checkout Shipping module

In my website, some products are not for sale in California. While the user checkouts, I have to do a validation like if the cart has items not for sale in California and user's shipping address is in CAlifornia, prevent user from checking out.
The sale in CA is set from admin side using an 'avl' attribute.
here is the code I use to iterate through the cart and check for the attribute
.....................
$cart = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
foreach ($cart as $_item){
$_product = $_item->getProduct();
//If atleast one product has availability status set to California, then set the flag and break.
if($_product->getResource()->getAttribute('avl')->getFrontend()->getValue($_product) == 'NC'){
$flag = true;
break;
}
......................
Well, now the problem is I'm not able to get the 'avl' value as set from the Admin side.
This code is in local//Checkout/Block/Onepage/Shipping.php
Any idea about how to retrieve the attribute value?
Thanks in advance.
To get a product's attributes during checkout, the easiest way is to just completely load the product:
$_product = Mage::getModel('catalog/product')->load($_item->getProduct());
$_avl = $_product->getAvl();
There are of course overheads with loading a product but this is the fastest way to get an attribute value from a cart item.
<?php $_item = $this->getItem()?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId())?>
<?php echo $_product->getResource()->getAttribute('attribute_code')
->getFrontend()->getValue($_product); ?>
app/design/frontend/your_default/your_default/template/checkout/cart/item/defaul‌​t.phtml

Resources