Magento: get final product price given arbitrary customer group - magento

Let's say a customer is in group A and for the group A a final price of a product is 10$. Now, in a module I need to find out what price he would get if he was in another group B. Is it possible?

I have used the following solution after some digging in Mage. Please let me know if this solution is problematic (so far it is working well though). Given a quote item:
$product = $quoteItem->getProduct();
$qty = $quoteItem->getQty();
$product->setCustomerGroupId($targetGroup->getId());
$price = $product->getPriceModel()->getFinalPrice($qty, $product);

Related

Magento: Bundled price is 0.00

Magento v1.7.0.2
We've been using this version several years now.
We have several free and paid extensions and last month we created our first bundled product.
When in list view the price is shown as 'Start at 0,00' for some products.
Other bundles products are fine and show the correct minimum price.
I've been searching for a while now, but can't find a workable solution.
Here's a sample page: http://www.scrapwebshop.nl/kado-tip.html
I finally got it working. It is probably not the right nor most efficient way, but the result is what I need. And that is what counts ;)
I now I have a grouped product, so I loop through all associated products, put their prices in an array. Next I sort to get the lowest value on top and get the first array entry.
I hope it helps somebody else:
$associatedProducts = $_product->getTypeInstance(true)->getAssociatedProducts($_product);
foreach ($associatedProducts as $assoc) {
$prices[] = $assoc->price;
}
sort($prices, SORT_NUMERIC);
$_minimalPrice = array_shift($prices);
$_exclTax = $_taxHelper->getPrice($_product, $_minimalPrice);
$_inclTax = $_taxHelper->getPrice($_product, $_minimalPrice, true)

How can i get the parent_item_id on a simple product that's associated to a grouped product

How can i get parent_item_id on a simple product ?
This give as result: Array
$simple_product_id = $_product->getId();
$grouped_product_ids = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($simple_product_id);
echo $grouped_product_ids
Japs.
According to magento Methodology ,a simple can be added associated with multiple Groups products.Magento give result of this code in array format.
If your Simple Product is associated with one group product.then getting group product id try below code
echo $grouped_product_ids[0]

To add discount to the product which is 15 days old from created date

I want to add discount to the product when that product exceeds more than 15 days from created date.
Generally i know how to add discount to the product, but i felt this is difficult to set the discount with that condition. It make me as so confused. I have found where to add that attribute in combo box.
\app\code\core\Mage\SalesRule\Model\Rule\Condition\address.php
I got created date of product by $product->getCreatedAt()
But i totally confused "how to do that action?". If anybody know, Please help me guys!
Here i am givin you some brief idea to make customization in catalog rule to check if your product is old from created with 15 days and more.
Try to build your own module to manage this kind of catalog rule in your applicaion
you can take understand from this tutorial to manage catalog rule
specially just go throw last 4 slides to make your own rule to achieve your goal.
I have simply used shopping cart price rules by the following way.
first i had created product attribute named as days. Then I have set the value to that days textbox as programmatically as follows
require_once("app/Mage.php");
Mage::app();
$productCollection = Mage::getModel('catalog/product')->getCollection();
$date2=Date("Y-m-d");
foreach($productCollection as $_product)
{
$product = Mage::getModel('catalog/product')->load($_product->getEntityId());
$date1=$product->getCreatedAt();
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
$product->setDays($days);
$product->save();
}
After that i have added that product attribute promo rules. Then i set the condition as if differerence between dates which are from product creation date to now is more than 15 days, to add discount to that particular product.

Magento - Get total number of items of a category in view.phtml

How can I get the total number of Items, I want to show it in the category view.phtml file. Usually this value is in the Toolbar.phtml.
I have tried something like this, but I think I am pretty far away:
$this->helper('catalog/output')->$_productCollection->count()
Magento version 1.7.0.2
The expected result should be something like this:
Items in this category: 17
The 17 should be the total number. If possible should include subcategory items.
Assuming that you want to display it in view.phtml you already have the current category object there so you can use $_category->getId()
$products_count = Mage::getModel('catalog/category')->load($_category->getId())
->getProductCount();
echo($products_count);
If you want to use it in list.phtml you can use
echo($_productCollection->count());
Try this,
<?php $_helper = $this->helper('catalog/output');?>
<?php $_category_detail = Mage::registry('current_category');?>
<?php $_category_detail->getName();?>
<?php $_category_detail->getId(); ?>
<?php $products_count = Mage::getModel('catalog/category')->load($_category_detail->getId())
->getProductCount();
echo($products_count);
?>
Basically, you can't show the total amount of filtered items in your view.phtml.
the reason is, that the logic, which gets the total amount, is not present in the $this context of the view.phtml.
But the logic is available in the Mage_Catalog_Block_Product_List_Toolbar block which is a child block of Mage_Catalog_Block_Product_List, though.
that basically means that you can actually get the total amount of filtered items by instantiating a toolbar and list block.
After doing that, the collection of the toolbar block has to be set with the value of the collection of the list block.
the following code is used in the view.phtml file to get the filtered total amount of items from the toolbar block:
$toolbar = new Mage_Catalog_Block_Product_List_Toolbar();
$list = new Mage_Catalog_Block_Product_List();
$toolbar-> setCollection($list -> getLoadedProductCollection());
$products_count = $toolbar -> getTotalNum();
There can be two ways we can find product count of a category.
$collection = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('level')
->addAttributeToSelect('entity_id');
foreach($collection as $cat)
$cat->getProductCount();
This will give you the product count for deepest category only. So for example, you have following categories. considering tree like structure.
Clothes(6)
->Cotton(3)
->Women(2)
The result returned from the piece of code given above.
Clothes(3)
Cotton(1)
Women(2)
There are three products directly associated with Clothes only, 1 with Cotton only and 2 with Women only. So it simply ignores the subcategories.
Another way is getting product count from products perspective.
$current_category = Mage::getModel('catalog/category')->load($cat->getEntityId());
$productCount = Mage::getModel('catalog/product')->getCollection()
->addFieldToFilter('manufacturer',$this->manufacturer["id"])
->addFieldToFilter('visibility',4)
->addFieldToFilter('status',1)
->addCategoryFilter($current_category)->getSize();
This gives us the added benefit of filtering product attributes. However in the above scenario, the count returned will be slightly different.
It will return Clothes (6), as it has 3 products associated to itself and 3 more products to its sub categories. Similarly
Cotton(3)
Women(2).
So for efficient results it would be nice to use mix of both.
It's not right to load additional model inside view because you already have model instance from which you can retrieve Product collection.
$this->getCurrentCategory()->getProductCollection()->count();
it is very simple and it worked well for me its just one line of code
<?php echo Mage::registry('current_category')->getProductCount();?>
It will display the count of the products of current category

Magento: Fixed shipping cost BELOW certain basket price

How can I set the shipping cost for Magento for all baskets that are below a certain point. For example, all baskets under £5 have fixed shipping of £1.99.
I think this is what you are looking for, unless I have the wrong thing. It seems to be called Table Rate Shipping.
the only way i've managed to get it working is to add an extra case statement in my shipping module.
$result = Mage::getModel('shipping/rate_result');
...
} else if ($request->getPackageValue() < 6) {
$price = '1.99';
...

Resources