Magento get weigth of configurable product - php

good afternoon,
How can I recover the value in phtml from the weight of the product? this product is configurable, so it has variations, it needed to recover the weight of the variation
i use this for Default products:
$_product->getWeight()

Lets assume that the product model is loaded.
You need to load the model of the configurable in order to access its child products (variations).
Here is an example
<?php $configurable= Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$simpleCollection = $configurable->getUsedProductCollection()->addAttributeToSelect('*'); // selecting all attributes?>
<?php foreach($simpleCollection as $simple): ?>
<?php echo $simple->getWeight(); ?>
<?php // or?>
<?php echo $simple->getAttributeText('weight'); ?>
<?php endforeach; ?>
Hope this helps

Related

magento get all products by attribute

I have displayed attribute filters in my catalog page. My client Requirement is, In some categories, attribute filter has no products that time i need to hide the empty attribute label. How can i achieve this Please help me.
"I need Product count for particular attribute that is shape,color and watts like that how can i get all products count by attribute, if i get count i will control the attribute label using that."
My code in catalog/layer/view.phtml:
<?php if($this->canShowBlock()): ?>
<?php // echo $this->getStateHtml() ?>
<?php if($this->canShowOptions()): ?>
<?php $_filters = $this->getFilters() ?>
<?php if($_filter->getItemsCount()):
<?php echo $this->__($_filter->getName()) ?>
<?php echo $_filter->getCount();?>
<?php echo $_filter->getHtml(); ?>
<?php endif;?>
<?php endif;?>
<?php endforeach; ?>
//Get product collection from "catalog/product" model
$collection = Mage::getModel('catalog/product')->getCollection();
//Fetch Most popular Featured products
$collection->addAttributeToSelect('most_popular');
$collection->addAttributeToSelect('featured_prod');
//You can check your query by:
$collection->getSelect();
Hope this may help you.... :)

Display number of products within filter in Magento sidebar

I'm currently building out a site using Magento 1.7 where the total number of products displayed in a category is displayed in the sidebar (template/category/layer/view.phtml in the theme directory). The code I have to display this value at the moment is as follows:
<div class="products-total">
<?php if (Mage::registry('current_category')) { ?>
<?php $_category_detail->getName();?>
<?php $_category_detail->getId(); ?>
<?php $products_count = Mage::getModel('catalog/category')->load($_category_detail->getId())
->getProductCount();
?>
<?php echo $products_count,' products' ?>
<?php } ?>
</div>
However, as it simply pulls the current category total products value, it doesn't account for filters. How would it be possible to show the filtered products total?

Magento: List product categories EXCEPT a select few

I am looking to list on the product page the categories that a particular product belongs to; HOWEVER, I would like to be able to say do NOT list some specific categories.
A solution to outputting the list of categories a product belonged to was posted by a fellow stackoverflow user here: https://stackoverflow.com/a/9720480/99112 and it works great to output the results. How could the above code be modified to get what we are looking for?
Just to draw up an example of what I mean:
Say a Product A is a member of Category IDs: 4, 7, 9, 14, 92
On the product page, I want to output the names of the above categories MINUS category IDs: 7, 92
So, the output would only be Category ID names for: 4, 9, 14
The categories we would want to exempt would apply to all products. So in the above example and looking at a Product B, it would also output Category ID names EXCEPT for the ones we don't want (i.e. 7, 92).
Here is the code in question from the above thread (thanks to user "Sarath Tomy"):
<?php $categories = $_product->getCategoryIds(); ?>
<?php foreach($categories as $k => $_category_id): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>
<?php echo $_category->getName() ?>
<?php endforeach; ?>
How would we modify this to check a list of Category IDs that we do NOT want outputted, please?
Many thanks.
Here's a solution that worked (no idea if it's the most efficient way of doing it or not), but here it is:
<?php $categories = $_product->getCategoryIds(); ?>
<?php foreach($categories as $k => $_category_id): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category_id) ?>
<?php if (!in_array($_category->getId(), array(XX,YY))) : ?>
<?php echo $_category->getName() ?>
<?php endif; ?>
<?php endforeach; ?>
where you put in whatever Category IDs you want to exclude in place of XX,YY above.
You could make a System - Configuration setting that contains a multiple select with all the categories.
The categories selected would be the ones excluded.
Now, the best practice would be to extend Mage_Catalog_Model_Product, and add another method getVisibleCategoryIds()
Here's how it would look (not tested):
public function getVisibleCategoryIds() {
return array_diff($this->getCategoryIds(), Mage::getStoreConfig('section_name/group/field'));
}
Or you can extend getCategoryIds() directly and save the hassle of modifying through templates. This would look like this:
public function getCategoryIds() {
return array_diff(parent::getCategoryIds(), Mage::getStoreConfig('section_name/group/field'));
}

Product details in magento

I have this code in my magento app
<?php
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id);
foreach ($order_details->getAllItems() as $item) {
//here i know we can get item name as $item->getName(), sku as $item->getSku()
//but how do we get the following details
//1.category name,2.store,3.tax,city,country,state
<?php } ?>
I know by simply print_r($order_details->getAllItems()) will get the array list.but im in no situation to do this
This items are not as same as products, they don't have all the properties. You can either do a Mage::getModel('catalog/product')->load($item->getProductId()); fast way to test something, but this adds an extra query to mysql for every item in the loop. Or I recommend to edit the sales xml -> Mage > Sales > etc > config.xml (in a local module). You should add to the nodes sales_convert_quote_item or sales_convert_order_item the attributes you want to be copied from product to item. In your case it would be the sales_convert_order_item node since you are dealing with an order.
You need to load the full product model to access that data.
The collection you are loading is not of products, it's a collection of Order Items, which has minimal data associated with it. You need to load the full product model, by getting the product if from the Order Item.
try this:
<?php
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order_details = Mage::getModel('sales/order')->loadByIncrementId($order_id);
?>
<?php foreach ($order_details->getAllItems() as $item): ?>
<?php $product = Mage::getModel('catalog/product')->load($item->getProductId()) ?>
<?php echo $product->getName() ?>
<?php // now you have the full product model/data loaded ?>
<?php endforeach ?>

Opencart targeting specific product_id

I'm trying to display the price of particular product (with the ID 51) on the home page. It is not a featured product, but something else entirely so I can't use the featured module.
I know the product ID is 51, so have tried to use the following:
<?php if (!$product[$product_id[51]]['special']) { ?>
<?php echo $product[$product_id[51]]['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product_id[51]['price']; ?></span> <span class="price-new"><?php echo $product_id[51]['special']; ?></span>
<?php } ?>
but this only returns "undefined variable product_id". How do I display the price of this particular product?
MTIA.
You can get the product in full using
$product = $this->model_catalog_product->getProduct(51);
Don't forget when using currency values you should format them appropriately using
$this->currency->format()
To get an idea of what code you need to be using, take a look inside the catalog/controller/product/product.php for the special and price coding

Categories