33 'QUANTITY',
'BASKET_ID',
'STORE_ID',
34 'DATE_RESERVE',
'DATE_RESERVE_END',
'RESERVED_BY',
51 return Reservation\Internals\BasketReservationTable::getMap();
63 if (!$basketItem->isReservableItem())
72 if ($basketItem->getId() > 0)
74 $fields[
'BASKET_ID'] = $basketItem->getId();
77 $reservedItem = static::createEntityObject($fields);
89 private static function createEntityObject(array $fields = array())
92 $entityClassName = $registry->get(static::getRegistryEntity());
94 return new $entityClassName($fields);
105 public static function loadForBasketItem(
int $id)
118 $dbRes = $reserveCollection::getList([
124 while ($data = $dbRes->fetch())
126 $entityList[] = static::createEntityObject($data);
134 return (
float)$this->getField(
'QUANTITY');
139 return $this->setField(
'QUANTITY', $quantity);
144 return (
int)$this->getField(
'STORE_ID');
149 return $this->setField(
'STORE_ID', $storeId);
154 if ($name ===
'QUANTITY')
162 return $result->addError(
164 Main\Localization\
Loc::getMessage(
'SALE_RESERVE_QUANTITY_EXCEEDING_ERROR')
169 $result = Internals\Catalog\Provider::tryReserve($this);
170 if (!$result->isSuccess())
181 Main\Localization\
Loc::getMessage(
'SALE_RESERVE_QUANTITY_CHANGE_STORE_ERROR')
185 return parent::onFieldModify($name, $oldValue, $value);
194 if (isset($values[
'QUANTITY']))
196 $quantity = $values[
'QUANTITY'];
199 unset($values[
'QUANTITY']);
200 $values[
'QUANTITY'] = $quantity;
214 if (!$this->isChanged())
219 $id = $this->getId();
223 $fields = $this->getFields()->getChangedValues();
224 $r = $this->updateInternal($id, $fields);
228 if (!$this->getField(
'BASKET_ID'))
232 $fields[
'BASKET_ID'] = $basketItem->getId();
233 $this->setFieldNoDemand(
'BASKET_ID', $fields[
'BASKET_ID']);
236 if (!$this->getField(
'DATE_RESERVE_END'))
239 $defaultDateReserveEnd = (new \Bitrix\Main\Type\Date())->
add($reserveClearPeriod .
'D');
240 $this->setFieldNoDemand(
'DATE_RESERVE_END', $defaultDateReserveEnd);
243 $this->setFieldNoDemand(
'DATE_RESERVE',
new Main\
Type\
DateTime());
245 $fields = $this->getFields()->getValues();
247 $r = $this->addInternal($fields);
251 $this->setFieldNoDemand(
'ID', $id);
255 if (!$r->isSuccess())
257 $result->addErrors($r->getErrors());
265 public function delete()
268 if (!$result->isSuccess())
273 return parent::delete();
278 return parent::delete();
287 protected function updateInternal($primary, array $data)
290 $service = ServiceLocator::getInstance()->get(
'sale.basketReservation');
291 return $service->update($primary, $data);
299 protected function addInternal(array $data)
302 $service = ServiceLocator::getInstance()->get(
'sale.basketReservation');
303 return $service->add($data);
308 return 'SaleReservedQuantity';
static getMessage($code, $replace=null, $language=null)