javascript - loop through the cart items and return it's own ID -


i want loop thought items added shopping cart , return it's own id.

update1 : have updated method

   public function formatprice($price)     {         $productid=""; // iterate here         $cart = mage::getmodel('checkout/cart')->getquote();              foreach ($cart->getallitems() $item) {                  $productid = $item->getproduct()->getid();                  $productprice = $item->getproduct()->getfinalprice();             }           return 'id: '.$productid;       } 

now returns in 1 row therefore have result this, should use "," splite them? enter image description here

p.s: file editing data.php under \app\code\core\mage\checkout\helper

i assume first product's id 471186 , second should 463089, need foreach loop that?

update2 : split it, display 471186, 463089 want display according there current product, assuem need else, magento library supply method that?

update3: have seen latest method, store variable in array , return it. after modify depends on code have:

 $productid =array();  $cart = mage::getmodel('checkout/cart')->getquote();     foreach($cart->getallitems() $item) {  $productid[]= $item->getproduct()->getid();        }      $productid =array_filter($productid);         //remove empty array          foreach($productid $id){         return $id; //return $productid;         } 

if use return $productid , give me "array" data type result no use , tried print out $id gives first product id before. use print_r under situation seem not allowing me that.

update4: tried internal loop , assume it's going loop , display price until it's value smaller $index 0 means null.

so re-factor codes this:

    $productid =array();     $cart = mage::getmodel('checkout/cart')->getquote();  foreach($cart->getallitems() $item) {      $productid['id']= $item->getproduct()->getid();        $productid['price'] = $item->getproduct()->getfinalprice();          }          $productid =array_filter($productid);         for($index=0; $index<count($productid); $index++){    return $productid[$index]['price']; //cannot use echo, printf , print_r             } 

but return's null only, nothing display on shopping cart. enter image description here

in function can return 1 value. should concatenate results each iteration , return

$productid= ""; foreach($cart->getallitems() $item) {  $productid.= $item->getproduct()->getid();  $productprice = $item->getproduct()->getfinalprice();   } return 'id: '.$productid; 

or use array

$productid =array(); foreach($cart->getallitems() $item) {      $productid['id']= $item->getproduct()->getid();        $productid['price'] = $item->getproduct()->getfinalprice();          } $productid =array_filter($productid); //remove empty array  for($index=0; $index<count($productid); $index++){   echo $productid[$index]['id'];  echo $productid[$index]['price']; } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -