M
M
Maxim2020-09-14 18:11:46
1C-Bitrix
Maxim, 2020-09-14 18:11:46

How to make all items in stock?

Good afternoon.
I got an online store on Bitrix with 4000 products, all products are "out of stock",
In the product settings - trade catalog - Allow purchase in the absence of goods (including allowing a negative quantity of goods): NO.
How can I bulk-enable all items to "in stock" and allow a purchase with a negative quantity?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PetrPo, 2020-09-15
@ikfah012

Something like this, you can make a better request, but it will do for once - this code will set the default value

\Bitrix\Main\Loader::includeModule('iblock');
\Bitrix\Main\Loader::includeModule('catalog');

$iblocksId = [2, 3];

$iterator = \Bitrix\Iblock\ElementTable::getList([
  'select' => ['IBLOCK_ID', 'ID'],
  'filter' => ['IBLOCK_ID' => $iblocksId, '!PRODUCT.CAN_BUY_ZERO' => 'D', '!PRODUCT.TYPE' => \Bitrix\Catalog\ProductTable::TYPE_SKU],
  'runtime' => [
    'PRODUCT' => [
      'data_type' => '\Bitrix\Catalog\ProductTable',
      'reference' => ['=this.ID' => 'ref.ID']
    ]
  ]
]);

$elements = [];
while($row = $iterator->fetch()) {
  $elements[] = $row;
}

foreach($elements as $element) {
  CCatalogProduct::Update($element['ID'], ['CAN_BUY_ZERO' => 'D']);	
}

echo 'Количество = '.count($elements);

$iblocksId - id-shnik infoblocks Catalog and Trade offers, if there are no trade offers, specify only the catalog ID
Then in the answers there the person threw off the screen, set the default settings
In the catalog component, PRICE_CODE must be specified

I
Ilya, 2020-09-14
@rpsv

In the module settings, the trade catalog: https://i.imgur.com/WzPgTi6.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question