Jump to content

Adding product by visitors (webservice)


ArashAnvari

Recommended Posts

For Prestashop 1.6.1.7
Hello,
I have a section in my site visitors they can express their product (second-hand) with features such as multiple photos, product name, product price, contact the seller, description, keywords (optional) them.
I'm going through prestashop webservice after the form is submitted and record on second-hand product categories,
Categories ID is 994.
I wrote this code:
<?php
$shop_url = 'http://subdomain.test.com';
$secret_key = '9CQEDRKAD5IF8C9FFPP59T7AJSCPIW2Q';
$debug = true;

require_once('./PSWebServiceLibrary.php');

	try {
		$webService = new PrestaShopWebservice($shop_url, $secret_key, $debug);
		$xml = $webService->get(array('url' => $shop_url.'/api/products?schema=blank'));
		$resources = $xml->children()->children();
		
		if (!isset($_POST['btn_submit']))
		{
			$html = '<form action="" method="POST"><table border=1>';
			foreach ($resources as $key => $resource)
			{
				$html .= '<tr><th>'.$key.'</th><td>';
				$html .= '<input type="text" name="form['.$key.']" value=""/>';
				$html .= '</td></tr>';
			}
			$html .= '<td colspan=2><input type="submit" name="btn_submit" value="btn_submit" /></td>';
			$html .= '</table></form>';
			echo $html;
		}
		else
		{
			foreach ($resources as $nodeKey => $node)
			{
				$resources->$nodeKey = $_POST['form'][$nodeKey];
			}
			
			try {		
				$opt = array('resource' => 'products');
				$opt['postXml'] = $xml->asXML();
				$xml = $webService->add($opt);
				echo "Successfully added.";			
			}
			catch(PrestaShopWebserviceException $ex) {
				echo 'Other error: <br />' . $ex->getMessage();
			}
		}
	}
	catch (PrestaShopWebserviceException $ex) {
		echo 'Other error: <br />' . $ex->getMessage();
	}
?>

this is add_product.php in prestashop root folder.

PSWebServiceLibrary.php in prestashop root folder.

 

Why not working properly, and how can I sum up the form that the product name, product description, product price.

 

result screentshot attached.

post-1321061-0-17751100-1480974271.txt

Edited by reminoco (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...