Don't change that code in the above post. It will mess up your site.
I created an API key and then manually changed the webservice_xxx databases to a different shop for testing.
In WebserviceRequest.php I found this code:
- Code: Select all
protected function shopHasRight($key)
{
$sql = 'SELECT 1
FROM '._DB_PREFIX_.'webservice_account wsa LEFT JOIN '._DB_PREFIX_.'webservice_account_shop wsas ON (wsa.id_webservice_account = wsas.id_webservice_account)
WHERE wsa.key = \''.pSQL($key).'\'';
foreach (self::$shopIDs as $id_shop) {
$OR[] = ' wsas.id_shop = '.(int)$id_shop.' ';
}
$sql .= ' AND ('.implode('OR', $OR).') ';
if (!Db::getInstance()->getValue($sql)) {
$this->setError(403, 'No permission for this key on this shop', 132);
return false;
}
return true;
}
So the shop id needs to be changed for what shop is being access which is here:
- Code: Select all
protected function shopExists($params)
{
if (count(self::$shopIDs)) {
return true;
}
if (isset($params['id_shop'])) {
if ($params['id_shop'] != 'all' && is_numeric($params['id_shop'])) {
Shop::setContext(Shop::CONTEXT_SHOP, (int)$params['id_shop']);
self::$shopIDs[] = (int)$params['id_shop'];
return true;
} elseif ($params['id_shop'] == 'all') {
Shop::setContext(Shop::CONTEXT_ALL);
self::$shopIDs = Shop::getShops(true, null, true);
return true;
}
} else {
die();
self::$shopIDs[] = Context::getContext()->shop->id;
return true;
}
$this->setError(404, 'This shop id does not exist', 999);
return false;
}
So changing
- Code: Select all
self::$shopIDs = Shop::getShops(true, null, true);
to what shop is being accessed using the key seems to work. I manually set this to the shop number of the key by a mysql query should do the trick.
I still am getting all the shop data so this is where I'm stuck right now.
I looked at orders in the database and they are listed by the owner, not store. This function getFilteredObjectDetails probably needs to have the owner added to limit access only to the owner, I guess. It probably would be best to make the function shopExists also use the owner too.
I'll do more testing later and try to report back.