Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    ubh
    ubh is offline
    Regular Coder ubh's Avatar
    Join Date
    Apr 2008
    Location
    Portland, Oregon U.S.A.
    Posts
    443
    Thanks
    108
    Thanked 15 Times in 14 Posts

    external var and foreach counting

    I have a very embarrassing question. I am trying to count items in a foreach and then echo out the final number out side of the foreach... yet my number instead of coming out to being 2 comes out to being 12...

    Anyone know how I can use an external var out side of a foreach correctly so it can output the correct number?

    Seems like 101 stuff but I am stumped. ($itemCount is my bugger)

    PHP Code:
    <?php
    Mage
    ::getSingleton('core/session', array('name'=>'frontend'));
    $session Mage::getSingleton('checkout/session');
    $itemCount "";
    foreach (
    $session->getQuote()->getAllItems() as $item) {
    $cProduct Mage::getModel('catalog/product')->loadByAttribute('sku',$item->getSku()); 
        foreach (
    $cProduct->getCategoryIds() as $catId){
            if(
    $catId == "64"){
                
    $itemCount .= $itemCount 1;
            }
        }
    }
    echo 
    $itemCount;
    ?>

  • #2
    New Coder
    Join Date
    Dec 2008
    Posts
    16
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I am not sure I understood your issue .. still try this please


    PHP Code:
    <?php
    Mage
    ::getSingleton('core/session', array('name'=>'frontend'));
    $session Mage::getSingleton('checkout/session');
    $itemCount 0;
    foreach (
    $session->getQuote()->getAllItems() as $item) {
    $cProduct Mage::getModel('catalog/product')->loadByAttribute('sku',$item->getSku()); 
        foreach (
    $cProduct->getCategoryIds() as $catId){
            if(
    $catId == "64"){
                
    $itemCount $itemCount 1;
            }
        }
    }
    echo 
    $itemCount;
    ?>
    Dedicated Servers - sales@hivelocity.net - 1-888-869-HOST(4678)
    Award winning Managed Hosting - Dedicated Server Hosting
    Managed Dedicated Servers. Reseller Discounts. 24/7 Impressive Tech Support.

  • #3


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •