diff --git a/Packetery/Checkout/Controller/Adminhtml/Packet/SaveDraft.php b/Packetery/Checkout/Controller/Adminhtml/Packet/SaveDraft.php
new file mode 100644
index 0000000..e89eff7
--- /dev/null
+++ b/Packetery/Checkout/Controller/Adminhtml/Packet/SaveDraft.php
@@ -0,0 +1,66 @@
+getRequest();
+ if (!$request->isPost()) {
+ throw new NotFoundException(__('Page not found'));
+ }
+
+ $postData = $request->getPost('general');
+ $data = [
+ 'order_id' => $postData['order_id'],
+ 'value' => $postData['order_value'] === '' ? null : $postData['order_value'],
+ 'cod' => $postData['cod_value'] === '' ? null : $postData['cod_value'],
+ 'weight' => $postData['weight'] === '' ? null : $postData['weight'],
+ 'length' => $postData['length'] === '' ? null : $postData['length'],
+ 'height' => $postData['height'] === '' ? null : $postData['height'],
+ 'width' => $postData['width'] === '' ? null : $postData['width'],
+ 'adult_content' => $postData['adult_content'] === '' ? null : $postData['adult_content'],
+ 'dispatch_at' => $postData['dispatch_at'] === '' ? null : $postData['dispatch_at'],
+ ];
+
+ $this->packetDraftCollectionFactory->saveData($data);
+
+ $this->messageManager->addSuccessMessage(
+ __('Saved')
+ );
+
+ return $this->resultFactory->create(ResultFactory::TYPE_REDIRECT)->setPath('sales/order/view/order_id/' . $postData['magento_order_id']);
+ }
+}
diff --git a/Packetery/Checkout/Model/Order.php b/Packetery/Checkout/Model/Order.php
index d1c49dc..e7c61f3 100755
--- a/Packetery/Checkout/Model/Order.php
+++ b/Packetery/Checkout/Model/Order.php
@@ -32,7 +32,7 @@ public function getDefaultValues()
*/
public function getPointId(): int
{
- return (int)$this->getData('point_id');
+ return $this->getData('point_id');
}
/**
@@ -40,23 +40,95 @@ public function getPointId(): int
*/
public function getPointName(): string
{
- return (string)$this->getData('point_name');
+ return $this->getData('point_name');
}
/**
- * @return string
+ * @return bool
*/
- public function getOrderNumber(): string
+ public function isAddressValidated(): bool
{
- return $this->getData('order_number');
+ return $this->getData('address_validated');
}
/**
- * @return bool
+ * @return int
*/
- public function isAddressValidated(): bool
+ public function getId(): int
+ {
+ return (int)parent::getId();
+ }
+
+ /**
+ * @return float|null
+ */
+ public function getCod(): ?float
+ {
+ return $this->getData('cod');
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getCurrency(): ?string
+ {
+ return $this->getData('currency');
+ }
+
+ /**
+ * @return float|null
+ */
+ public function getValue(): ?float
+ {
+ return $this->getData('value');
+ }
+
+ /**
+ * @return float|null
+ */
+ public function getWeight(): ?float
+ {
+ return $this->getData('weight');
+ }
+
+ /**
+ * @return bool|null
+ */
+ public function hasAdultContent(): ?bool
+ {
+ return $this->getData('adult_content');
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getPlannedDispatch(): ?string
+ {
+ return $this->getData('delayed_delivery');
+ }
+
+ /**
+ * @return int|null
+ */
+ public function getWidth(): ?int
+ {
+ return $this->getData('width');
+ }
+
+ /**
+ * @return int|null
+ */
+ public function getHeight(): ?int
+ {
+ return $this->getData('height');
+ }
+
+ /**
+ * @return int|null
+ */
+ public function getLength(): ?int
{
- return $this->getData('address_validated') === '1';
+ return $this->getData('depth');
}
/**
diff --git a/Packetery/Checkout/Model/Packetdraft.php b/Packetery/Checkout/Model/Packetdraft.php
new file mode 100755
index 0000000..8d76c31
--- /dev/null
+++ b/Packetery/Checkout/Model/Packetdraft.php
@@ -0,0 +1,24 @@
+_init(\Packetery\Checkout\Model\ResourceModel\Packetdraft::class);
+ }
+
+ public function getIdentities()
+ {
+ return [self::CACHE_TAG . '_' . $this->getId()];
+ }
+}
diff --git a/Packetery/Checkout/Model/ResourceModel/Packetdraft.php b/Packetery/Checkout/Model/ResourceModel/Packetdraft.php
new file mode 100755
index 0000000..a89f70b
--- /dev/null
+++ b/Packetery/Checkout/Model/ResourceModel/Packetdraft.php
@@ -0,0 +1,19 @@
+_init('packetery_packet_draft', 'id');
+ }
+}
diff --git a/Packetery/Checkout/Model/ResourceModel/Packetdraft/Collection.php b/Packetery/Checkout/Model/ResourceModel/Packetdraft/Collection.php
new file mode 100755
index 0000000..9e398f7
--- /dev/null
+++ b/Packetery/Checkout/Model/ResourceModel/Packetdraft/Collection.php
@@ -0,0 +1,32 @@
+_init('Packetery\Checkout\Model\Packetdraft', 'Packetery\Checkout\Model\ResourceModel\Packetdraft');
+ }
+
+ /**
+ * @return \Packetery\Checkout\Model\Packetdraft[]
+ */
+ public function getItems(): array
+ {
+ return parent::getItems();
+ }
+}
diff --git a/Packetery/Checkout/Model/ResourceModel/Packetdraft/CollectionFactory.php b/Packetery/Checkout/Model/ResourceModel/Packetdraft/CollectionFactory.php
new file mode 100644
index 0000000..3f4aeda
--- /dev/null
+++ b/Packetery/Checkout/Model/ResourceModel/Packetdraft/CollectionFactory.php
@@ -0,0 +1,74 @@
+instanceName = $instanceName;
+ }
+
+ /**
+ * Create class instance with specified parameters
+ *
+ * @param array $data Class constructor arguments to override auto-wiring or specify non-service arguments.
+ * @return Collection
+ */
+ public function create(array $data = []): Collection
+ {
+ /** @var Collection $collection */
+ $collection = $this->objectManager->create($this->instanceName, $data);
+
+ return $collection;
+ }
+
+ /**
+ * Creates a Collection specifically for inserting new entries into the DB
+ *
+ * @param array $data Class constructor arguments to override auto-wiring or specify non-service arguments.
+ * @return Collection
+ */
+ public function createForDbInsert(array $data = []): Collection
+ {
+ $collection = $this->create($data);
+ $collection->getSelect()->where('0');
+
+ return $collection;
+ }
+
+ /**
+ * Saves Packet Draft data to DB
+ *
+ * @throws \Exception
+ * @param array $data
+ */
+ public function saveData(array $data): void
+ {
+ $collection = $this->createForDbInsert();
+ $packetDraft = $collection->getNewEmptyItem();
+ $packetDraft->setData($data);
+ $collection->addItem($packetDraft);
+
+ $collection->save();
+ }
+}
diff --git a/Packetery/Checkout/Ui/Packetdraft/DataProvider.php b/Packetery/Checkout/Ui/Packetdraft/DataProvider.php
new file mode 100644
index 0000000..92056d1
--- /dev/null
+++ b/Packetery/Checkout/Ui/Packetdraft/DataProvider.php
@@ -0,0 +1,53 @@
+collection = $orderCollectionFactory->create();
+ parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
+ }
+
+ /**
+ * @return array
+ */
+ public function getData(): array
+ {
+ $result = [];
+ foreach ($this->collection->getItems() as $item) {
+ $orderNumber = $item->getDataByKey('increment_id');
+ /** @var Order $order */
+ $order = $this->orderFactory->create()->getItemByColumnValue('order_number', $orderNumber);
+
+ $result[$item->getId()]['general'] = [
+ 'magento_order_id' => $item->getDataByKey('entity_id'),
+ 'order_id' => $order->getId(),
+ 'order_value' => $order->getValue(),
+ 'cod_value' => $order->getCod(),
+ 'weight' => $order->getWeight(),
+ 'length' => $order->getLength(),
+ 'height' => $order->getHeight(),
+ 'width' => $order->getWidth(),
+ 'adult_content' => $order->hasAdultContent() ?? false,
+ 'dispatch_at' => $order->getPlannedDispatch(),
+ ];
+ }
+
+ return $result;
+ }
+}
diff --git a/Packetery/Checkout/view/adminhtml/layout/packetery_packet_add.xml b/Packetery/Checkout/view/adminhtml/layout/packetery_packet_add.xml
new file mode 100644
index 0000000..2eae1d5
--- /dev/null
+++ b/Packetery/Checkout/view/adminhtml/layout/packetery_packet_add.xml
@@ -0,0 +1,15 @@
+
+
+