Jump to content
powersvolk2

Поиск в истории заказов по артикулу

Recommended Posts

Opencar 2.3 Пытаюсь сделать в исории заказа фильтр поиска по артикулу Не получаеться написать запрос

 

Нужно получить Артикулы (sku) из таблички oc_order_product и записать  в табличку oc_order
при условии что id таблички oc_order_product = id таблички oc_order_product


Табличка oc_order

-----------------------------
|order_id|firstname|lastname|
|1            |Igor         |Volk      |     
|2            |Vova       |Alex      |
|3            |Sasha     |ivanov  |
-------------------------------------- 

Табличка oc_order_product

----------------------------------------------------
|order_product_id|order_id  |product_id|
|1                         |1             |42             |     
|2                         |2             |43             |
|3                         |3             |44             |
----------------------------------------------------

Табличка oc_order_product
---------------------------
|product_id   |sku      |
|42                |1fdf     |          
|43                |2123   |         
|44                |34543 |   
----------------------------

Результат 

-------------------------------------------------
|order_id|firstname|lastname|sku      |
|1           |Igor         |Volk        |1fdf     |          
|2           |Vova       |Alex        |2123   |
|3           |Sasha     |ivanov    |34543  |
--------------------------------------------------

 

 

Вот вариант мого запроса 

 

SELECT o.order_id, o.firstname, o.lastname, (SELECT p.sku FROM oc_order_product op LEFT JOIN oc_product p ON op.product_id = p.product_id) AS sku, (SELECT os.name FROM oc_order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '1') AS status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `oc_order` o LIMIT 1, 20

 

Но выдает ошибку  Subquery returns more than 1 row

Edited by powersvolk2

Share this post


Link to post
Share on other sites

А зачем вам что-то записывать в oc_order?

Вы можете просто по product_id прицепить oc_product к oc_order_product и оттуда взять sku

Share this post


Link to post
Share on other sites

Если кому интересно сделал вот так 

SELECT o.order_id, o.firstname, o.lastname, p.sku as sku, (SELECT os.name FROM oc_order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '1') AS status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `oc_order` o LEFT JOIN oc_product p ON (product_id = p.product_id) LIMIT 1, 100

Share this post


Link to post
Share on other sites

И это работает?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.