Weird error during product update via API - prestashop

​I'm working on simple python script for updating product using prestapyt library.
Prerequisites
✅ API is enabled
✅ API Key is generated with full permissions
✅ Other operations like retrieving single product or all products work fine
Script
from prestapyt import PrestaShopWebServiceDict
prestashop = PrestaShopWebServiceDict('{API_URL}', '{API_KEY}', debug=True, verbose=False)
new_price = 28.0
product_id = '22806'
product = prestashop.get('products', product_id)
product['product']['price'] = new_price
product['product'].pop('manufacturer_name', None)
product['product'].pop('quantity', None)
prestashop.edit('products', product)
Error
prestapyt.prestapyt.PrestaShopWebServiceError: "[SQL Error] Table '{SENSITIVE}.ps_accounts_incremental_sync' doesn't exist. From DbCore->insert() Query was : INSERT INTO `ps_accounts_incremental_sync` (`id_shop`, `id_object`, `type`, `created_at`, `lang_iso`) VALUES ('1', '22806', 'products', '2022-11-09T19:40:25+01:00', 'pl') ON DUPLICATE KEY UPDATE `id_shop` = '1',`id_object` = '22806',`type` = 'products',`created_at` = '2022-11-09T19:40:25+01:00',`lang_iso` = 'pl'"
To be honest, I have no idea how to approach that. Table name ps_accounts_incremental_sync doesn't even exist in prestashop github source code (or it's not searchable?).
I've tried requesting API using postman with same result (screen attached):
Any help greatly appreciated!

Related

How to get variable from feature, which is using in karate.repeat?

I need to create 2 items, use get method to check if everything is ok and after that I should delete these items.
I have 1 tc - getItem, which uses 2 helpers (postItem and deleteItem).
For getItem I need to have itemId, which I get from postItem, where this variable is defined. After that I use the same itemId for deleteItem as afterhook. What I do:
Feature:get item
Background:Pre-conditions
* url apiUrl
* call read('classpath:/helpers/features/postItem.feature')
* configure afterScenario = function(){karate.call('classpath:/helpers/features/deleteItem.feature')}
Scenario: Get items
* path '/items/'
And param id = itemId
When method Get
Then status 200
It works but I create only 1 item and delete it correctly because itemId is predefined in postItem and I`m able to re-use it. I saw how to use karate.repeat from HERE but when I do the next
* def item = function(i){ return karate.call ('classpath:/helpers/features/postItem.feature')}
I`m not able to get itemId and as a result not able to delete it. Have tried to use
* print item.response
but it is "null"
So I have 2 questions:
How to get variable from postItem
How to delete each of these created items using afterHook?
May I offer some advice. I would NOT try to create helpers and re-use them like this. Please take some time to read this, and then you may understand: https://stackoverflow.com/a/54126724/143475
I would definitely not use a hook also. Please think of the people who need to maintain your test in the future, they will cry.
Here is how I would write your test. And let me repeat, it is OK to repeat some code when your are doing test automation. For a real, working example, see here.
Background:
* url apiUrl + '/items'
Scenario:
* request {}
* method post
* status 201
* path response.id
* method get
* status 200
* request {}
* method post
* status 201
* path response.id
* method delete
# and so on
Otherwise, the only thing I will say is please refer to the documents on how you can call features and get data back in a loop without using karate.repeat() which should be used only for creating JSON arrays. You can see this answer which has an example and links to the documentation: https://stackoverflow.com/a/75394445/143475
Have found solution how can I do this using DRY pattern + afterhooks.
Feature:get items
Background:Pre-conditions
* url apiUrl
* def item = function(i){ return karate.call ('classpath:/helpers/features/postItem.feature')}
* def createdItem = karate.repeat(2, item )
* table createdItems
|itemId |
|createdItem[0].response.data.id|
|createdItem[1].response.data.id|
* configure afterScenario = function(){karate.call('classpath:/helpers/features/deleteItem.feature', createdItems )}
Scenario: Get all items
* path '/items'
When method Get
Then status 200
It works, but maybe it also can be updated. Im new in this)
So, basically, what I do:
I create 2 items, for get method using karate.repeat with calling postItem feature
I create table with itemId references
Create afterHook with calling deleteItem.feature, which should have argument itemId and I provide created table for this.
And I have scenario, which checks created items
And after that these created items are deleted by afterhooks.
As a result, I have clear scenario, which contains
Pre-conditions --> creating items (preparing data)
Scenario body --> GET method
Post-conditions --> deleting created items and returning to default state.
All of this I do because dont have DB read permission) In an ideal world, preparing data should be done via SQL and deleted as well)
Hope this will help someone)) Also, if you find better solution, feel free to write this here) Tnx

Shopify API - Can't find orders created by another application

