X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Need advice (https://forum.x-cart.com/forumdisplay.php?f=34)
-   -   Wordpress plugin and shortcode (https://forum.x-cart.com/showthread.php?t=48564)

amy2203 07-12-2009 03:38 AM

Wordpress plugin and shortcode
 
hoping to be able to create a wordpress plugin and shortcode to easily add product details to posts, things like a thumbnail, title, price, add to cart button.

anyone else interested in anything like this?

anandat 07-12-2009 11:02 PM

Re: Wordpress plugin and shortcode
 
Hi Amy2203,
yes, this would be very useful plugin.
I am interested in this mod...plz keep me update.
Just make sure that this mod should compitable even if wordpress is on different database than x-cart.
Thanks :)

WebGuyJD 07-13-2009 02:13 PM

Re: Wordpress plugin and shortcode
 
Yes! Definitely. Please keep me posted as well. Great Idea.

amy2203 07-16-2009 04:32 AM

Re: Wordpress plugin and shortcode
 
it looks like its working at a basic level, i've not put in an admin panel yet for the settings so they are all in the single php file.

not sure if I'll get round to doing anything else on this soon as it works for me, so thought I'd put it here in case anyone else wants it,

save the following as xcart.php and save in your wp-plugins folder. There are a number of places where you will need to insert your settings, marked with ****, and it's designed for wordpress to be on a different database than xcart,

Code:


<?php
/*
Plugin Name: Xcart Links
Plugin URI: http://www.willowtreecrafts.co.uk
Description: Insert your Xcart products into your posts
Version: 0.1 BETA
Author: Amy Gibbs
Author URI: http://www.willowtreecrafts.co.uk
*/

/*
Xcart Links (Wordpress Plugin)
Copyright (C) 2009 Amy Gibbs
Contact me at http://www.willowtreecrafts.co.uk

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 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.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

//tell wordpress to register the xcart shortcode

add_shortcode("xcart", "xcart_product_handler");

function xcart_product_handler($attr) {


extract(shortcode_atts(array(
                'product' => 'none',
), $attr));



//$product=m111100;

//connect to xcart db
$dbc=@mysql_connect ('****','****','****');
$dbc=@mysql_select_db('****');

//query the xcart db

$q = "SELECT * FROM xcart_products LEFT JOIN xcart_pricing USING(productid) LEFT JOIN xcart_images_T ON productid=id WHERE productcode='".$product."'";

//echo $q;

$results = mysql_query($q);

$productdata = mysql_fetch_assoc($results);

$xcart_output= "<form name='orderform_".$productdata[productid]."' method='post' action='http://www.willowtreecrafts.co.uk/shop/cart.php'>";
$xcart_output= $xcart_output."<input type='hidden' name='mode' value='add' /><input type='hidden' name='amount' value='1'>";
$xcart_output= $xcart_output."<input type='hidden' name='productid' value='".$productdata[productid]."' />";
$xcart_output= $xcart_output."<div><div>".$productdata[product]."</div><div><img id='product_thumbnail' src='http://www.willowtreecrafts.co.uk/shop/imager.php/product_thumb.jpg?width=500&image=http://www.willowtreecrafts.co.uk/shop/images/T/".$productdata[filename]."' width='100' style='margin:5px;' alt='".$productdata[product]."' /></div>";
$xcart_output= $xcart_output."<div class='ProductPriceConverting' valign='top'>Price: <font class='ProductDetailsTitle'><span style='WHITE-SPACE: nowrap'>&pound;".$productdata[price]."</span></font><font class='MarketPrice'> </font></div>";
$xcart_output= $xcart_output."<div><a class='Button' href='javascript: document.orderform_".$productdata[productid].".submit();'>Add to cart </a></div>
</div>
</form>";


 
  //send back text to replace shortcode in post
  return $xcart_output;


 }

?>


then in your posts use the shortcode like the following. where 76027 is the SKU of the product.

[xcart product="76027"]

you might want to add some css to pretty it up, there are some calsses etc in there,

hope it's useful, if anyone wants to develop it further feel free,

anandat 07-16-2009 06:59 AM

Re: Wordpress plugin and shortcode
 
hi amy2003,
I tried to play with the code at localhost & I got the following error
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\blog\wp-content\plugins\xcart.php on line 57

I have replaced all your web site links with my site links & changed the database setting also.
I guess in following line of the code there is no file "imager.php" is my x-cart root directory.

$xcart_output= $xcart_output."<div><div>".$productdata[product]."</div><div><img id='product_thumbnail' src='http://www.willowtreecrafts.co.uk/shop/imager.php/product_thumb.jpg?width=500&image=http://www.willowtreecrafts.co.uk/shop/images/T/".$productdata[filename]."' width='100' style='margin:5px;' alt='".$productdata[product]."' /></div>";

Please help to resolve the issue :)

amy2203 07-16-2009 07:55 AM

Re: Wordpress plugin and shortcode
 
Quote:

Originally Posted by anandat
hi amy2003,

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\blog\wp-content\plugins\xcart.php on line 57

Please help to resolve the issue :)


the problem is that the mysql query is not returning a product, are you using the SKU in the shortcode?

anandat 07-17-2009 05:48 AM

Re: Wordpress plugin and shortcode
 
Quote:

Originally Posted by amy2203
the problem is that the mysql query is not returning a product, are you using the SKU in the shortcode?

Yes I have used SKU in short code. also my product id & SKU are same.
For example for product id & SKU number for product 3415 I put [xcart product="3415"]

r u sure there is file "imager.php" in x-cart root ?

amy2203 07-17-2009 06:02 AM

Re: Wordpress plugin and shortcode
 
try running this query on your database directly and see if it works

SELECT * FROM xcart_products LEFT JOIN xcart_pricing USING(productid) LEFT JOIN xcart_images_T ON productid=id WHERE productcode=3415

amy2203 07-17-2009 06:03 AM

Re: Wordpress plugin and shortcode
 
Quote:

Originally Posted by anandat
r u sure there is file "imager.php" in x-cart root ?


Am I sure that YOU have a file called imager.php in your root? funnily enough no! have a look at your file manager to see if it's there

anandat 07-17-2009 06:35 AM

Re: Wordpress plugin and shortcode
 
Quote:

Originally Posted by amy2203
try running this query on your database directly and see if it works

SELECT * FROM xcart_products LEFT JOIN xcart_pricing USING(productid) LEFT JOIN xcart_images_T ON productid=id WHERE productcode=3415

Yes, query is running fine in phpmyadmin


All times are GMT -8. The time now is 12:13 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.