How to change the product display order in magento - magento

How can I change the product display order in the front end (grid or list) by setting some preferences from back-end? I guess it should be other than best value and name from the default Magento display order property.
I tried by creating a new attribute called display_order, and each product holds a value based on its value the product needs to shown in front end. However, it is not working. Please help me fix this.

You'll need to extend the Mage_Catalog_Block_Product_List block to provide your own functionality for the getProductCollection() method. Probably something along the lines of:
class ... extends Mage_Catalog_Block_Product_List {
function getProductCollection() {
parent::getProductCollection()->addAttributeToSort('display_order', 'ASC')
}
}
Then, of course, you'll have to update you layout xml file on your, presumably, custom controller (unless you want all of the product listing screens to act like this) to use your new block instead of the Magento default of catalog/product_list.

Why don't you use the Magento sorting thing ?
In your category, under Category Product you have the possibility to choose the sorting order in the last column. To do it through php, just make a custom script that you'll need to launch once.
$collection = 'Your product collection';
$result = array();
foreach ($collection as $product) {
$sort = 'Your way of calculating the desired sorting';
$result[$product->getId()]=$sort;
}
Mage::getModel('catalog/category')->load('your category id')->setPostedProducts($result)->save();
And that's it :)

To change the display order , first you need to set the default sort by option to position.This can be done from the magento admin configuration.After that you need to set position for all the products starting with the value 1.
I come across the following module which will make this task very easy, just by drag and drop the products from the manage categories itself.Please check the following extension
http://www.blackqubers.com/extensions/product-sorting-drag-and-drop.html
Hope this will helps you

Related

Magento - category products by attribute

When I create categories in Magento, I currently add all the products manually.
Problem is that we are getting more and more products and that some of our products change quite often.
So is it possible to dynamically change the category products depending on the product attributes?
i.e. to create categories that each contain all the products with a specific attribute value.
For example the category "blue", dynamically containing all the products where the attribute "color" is set to "blue".
Thanks.
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('color', 'blue');
$_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'blue');
foreach ($collection as $_item){
$_item->setCategoryIds(array($_category->getId()));
$_item->save();
}
Its just a stupid dummy you may need another foreach loop for all colors....but it shows what needs to be done...
Why are you doing data entry Manually?.
Magento has an inbuilt stable product import export system.Did you try this?
If this import export system does not solve your purpose then you will have to write a script and run it via cron once every day.
See www.proxiblue.com.au, there is a module that does exactly this.
Products can Be Assigned to categories, using any attribute combination.
Disclaimer: this is my site and module.

Magento - Some products not for sale

I would like to set some products to "non-saleable", removing the "Add to cart" button and adding a link to contact form.
I'm looking for this solution for a few weeks. Searching, I found this post:
Magento - product that are not for sale
At the end of page have this answer:
""Alternatively, you could set up a new product attribute that replaces the add to cart button with something different (more info button, popup, etc)."
How can I do it?
Another post about this subject:
http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/non-salable-products-with-attribute-sets.php
But I can't make it work. Someone could help me with more details?
small tutorial
Create a new attribute "saleable"
Default Value = yes
Unique value = no
values required = yes
apply to = all product types
use in quick search = no
use in advanced searched = no
comparable on front-end = no
Use In Layered Navigation = no
Use for Promo Rule Conditions = no
Visible on Product View Page on Front-end = no
Used in Product Listing = no
Used for Sorting in Product Listing = no
Manage titles
admin = "Is saleable"
Default store view = "Is saleable"
Now add it to your attribute set (default)
create a product or edit a product and define the is "is saleable" attribute.
Now go to the view of your product
/tomcollins.be/app/design/frontend/default//template/catalog/product/view.phtml
put an if statement like this
<? if($_product->getData('saleable')): ?>
// do what ever you want
<?php else: ?>
// do what ever you want
<?php endif; ?>
Hope this helps someone :)
bye
Modify your product with an Attribute for example nonsaleable. If that Attribute has value true the product is not saleable.
So now you should take a look at the
Productview in app/design/frontend/your_theme/your_theme/template/catalog/product/view.phtml
and the
listview app/design/frontend/your_theme/your_theme/template/catalog/product/list.phtml
Now look where in these files are the addtocart buttons are located.
Before this button you place an if nonsable === TRUE { make something } else { addtocart }
Thats the way i would try this.
Sorry for my bad english. I'm still tired :))))
For all non-for sale products you can set a quantity to 0. It will automatically remove Add to cart. Then you can add link to contact form on all products where add-to-cart doesn't exist. I am coming from Magento Go background so I would do it this way, but I know that with community and enterprise versions you have more flexibility.
I guess you will get your desire requirement through this extension because the developer teams for this extension is really very supportive.Please refer below link for extension:
Click here to get extension

is it possible to show custom attributes of associated products under a grouped product in front end? (Magento)

