PrestaShop 1.7.6.4 WebService API故障求助:产品不全、分类无法获取及代码报错
Hey there, let's work through this PrestaShop API problem together— I’ve debugged similar issues on 1.7.x versions, so here’s a step-by-step breakdown to get things sorted:
1. Fix the Category.php Override Error
The error Trying to get property 'php_self' of non-object points directly to your custom override file at /override/classes/Category.php line 14. Overrides are powerful but can break core functionality if not implemented correctly. Here’s how to fix it:
- First, isolate the issue: Rename the file to
Category.php.bak(temporarily disabling the override), then clear PrestaShop’s cache (go to Back Office → Advanced Parameters → Performance → Clear Cache). Test the API again—if the category error disappears, you’ve confirmed the override is the culprit. - Inspect the problematic code: Open the original override file and look at line 14. The most common cause here is uninitialized context access. For example, if the code uses
$this->context->php_selfwithout first ensuring$this->contextexists:- If this is in a class method, make sure you’re either calling
parent::__construct();in the override’s constructor (to inherit the parent class’s context setup) or explicitly fetching the context with$context = Context::getContext();before accessing$context->php_self.
- If this is in a class method, make sure you’re either calling
- Compare with core code: Cross-reference your override with the native
/classes/Category.phpfile. Ensure your custom logic doesn’t overwrite or skip critical initialization steps that the core class relies on. If you’re unsure about the override’s purpose, consider removing it (if it’s not essential) or rewriting the custom logic to align with core conventions.
2. Resolve the Limited Product Count (~20 Products Returned)
This is almost always a default pagination limit in PrestaShop’s WebService:
- Add pagination parameters to your API request: The WebService defaults to returning 20 items per page. To get more products, modify your request URL with:
?limit=50to return 50 products per page (adjust the number as needed—max is usually 1000, depending on your server’s memory limits)?limit=0,100to fetch the first 100 products (format:[offset],[number_of_items])?page=2to load the second page of results
- Double-check API permissions: Even though you enabled all permissions, verify in Back Office → Advanced Parameters → Web Service → [Your API Key] that the "Products" resource is set to "Read" or "All" permissions.
Final Notes
Start with fixing the override error first—if the category class is broken, it can prevent proper retrieval of category data and might even interfere with how product data is fetched. Once that’s resolved, adjusting the pagination parameters should let you access all your products.
内容的提问来源于stack exchange,提问作者Yàs Sine

