Jump to content

Admin Controller and Webservice


A-Z Hosting

Recommended Posts

I'm trying to write up a migration tool that imports from xml all the categories, products, images, attributes, etc.  I've found my way around building the skeleton with no problems and it even has a tab! I'm now at the creation of Categories and Products and trying to figure out the best way to do it.  

 

I've looked at using the AdminImportController but there is no real documentation (or even coders notes) on what those functions need passed so it seems a tough route. Next I've looked at Webservice as an option.

 

What seems to be the issue is that my calls to the webservice run and then never return to the function. If I throw the same thing in __construct() it runs fine prints a result and continues to render just fine.  It's probably something simple I am overlooking.

	public function createCategory() {
	
		require 'PSWebServiceLibrary.php';
		
		try
		{
		$webService = new PrestaShopWebservice('http://www.blahblah.com/ps/', '0B9UKVBxxxxxxxYFPGTLVHX8DRJG1', true);			

			$opt['resource'] = 'customers';
			
			$xml = $webService->get($opt);
		
			// Here we get the elements from children of customers markup "customer"
			$resources = $xml->customers->children();
		}
		catch (PrestaShopWebserviceException $e)
		{
			// Here we are dealing with errors
			$trace = $e->getTrace();
			if ($trace[0]['args'][0] == 404) echo 'Bad ID';
			else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
			else echo 'Other error';
		}

		echo '<table border="5">';

		if (isset($resources))
		{
				echo '<tr><th>Id</th></tr>';
				foreach ($resources as $resource)
				{
					// Iterates on the found IDs
					echo '<tr><td>'.$resource->attributes().'</td></tr>';
				}
		}
		echo '</table>';
		return;
	}
Link to comment
Share on other sites

Yes I figure the attributes are going to be really tough through webservice.  Is there  better way to add products, categories, customers etc?  I would much rather push the additions through a function or class.  I was going to inject directly to the databases, but the category levels and nesting I can already tell are going to be quite a chore.

Link to comment
Share on other sites

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...