/** * @param $id * @return Main\Entity\DeleteResult * @throws Main\ArgumentException * @throws Main\ArgumentNullException */ public static function deleteWithItems($id) { $id = intval($id); if ($id <= 0) { throw new Main\ArgumentNullException("id"); } $itemsList = BasketPropertyTable::getList(array("filter" => array("BASKET_ID" => $id), "select" => array("ID"))); while ($item = $itemsList->fetch()) { BasketPropertyTable::delete($item["ID"]); } return BasketTable::delete($id); }
/** * */ public function save() { $result = new Sale\Result(); $itemsFromDb = array(); $itemsFromDbList = Internals\BasketPropertyTable::getList(array("filter" => array("BASKET_ID" => $this->getBasketItem()->getId()), "select" => array("ID"))); while ($itemsFromDbItem = $itemsFromDbList->fetch()) { $itemsFromDb[$itemsFromDbItem["ID"]] = true; } /** @var BasketPropertyItem $basketProperty */ foreach ($this->collection as $basketProperty) { $r = $basketProperty->save(); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } if (isset($itemsFromDb[$basketProperty->getId()])) { unset($itemsFromDb[$basketProperty->getId()]); } } foreach ($itemsFromDb as $k => $v) { Internals\BasketPropertyTable::delete($k); } return $result; }