A
A
Airslip2017-03-24 14:47:55
1C-Bitrix
Airslip, 2017-03-24 14:47:55

How do I add a deactivated item to the cart?

People, help. Add items to cart using the following code:

if(!empty($_POST['ADD'])) {
    $itemID = intval($_POST['ADD']);
    CModule::IncludeModule("sale");
    CModule::IncludeModule("catalog");
    $count = 1;
    if(!empty($_POST['QUANTITY'])) {
        $count = $_POST['QUANTITY'];
    }
    Add2BasketByProductID($itemID, $count);
    echo json_encode(array(0=>$itemID));
}

Everything works, but the problem is that if the product is deactivated in the infoblock, then the addition does not work. Another problem is that if an active item added to the cart is deactivated, then it disappears from the cart. How can this be fixed? In general, the essence is that deactivated products should always be added to the basket and displayed in it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey, 2017-03-24
@flx12

callback is triggered, you need to pass Add2BasketByProductID 3 as a parameter

$arRewriteFields = array(
  'CALLBACK_FUNC'        => '',
  'ORDER_CALLBACK_FUNC'    => '',
  'CANCEL_CALLBACK_FUNC'     => '',
  'PAY_CALLBACK_FUNC'     => '',
  'PRODUCT_PROVIDER_CLASS'  => '',
);

but with this layout, the price in the basket and checking the balances in the admin panel will not be recalculated, if the parameters in the card have changed
or another option, write your own class that inherits from PRODUCT_PROVIDER_CLASS ( https://dev.1c-bitrix.ru/api_help/catalog/ classes/... and specify it in $arRewriteFields['PRODUCT_PROVIDER_CLASS']

A
Airslip, 2017-03-24
@Airslip

I inserted the 3rd parameter and no more product wants to be added to the cart.

if(!empty($_POST['ADD'])) {
    $itemID = intval($_POST['ADD']);
    CModule::IncludeModule("sale");
    CModule::IncludeModule("catalog");
    $count = 1;
    if(!empty($_POST['QUANTITY'])) {
        $count = $_POST['QUANTITY'];
    }
  $arRewriteFields = array(
    'CALLBACK_FUNC'        => '',
    'ORDER_CALLBACK_FUNC'    => '',
    'CANCEL_CALLBACK_FUNC'     => '',
    'PAY_CALLBACK_FUNC'     => '',
    'PRODUCT_PROVIDER_CLASS'  => '',
  );
    Add2BasketByProductID($itemID, $count, $arRewriteFields);
    echo json_encode(array(0=>$itemID));
}

E
Eugene, 2018-04-09
@kutepovea

I don’t know how relevant the answer is, but I’ll give you more advice - internal manipulations should not break the Bitrix mechanisms.
If you need to hide a product out of sight but leave the ability to add to the cart, then create a filter with some product property in the $arrFilter global variable in init.php.
Activity is used in a large number of mechanisms. And besides, your approach complicates the further support of the site.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question