S
S
strify_252020-07-07 10:00:56
1C-Bitrix
strify_25, 2020-07-07 10:00:56

How to add products to the order via api?

To add a product to a placed order, I use the CSaleBasket::Add function:

$arFields = array(
        "PRODUCT_ID"        => $_POST["id"], 
        "NAME"              => htmlspecialchars_decode($name), 
        "PRICE"             => $price, 
        "CURRENCY"          => "RUB", 
        "ORDER_ID"          => $_POST["order"],
        "LID"               => "s1", 
        "QUANTITY"          => 1
    );

    $basketID = CSaleBasket::Add($arFields);


The product is added, but when viewing the order in the admin panel, it does not have a preview photo and a link to the product detail page
b3a5d4760d.jpg
How to add a product with all the parameters correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2020-07-07
@strify_25

1. Remove line:

"NAME"              => htmlspecialchars_decode($name),

2. make sure that the element"PRODUCT_ID" => $_POST["id"], ID is passed here . 3. "PRICE" => $price, remove, otherwise add
'CUSTOM_PRICE' => 'Y',

A
Andrey Nikolaev, 2020-07-07
@gromdron

Look at the example in the documentation for the method: https://dev.1c-bitrix.ru/api_help/sale/classes/csa... Offhand
:
- no module indication
- no provider indication
- no PRODUCT_PRICE_ID indication (if necessary)
But this is not enough, in addition to adding the product to the order, you additionally need to
- Create a shipment for it (or place it in an existing one)
- Create a payment for it (or change the first unpaid one, but a new one is better)
- recalculate the order (what if discounts appeared there)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question