I'm trying to find all of my store's orders, and found out that I can only received list of manually created orders, but not orders created by another applications throughout APIs.
Here my current orders list:
And here my code to find all orders
temp = ShopifyAPI::Order.find(:all, :params=>{:status => 'any', :fields => 'name'})
or find single order with order_id
order = ShopifyAPI::Order.find(show_params['order_id'])
The 1st line of code return only 1 order (#1013) created by me
[#<ShopifyAPI::Order:0x0000000c6ae170 #attributes={"name"=>"#1013"}, #prefix_options={}, #persisted=true>]
The 2nd line of code raised error:
#<ActiveResource::ResourceNotFound: Failed. Response code = 404. Response message = Not Found (Not Found).>
Note that all of my other orders except #1013 created by 3rd-application:
What should I do now to find all my orders?
Thank in advance.
P/s: I use 2020-01 api version.
By default, read_orders scope grants you access to get orders created not earlier than 60 days ago.
You have to request read_all_orders scope to be able to fetch all orders now.

Computed many2many field dependencies in Odoo 10

I am trying to create a new field on the sale.order.line model. This field is called x_all_route_ids, and is meant to contain all of the available stock.location.route for an Order Line.
It should look up the product_id.route_ids and product_id.routes_from_categ_ids for the Order Line, and join them together into a single set of Routes.
I am trying to set this field up through the Odoo UI, but getting error related to my "Dependencies".
I have Dependencies defined as:
product_id, product_id.route_ids, product_id.routes_from_categ_ids
I have Compute defined as:
for record in self:
record['x_all_route_ids'] = record.product_id.route_ids
To start I am just trying to get the field to show the same value as product_id.route_ids, but it's not working. When I save, I get the following error:
Error while validating constraint
Unknown field u'product_id' in dependency u'product_id'
Any idea what I'm doing wrong here?
I was able to get this working. I think the issue was just a bug in the UI that came about because I had been trying so many different things. After refreshing the page, the following worked:
Dependency = product_id
Field type = many2many
Compute method:
for record in self:
full = record.product_id.route_ids | record.product_id.route_from_categ_ids
record['x_all_route_ids'] = full.filtered('sale_selectable')

Prestashop 1.5.6.2 shows wrong products in the category (FrontOffice)

I'm using prestashop 1.5.6 and make a bulk category and product operation into mysql via 3rd party libraries (which i was wrote). Everything fine till some of my products show in wrong category.
For eg i have A product in A category;
But when i go to the B category A product is also there.
I think something wrong with my ps_category_product table with position column.
I'm updating this table with code below;
$sqlFirst = 'SELECT id_product, id_category_default, xml_id_product FROM ps_shop_product';
$queryFirst = $db->prepare($sqlFirst);
$queryFirst->execute();
while ($rowFirst = $queryFirst->fetch(PDO::FETCH_OBJ)){
$sqlProductAddCatPosFirst = '
INSERT INTO ps_shop_category_product
(id_product, id_category, position)
VALUES
(?, ?, ?)
';
// ps_shop_category_product Sql sorgumuzu hazırlayalım
$queryProductAddCatPosFirst = $db->prepare($sqlProductAddCatPosFirst);
$queryProductAddCatPosFirst->bindParam(1, $rowFirst->id_product, PDO::PARAM_INT);
$queryProductAddCatPosFirst->bindParam(2, $rowFirst->id_category_default, PDO::PARAM_INT);
$queryProductAddCatPosFirst->bindParam(3, $rowFirst->id_product, PDO::PARAM_INT);
// ps_shop_category_product Hazır Sql sorgumuzu çalıştıralım
$queryProductAddCatPosFirst->execute();
}
But everything fine on Backoffice > Products > Filter By Category tab.
It shows correct products under category. Is there any specific detail in Front Office? If i truncate table (ps_category_product), my products dont shown in categories in Front Office. What am i missing?
Any help will greatly appricated.
Update
After #bcsteeve s comment, i create a sample category from BackOffice and all products shown in correct categories. When i look at the changes on my mysql tables; only ps_category table has changed some values nleft and nright columns.
In my simple webservice, i assign nleft and nright to 0 (zero). But now they have some values different then 0 (zero).
Now i think my problem is recalculating hierarchy of ps_category table.
Is there any specific prestashop core controller and/or method that
can recalculate nleft and nright values on ps_category table?
Because i dont want to add category manually after my webservice is
update my products and categories.
Thanks in advance!
You can regenerate the nleft and nright columns of the ps_category table with the following code:
require_once '../config/config.inc.php';
try {
Category::regenerateEntireNtree();
} catch (CategoryException $e) {
echo $e->getMessage();
}
I had the same problem in prestashop 1.6.
Switch off cache if you have file cache selected.
Cache switched on after few minutes and all back to work again.
I had a similar problem, products list in category page are wrong, i upgraded the layered navigation module and it had fixed the problem, i think i should create some indexing crons for this module

Bigcommerce API batch update?

is there a way to batch update products or orders using bigcommerce api?
I need to update multiple products with just one call if possible.
If your using the PHP library which can be downloaded # https://github.com/bigcommerce/auspost-api-php
I first made a local database of products using the following calls...
$filter = array('limit' =>, 'page' =>1);
Bigcommerce::getProducts($filter);
foreach($products as $product){
$sku = $product->SKU;
$id = $product->id;
/* write some code in the loop to add all the products to your DB */
}
Once you have a DB of all your products you can make SQL call with SELECT ALL from your Database and update them with some static content like below(put below in a loop for each product)....
$UpdateQuery = array('description' => 'Some Random Text added to all descriptions')
Bigcommerce::updateProduct($Bicommerce_Product_ID,$UpdateQuery)
This would bulk add 'Some Random Text added to all descriptions' too products in your database. You need to use the Bigcommerce product ID in each loop to target it and update in 'bulk'.
Hope this is useful - can verify it works as use it myself :)