35 public static function load($id)
43 $archivedOrder = Internals\OrderArchiveTable::getList(
45 "select" => array(
"*",
"ORDER_FULL" =>
"ORDER_PACKED.ORDER_DATA"),
46 "filter" => array(
"=ID" => $id),
50 $orderFields = $archivedOrder->fetch();
55 $restorer =
new self($id);
56 if (!$restorer->checkVersion($orderFields[
'VERSION']))
61 $restorer->version = (int)$orderFields[
'VERSION'];
62 $restorer->dateArchived = $orderFields[
'DATE_ARCHIVED'];
63 $builder = $restorer->loadBuilder();
64 $builder->setPackedOrder($restorer->packField($orderFields[
'ORDER_FULL']));
65 $orderFields[
'ID'] = $orderFields[
'ORDER_ID'];
66 $archiveFields = [
'ORDER_DATA',
'ORDER_FULL',
'ORDER_ID',
'VERSION',
'DATE_ARCHIVED'];
67 foreach ($archiveFields as $fieldName)
69 unset($orderFields[$fieldName]);
72 $builder->setEntityFields(
'ORDER', $orderFields);
74 $basketArchivedItems = Internals\BasketArchiveTable::getList(
76 "select" => array(
"*",
"BASKET_FULL" =>
"BASKET_PACKED.BASKET_DATA"),
77 "filter" => array(
"ARCHIVE_ID" => $id)
82 while ($item = $basketArchivedItems->fetch())
84 $builder->addPackedBasketItem(
86 $restorer->packField($item[
'BASKET_FULL'])
88 unset($item[
'BASKET_DATA'], $item[
'BASKET_FULL'], $item[
'ARCHIVE_ID']);
89 $basketItems[$item[
'ID']] = $item;
91 $builder->setEntityFields(
'BASKET', $basketItems);
92 $restorer->setBuilder($builder);
175 $eventManager = Main\EventManager::getInstance();
176 if ($eventsList = $eventManager->findEventHandlers(
'sale', self::EVENT_ON_ARCHIVE_ORDER_BEFORE_RESTORED))
178 $event =
new Main\Event(
'sale', self::EVENT_ON_ARCHIVE_ORDER_BEFORE_RESTORED, array(
184 $archivedOrder = $this->builder->buildOrder();
185 $archivedOrder->setVersion($this->version);
186 $archivedOrder->setDateArchived($this->dateArchived);
187 return $archivedOrder;