Magento: Sort getCrossSellProducts - magento

I am trying to display the cross sell product on a magento product oagei get the cross sell products like this
$_crossSellProducts = $_product->getCrossSellProducts();
if($_crossSellProducts):
foreach ($_crossSellProducts as $_item):
$_item = Mage::getModel('catalog/product')->load($_item->getId());
I need to be able to sort the cross sell items by position. How can i do this?

knowzero,you cant sort crossell products by position because of position depends on category.product of same category may sort by postion

Related

Limit Product Title Characters before cut-off in Magento

I'm having trouble with my magento store's layout. Some products with long titles would get cut off with a '...' but sometimes the title won't get cut off the title and instead throw out my layout's positioning. I have attached a photo
Photo of issue
I have tried the substr function in app/design/frontend/interface/theme/template/catalog/product/view.phtml
but it just ended up cutting the product's name in the actual page of the product, not the full view like the image above shows. I just need the '...' to happen without as many characters to prevent it going to a new line and ruining the layout.
Use this trick in PHP, use substr function :
Go to template > catalog > products > list.phtml file and update product name code with this code
<?php
// define the maximum length of the product name here
$maxLength = 10;
$productName = $_helper->productAttribute($_product, $_product->getName(), 'name');
echo substr($productName, 0, $maxLength).'...';
?>

Magento - Can you show stock levels when a configurable product selection has been made

When a variation has been selected I want it to then display how many of that selection is in stock. For example for a t-shirt i select colour red and size large it would then say 4 in stock in this variation.
I don't mind whether its editing code in default.phtml or adding an extension.
Thanks.
You could do something like this:
First load the product and stock models respectively:
//Load product Model
/* Via SKU */
$sku = productSKU; //Pass the simple product SKU here
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
// Via ID: $_product = Mage::getModel('catalog/product')->load($id);
//Stock Model
$_stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product);
And then get the quantity from stock model using this:
$_productQTY = $_stock->getQty();
If you want to show the results instantly you could integrate some AJAX calls.

How can I get which products are not saleable in configurable products in magento?

I can get it through this code :-
$allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
foreach($allProducts as $p)
if($p->isSaleable())
endforeach;
But the way I want is....like I have 1 configurable product in which I have 2 colors white then it's related sizes like s,m & l so total I have 3 products of combination of white to s,m & l & same way Blue & it's related s,m & l. So finally I can say I have 6 products.
Now the thing is White->s & l and Blue->s & m these products are out of stock and the problem is that all product's name are same i.e. T-Shirts so now how can I get to know which combination products are out of stock?
Any Code Please?
Thanks
If I understand properly you want to know which size & colour is out of stock? So, in that if ($p->isSaleable) you can should be able to check the colour and size as such:
echo $p->getAttributeText("color");
echo $p->getAttributeText("size");
If that doesn't work try:
$p->getResource()->getAttribute("color")->getFrontend()->getValue($p);
Other way is having the size & color in the short description, or having some kind of SKU code to be able to distinguish them. Ie. MYPRODUCT46. Where 4 can be mapping to a colour and 6 can be mapping to a size).
I hope it helps!
Thanks Javier for your valuable support :)
The way I wanted the output, Here I am posting the solution :-
/* FOR CONFIGURABLE PRODUCTS */
$_product = Mage::registry('current_product');
if($_product->isConfigurable())
{
/* FIRST GET ALL ATTRIBUTES OF CONFIGURABLE PRODUCT */
$attributes = $_product->getTypeInstance(true)->getConfigurableAttributes($_product);
foreach($attributes as $att)
{
$pAtt = $att->getProductAttribute();
$array_attribute_code[] = $pAtt->getAttributeCode();
}
/* NOW LOOP THE PRODUCTS & GET COMBINATIONS WHERE PRODUCTS ARE OUT OF STOCK */
$allProducts = $_product->getTypeInstance(true)->getUsedProducts(null, $_product);
foreach($allProducts as $allProduct)
{
if(!$allProduct->isSaleable())
{
for($i=0;$i<count($array_attribute_code);$i++)
{
echo $allProduct->getAttributeText($array_attribute_code[$i]).' ';
}
echo "<br/>";
}
}
}
Try the above code & get pair like output like White s then beneth White l then beneth Blue s
Important to tell you that I have implemented this code in my module's .phtml file.
Thanks :)

Magento: using categories for brands

I'm starting to build a new Magento site and its primarily focused on clothing brands. Launching with around 25 each one providing a range of products in categories. so some will have everything from shoes to jumpers, some may just be shoes or accessories.
Users need to be able to view a brand and see its categories for products, as well as via a different view view all of a type of product category so all shoes.
I really don't know how to set this kind of thing up. I know i could use categories for the brands then sub categories for the clothing categories, but then i don't know how linking sub categories items together would work (I've viewing all jumpers across all brands if they have separate parent categories).
Here'show the structure needs to work
Brand_1{
Shoes{
Item 1,
Item 2
}
Coats{
Item 3
}
},
Brand 2{
Shoes{
Item 4,
Item 5,
Item 6
}
Jumpers{
Item 7,
Item 8,
Item 9
}
Accessories{
Item 10
}
Shirts{
Item 11
}
},
Brand 3{
Shoes{
Item 12,
Item 13,
Item 14
}
}
So users can view brand 1 page, see items 1-3. Or view brand 1>Shoes and see items 1-2. Or view Shoes and see items 1,2,4,5,6,12,13,14.
The way I chose to work this out was to create a custom attribute as a brand drop down to assign a brand to every item. Then I chose to create a custom admin module with a database table to store the brand details giving the ability to store extra information for each brand, that feeds into the attribute dropdown.

why don’t my (Configurable Product) options/attributes show on product page?

Magento ver. 1.5.1.0
I have an attribute set “clothing”
There are two attributes in the set: “size” and “colour”
Size is required, colour is optional (i.e. not all products have any colour options).
I have created some Simple Products where the Size is set but Colour just has the empty value.
On the product page for the relevant Configurable Product no option inputs are shown! And in the product view.phtml if I echo $this->hasOptions() it prints an empty string, ie False.
If I set the Colour to a non-empty value then both select boxes are shown on the product page and echo $this->hasOptions() prints 1, ie True.
This doesn’t make sense to me, not sure what is failing?
Im struggling with something similar and have noticed similar behavior to what you have described.
Check first if the product is actually properly configurable. this is taken from another post in SO and was meant to part of a controller. Drop this on the front end ../template/catalog/product/view.phtml just to check.
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct();
?>
<?php
if ($_product->isConfigurable()) {
$configurable = $_product->getTypeInstance();
$attributes = $configurable->getConfigurableAttributes($_product);
foreach ($attributes as $attribute) {
print $attribute->getLabel();
print "<br />";
}
}
?>
so as an answer i think you are becoming confused between custom options and configurable products.

Resources