+ Reply to Thread
Results 1 to 13 of 13

Thread: Embedding Products on Other Webpages

  1. #1
    Client SketchWork's Avatar
    Join Date
    Aug 2007
    Posts
    79
    Squirrelcart version
    v3.3.2

    Embedding Products on Other Webpages

    Hi Jamie,

    I'm sure I saw this somewhere else at some point, but can't find it.

    Is there a way to add a SC prodct to an external website so it picks up the description and image with a link to the product in the cart.

    I'm sure I've seen it somewhere.

    Cheers, Justin

  2. #2
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,829
    Squirrelcart version
    v3.3.7
    Not really, we don't have a built in way to handle that.

    If you view the product on your Squirrelcart store page, you could view the source of the page, copy the HTML, and put it on any page you want. That HTML will be static. It won't change when you change the product's name, description, etc.. at a later date.

    It would be possible with some custom code to create a PHP page on your site that will show a product based on a query string, like:
    http://www.example.com/product_iframe.php?rn=123

    If you then put some PHP code in that file to include our functions and display the product with record_number equal to 123, you could then use that URL as the src for an <iframe />

    Code:
    <iframe src="http://www.example.com/product_iframe.php?rn=123" width="350" height="250" />
    If you can get the page to show the product, then you could put that iframe on any webpage, just like you can do with our slideshows.

    If you need to do it this way, let me know and I can write some code for it. I've been thinking of offering a way to do this in the future from the product records in the control panel, in a similar fashion to how the Slideshow records have this fieldset:
    example.png

  3. #3
    Client SketchWork's Avatar
    Join Date
    Aug 2007
    Posts
    79
    Squirrelcart version
    v3.3.2
    Ahh, yes. I'll have a think about it.

  4. #4
    Client Beery_Asst's Avatar
    Join Date
    Feb 2006
    Location
    Houston, TX
    Posts
    189
    Squirrelcart version
    v3.4.0
    Hmm,

    That would actually be a nice feature to add. I am not sure if the phpBBB board permit or if other bulletin board groups would support it (Yahoogroups for example). If they do support that iframe code, then it would be a way to "promote" a product when it is appropriate with a Buy Now button within the message.

    A link to the product record on the storefront works as well, you say tomatoes, I say tomato's <grin>.

    Beery

  5. #5
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,829
    Squirrelcart version
    v3.3.7
    Many forums do not allow you to post HTML, but some do. Here is the code for product_iframe.php:

    PHP Code:
    <?php
    require_once 'squirrelcart/pre_storefront.php';
    if (
    is_numeric($_GET['rn'])) {
        
    $prod_html sc_product($_GET['rn']);
        
    $prod_html str_replace('<a','<a target="_blank"',$prod_html);
        
    $prod_info sc_xml_safe(sc_query("SELECT IF(Page_Title, Page_Title, Name) AS Title, Keywords, Brief_Description FROM Products WHERE record_number = '$_GET[rn]'"));
    }
    if (empty(
    $prod_html)) $prod_html 'Product not found.';
    ?>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="title" content="<?php print $prod_info['Title']?>" />
        <meta name="keywords" content="<?php print $prod_info['Keywords']?>" />
        <meta name="description" content="<?php print $prod_info['Brief_Description'?>" />
        <title><?php print $prod_info['Title'?></title>
        <link rel="stylesheet" type="text/css" href="<?php print SC_MASTER_THEME_DIR_DYN ?>/style_main.css.php" />
    </head>
    <body>
    <div id="sc">
    <?php print $prod_html;?>    
    </div>
    </body>
    </html>
    If you drop that in a file named "product_iframe.php" and drop it at the same level as your storefront page, you can then do this:

    http://www.example.com/product_iframe.php?rn=123

    It should show that product thumbnail. You can then use that URL in an iframe src on any page you want.

    You will probably want to add a small amount of CSS to make it look better. I left that out. If you change this:
    PHP Code:
    $prod_html sc_product($_GET['rn']); 
    to this, you will get a product detail page instead:
    PHP Code:
    $prod_html sc_product($_GET['rn'], 'product_detail'); 

  6. #6
    Client SketchWork's Avatar
    Join Date
    Aug 2007
    Posts
    79
    Squirrelcart version
    v3.3.2
    Brilliant! With a little tweeking that will work perfectly.

    Thanks.

  7. #7
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,829
    Squirrelcart version
    v3.3.7
    You're welcome! I just moved this to Tutorials, and mentioned it on our new Facebook page so it should be famous shortly!

  8. #8
    Client SketchWork's Avatar
    Join Date
    Aug 2007
    Posts
    79
    Squirrelcart version
    v3.3.2
    lol - all 11 people will be jumping for joy

  9. #9
    Client
    Join Date
    Mar 2006
    Location
    Ontario, Canada
    Posts
    294
    Squirrelcart version
    v3.4.0

    Sticks in iFrame

    Jamie,

    Love the code...

    Can you look at www.woodwickcandles.ca I have put the code on my start page (trying it out) all good except when I click the "Add To Cart" the button link loads within the iFrame not a fresh page load.

    What might I be doing wrong?

    John

  10. #10
    Client
    Join Date
    Mar 2006
    Location
    Ontario, Canada
    Posts
    294
    Squirrelcart version
    v3.4.0

    I'm Thinking "Target=_blank"

    Target=_blank... is that something I should be looking for?

  11. #11
    Client
    Join Date
    Mar 2006
    Location
    Ontario, Canada
    Posts
    294
    Squirrelcart version
    v3.4.0

    <base target="_top" />

    Jamie,

    Did some research...

    If you add <base target="_top" /> in the head of the product_iframe.php file it works fine. Just not sure if all browsers understand <base target="_top" />

    Then when I click the add to cart button, it breaks out of the iframe and browser window opens with the store!!!

    Thanks... for the code...

    John

  12. #12
    Squirrelcart Staff Jamie's Avatar
    Join Date
    May 2002
    Posts
    6,829
    Squirrelcart version
    v3.3.7
    That will certainly work, but it's probably better to change the target attribute in the links on the page itself. I just updated the code above to do that. The new line is:
    PHP Code:
    $prod_html str_replace('<a','<a target="_blank"',$prod_html); 

  13. #13
    Client tgrant's Avatar
    Join Date
    Mar 2011
    Posts
    132
    Squirrelcart version
    v3.3.2
    Quote Originally Posted by SketchWork View Post
    lol - all 11 people will be jumping for joy
    We may be small in number, but we're dedicated & determined

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

     

Posting Permissions

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