I have a typical condition in my magento Grouped product.
Is it possible to show Custom attribute (color dropdown) of associated product under Grouped products in the fronted.. as shown below
Consider the sample blanket product
Let me know if i am not clear.
Thanks
It's not clear your question but I would give you a small example to get text field, multiple select or drop-down listbox value.
First, we should load the product collection :
<?php
// load the product that id 125, then show attributes of the product
$product = Mage::getModel('catalog/product')->load($this->getProduct()->getId(125));
echo $product->getCustomAttribute();
// lets say your custom attributes name is "size" and type is text field
echo $product->getSize();
// lets assume your custom attributes name is "product_size then
echo $product->getProductSize();
// lets assume your attribute type is drop-down, this will get array of attribute options instead of value that you selected
echo $product->getAttributeText(product_size);
// to get drop-down value that you selected
$attribute = $product->getAttributes();
$productSize = $attribute['product_size']->getFrontend()->getValue($product);
let me know if it's not meet your request.
I have found a solution for this, 3 edited files.
But these files are edited for a previous version of Magento, I don't know which version.
I have uploaded this 3 files on my Magento 1.7 and it works but when add the product to the cart it give's a error with app/code/core/Mage/Sales/Model/Quote.php
This file: Quote.php is one of the edited files, when i upload the original Quote.php it works.
Look at this pic: http://s8.postimage.org/g8bvbth0z/Naamloos.png
But maybe i get more errors in the future, i don't have any ideas..
I am a noob with this, if someone can look at the edited files and chek how they have do this and compare this with the newest files for Magento 1.7 maybe we can help to many peoples with this problem.

Custom Product Type -- Hidden Custom Option or Data Field

I'm building a custom Magento product type class. When the user adds an item of this product type to their cart, certain data needs to be associated with the item. A custom option would work well for storing this data except for the fact that the info needs to be kept hidden from the user.
I'm thinking that I either need to create some kind of hidden custom option or somehow add another datafield to the product. How would you suggest that I do this?
Thank you,
Ben
In your custom product's model add a function like this:
public function prepareForCart(Varien_Object $buyRequest, $product = null)
{
$buyRequest->setCertainData(...);
return parent::prepareForCart($buyRequest, $product);
}
This will store the 'certain data' as the result of a custom option without the effort of creating an option. Once ordered it will be carried over to the order's item's "product options" where you can later retrieve it with:
// $item is a Mage_Sales_Model_Order_Item
$item->getProductOptionByCode('certain_data');

Magento: How to tell if you're on a category page, or product page in .phtml file(s)

I am trying to program into my .phtml files an if statement if the guest is on a category list page, or on a product page.
For example this code:
<?= Mage::app()->getFrontController()->getRequest()->getRouteName(); ?>
Returns "catalog" whenever l'm on a page other than a CMS page.
Is there a way l can use a similar method to know if the user is looking at a root category, sub category or an individual product page?
Any help would be greatly appreciated!
It's been a while since I've dealt with frontend catalog pages, but give this a try.
Current versions of Magento register certain global variables (not PHP globals, but things global to the Magento system) on certain pages.
Calling the following
$category = Mage::registry('current_category');
$product = Mage::registry('current_product');
$product = Mage::registry('product');
will either return null if the objects haven't been set (i.e. you're on a page without a category or a product), or return category and product objects.
If a product object is returned you're on a product page.
If no product object is returned but a category object is, you're on a category page. Category objects have a method to getting the parent id
$category->getParentId()
A category without a parent id should be a top level category, categories with parent ids should be sub-categories.
That should give you what you need to identify where the current request is.
UPDATE: Coming back to this almost a decade later -- I likely would not rely on the contents of the registry alone to determine the page I'm on. Instead I'd use the full action name in combination with looking for the above the objects.
While Alan's answer will work, there is a more direct option, and you were actually on the right track with your code snippet... you just need to inspect the controller name rather than the module name:
<?php Mage::app()->getFrontController()->getRequest()->getControllerName(); ?>
That will return category or product based on their controllers being CategoryController.php and ProductController.php respectively.
This does assume that you've not installed any third-party modules that rewrite those controllers with their own.
I am not a big fan of checking if the current_category registry exists, because basically any controller could do this and it wouldn't necessarily mean it's a category. My way of doing it is a bit more robust:
$fullActionName = Mage::app()->getFrontController()->getAction()->getFullActionName();
if ($fullActionName == 'catalog_category_view') {
... //Category
}
elseif ($fullActionName == 'catalog_product_view') {
... //Product
}
I am afraid you are trying to do it the wrong way. I might be wrong, because you have not explained what is it exactly that you want to achieve, but I would use the layout xml to include your block on a product page with a parameter (say product-page="1") and similiarly on a category page (category-page="1").
Then you would be able to tell if you are on a product page or category page by examining those parameters inside your block:
if($this->getProductPage()) {
//this is a product page, do some stuff
}
elseif($this->getCategoryPage()) {
//this is a category page, do some stuff
}
Differentiating between main and subcategory pages might be more difficult, the first thing that comes to mind is analysis of the request variables, but that is certainly not the best approach.

Resources