Fork me on GitHub

Random pncommerce items  Bottom

  • I'm trying to get a random item from my pncommerce installation into a block, but I can't get the "add item to cart" button to work without a proper "authid" value. Is that something I can call from the database, or is it dynamically generated?

    Here's what I have...I realize it's 'the old way', but it gets done what I need:



    Code

    <?
    // Connect to the database
    mysql_connect ('localhost', 'myname', 'mypassword') ;
    mysql_select_db ('mydatabase');

    // Number of items displayed
    $num_displayed = 1 ;

    // Select random items from the database
    $result = mysql_query ("SELECT * FROM _pncommerce_items ORDER BY RAND() LIMIT $num_displayed");

    // For all the rows that you selected
    while ($row = mysql_fetch_array($result))

    {
    // Display them to the screen...

    echo "<a href=\"../module-pncommerce-itemview-ItemID-" . $row["ItemID"] . ".phtml\"><img src=\"../modules/pncommerce/product_images/" . $row["ItemSKU"] . "tn.jpg\" border=0 alt=\"" . $row["ItemName"] . "\"></a>";
    echo "<a href=\"../module-pncommerce-itemview-ItemID-" . $row["ItemID"] . ".phtml\">" . $row["ItemName"] . "</a>";
    echo "<div align=\"left\">";
    echo "<form action=\"../index.php?module=pncommerce&func=itemedit\" method=\"post\">";
    echo "<input type='hidden' name='authid' value=''><font class='pn-normal'>Add</font>";
    echo "<input type='text' name='ItemQuantity' value='1' size='2'>";
    echo "<input type='hidden' name='ItemID' value=\"" . $row["ItemID"] . "\">";
    echo "<input type='hidden' name='Mode' value='add'>";
    echo "<input class='pn-button' TYPE='submit' VALUE='Add to my Cart'>";
    echo "<input type='hidden' name='cartview' value='on' >";
    echo "</form>";
    echo "</div>";
    }
    ?>




    edited by: quasiman, Apr 04, 2007 - 04:40 PM

    --
    born ok the first time
  • echo '';


    ..hope it works.. ;)
  • hmmm....not quite:

    Code

    Fatal error: Call to undefined function: pnsecgenauthkey() in /home/quasito/public_html/generator/shopitems.php on line 24


    --
    born ok the first time
  • Oh wait, that's probably just because I haven't put it in a PostNuke environment yet....back in a bit:

    --
    born ok the first time
  • YES!!!! It works!!! I didn't turn it into it's own block, I just added it as a PHP file, but it still does everything it's supposed to! :D:D:D

    --
    born ok the first time
  • :D cool. I might have to borrow those form vars myself :)

    later!
  • Can we all use it?!
    Perfect timing,
    Ive just been asked to make a site for somebody.
    He wants a shop!!!!!!!
  • lol, I formerly release this code under the GPL:

    // LICENSE
    //
    // This program is free software; you can redistribute it and/or
    // modify it under the terms of the GNU General Public License (GPL)
    // as published by the Free Software Foundation; either version 2
    // of the License, or (at your option) any later version.
    //
    // This program is distributed in the hope that it will be useful,
    // but WITHOUT ANY WARRANTY; without even the implied warranty of
    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    // GNU General Public License for more details.
    //
    // To read the license please visit http://www.gnu.org/copyleft/gpl.html
    // ----------------------------------------------------------------------


    Enjoy! ;)

    --
    born ok the first time
  • I discovered a little problem with this...using Autothemes the block won't show up.

    I've got a message posted over at Spidean, if anyone is interested they can watch the topic here:
    http://spidean.mcken…read-tid-3130.phtml

    --
    born ok the first time
  • don't know about the AT thing, but maybe moving that query to the ADOdb "style" would solve it.
  • Well I more or less fixed it...

    Autothemes use HTML files for their themes, so they've made it so you can add PHP in the HTML files and have it read. But if you write a PHP script with login information into an HTML file....well you're just asking for trouble obviously.
    So instead I wrote the PHP script into it's own .php file, and then used for the HTML file.

    Still, for some reason I can't have other blocks in the same table as as the PHP without getting an error....so for the time being, I'll just use this by itself.

    I'll see if I can get ADOdb going on this...it's supposed to be a lot faster, and the way I'm doing it now isn't too great for databases that are larger.

    [edit]
    Oh, and if you want to see what it looks like, I have it running on my testsite....don't bother trying to order anything from it - it's getting info from my main page, so it won't work. This just shows the look of it:
    http://www.quasitown.com/testsite/

    --
    born ok the first time
  • 0 users

This list is based on users active over the last 60 minutes.