/** * @return array */ public static function getAllFields() { static $fields = null; if ($fields == null) { $fields = array_keys(ShipmentItemStoreTable::getMap()); } return $fields; }
/** * @param $id * @return Main\Entity\DeleteResult * @throws Main\ArgumentException */ public static function deleteWithItems($id) { $id = intval($id); if ($id <= 0) { throw new Main\ArgumentNullException("id"); } $itemsFromDbList = ShipmentItemStoreTable::getList(array("filter" => array('ORDER_DELIVERY_BASKET_ID' => $id), "select" => array("ID"))); while ($itemsFromDbItem = $itemsFromDbList->fetch()) { ShipmentItemStoreTable::delete($itemsFromDbItem['ID']); } return ShipmentItemTable::delete($id); }
/** * @return array */ public static function getAllFields() { static $fields = null; if ($fields == null) { $map = ShipmentItemStoreTable::getMap(); foreach ($map as $key => $value) { if (is_array($value)) { $fields[] = $key; } elseif ($value instanceof Main\Entity\ScalarField) { $fields[] = $value->getName(); } } } return $fields; }
/** * @return Main\Entity\AddResult|Main\Entity\UpdateResult * @throws Main\ArgumentNullException * @throws Main\ArgumentOutOfRangeException * @throws \Exception */ public function save() { global $USER; $result = new Result(); $id = $this->getId(); $fields = $this->fields->getValues(); /** @var ShipmentItemStoreCollection $collection */ $collection = $this->getCollection(); /** @var Result $r */ $r = $collection->checkAvailableQuantity($this); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } /** @var BasketItem $basketItem */ $basketItem = $this->getBasketItem(); if ($id > 0) { $fields = $this->fields->getChangedValues(); if (!empty($fields) && is_array($fields)) { if (isset($fields["QUANTITY"]) && floatval($fields["QUANTITY"]) <= 0) { throw new Main\ArgumentNullException('quantity'); } $fields['DATE_MODIFY'] = new Main\Type\DateTime(); $fields['MODIFIED_BY'] = $USER->GetID(); $r = Internals\ShipmentItemStoreTable::update($id, $fields); if (!$r->isSuccess()) { return $r; } } $result = new Main\Entity\UpdateResult(); } else { if (!isset($fields["ORDER_DELIVERY_BASKET_ID"])) { $fields['ORDER_DELIVERY_BASKET_ID'] = $this->getParentShipmentItemId(); } if (!isset($fields["BASKET_ID"])) { $fields['BASKET_ID'] = $basketItem->getId(); } $fields['DATE_CREATE'] = new Main\Type\DateTime(); if (!isset($fields["QUANTITY"]) || floatval($fields["QUANTITY"]) == 0) { return new Main\Entity\AddResult(); } if ($basketItem->isBarcodeMulti() && isset($fields['BARCODE']) && strval(trim($fields['BARCODE'])) == "") { $result->addError(new ResultError(Loc::getMessage('SHIPMENT_ITEM_STORE_BARCODE_MULTI_EMPTY', array('#PRODUCT_NAME#' => $basketItem->getField('NAME'), '#STORE_ID#' => $fields['STORE_ID'])), 'SHIPMENT_ITEM_STORE_BARCODE_MULTI_EMPTY')); return $result; } $r = Internals\ShipmentItemStoreTable::add($fields); if (!$r->isSuccess()) { return $r; } $id = $r->getId(); $this->setFieldNoDemand('ID', $id); $result = new Main\Entity\AddResult(); } return $result; }
/** * @return Main\Entity\Result */ public function save() { $result = new Main\Entity\Result(); $oldBarcodeList = array(); $itemsFromDb = array(); if ($this->getShipmentItem() && $this->getShipmentItem()->getId() > 0) { $itemsFromDbList = Internals\ShipmentItemStoreTable::getList(array("filter" => array("ORDER_DELIVERY_BASKET_ID" => $this->getShipmentItem()->getId()), "select" => array("*"))); while ($itemsFromDbItem = $itemsFromDbList->fetch()) { $itemsFromDb[$itemsFromDbItem["ID"]] = true; } } /** @var ShipmentItemStore $shipmentItemStore */ foreach ($this->collection as $shipmentItemStore) { $r = $shipmentItemStore->save(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } if (isset($itemsFromDb[$shipmentItemStore->getId()])) { unset($itemsFromDb[$shipmentItemStore->getId()]); } } foreach ($itemsFromDb as $k => $v) { Internals\ShipmentItemStoreTable::delete($k); } return $result; }