Reputation: 75
I want to fetch each value and then display it in sorting order..
foreach($simple_collection as $simple_product){
$simple_product_price = strip_tags(Mage::helper('core')->currency($simple_product->getPrice()));
$simple_product_drink_size = $simple_product->getAttributeText('drink_size');
$simple_product_id = $simple_product->getId();
$simple_product_name = $simple_product->getName();
$simple_product_url = $this->getAddToCartUrl($simple_product);
$updateUrl = str_replace('add','updateItemOptions',$simple_product_url);
echo "<span class='product-attribute-elem product-attribute-".$simple_product_id."' title='".$simple_product_id."' >" . $simple_product_drink_size .
"</span><input type='hidden' class='product-attribute-".$simple_product_id."-price' value='".
$simple_product_price."'/><input type='hidden' class='product-attribute-".$simple_product_id."-url' value='".$simple_product_url."'/>".
"<input type='hidden' class='product-attribute-".$simple_product_id."-name' value='".$simple_product_name."' >".
'<span class="qtyUpdater-'.$simple_product_id.'" style="display:none">'.
'<span onclick="NewAjaxAddCart(this,\''.$updateUrl.'\',\'-\',\'.category-products\');" class="Qmins"> </span>'.
'<input type="text" onchange="NewAjaxAddCart(this,\''.$updateUrl.'\',\'upd\',\'.category-products\');" value="0" >'.
'<span onclick="NewAjaxAddCart(this,\''.$updateUrl.'\',\'+\',\'.category-products\');" class="Qplus"> </span></span>';
}
I want to sort and display the $simple_product_id
as it is being fetched.. I tried tis
foreach($simple_collection as $simple_product){
$simple_product_price = strip_tags(Mage::helper('core')->currency($simple_product->getPrice()));
$simple_product_drink_size = $simple_product->getAttributeText('drink_size');
$simple_product_id = $simple_product->getId();
$sam_array[]=$simple_product_id;
sort($sam_array);
}
But its not working as expected.. So pls help me
Upvotes: 0
Views: 133
Reputation: 3867
$simple_product_id = array();
foreach($simple_collection as $simple_product){
$simple_product_price = strip_tags(Mage::helper('core')->currency($simple_product->getPrice()));
$simple_product_drink_size = $simple_product->getAttributeText('drink_size');
$simple_product_id[] = $simple_product->getId();
}
sort($simple_product_id);
If you want to display all the details.
$simple_product_array = array();
foreach($simple_collection as $simple_product){
$simple_product_price = strip_tags(Mage::helper('core')->currency($simple_product->getPrice()));
$simple_product_drink_size = $simple_product->getAttributeText('drink_size');
$simple_product_id = $simple_product->getId();
$simple_product_array[$simple_product_id] = array(
'id' => $simple_product_id,
'price' => $simple_product_price,
'size' => $simple_product_drink_size);
}
ksort($simple_product_array);
Upvotes: 3