-
Notifications
You must be signed in to change notification settings - Fork 9
PES-2144, PES-2167: New packet info page #86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DBelka
wants to merge
2
commits into
dev
Choose a base branch
from
PES-2144-magento-2-new-packet-info-page
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
Packetery/Checkout/Controller/Adminhtml/Packet/SaveDraft.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Packetery\Checkout\Controller\Adminhtml\Packet; | ||
|
|
||
| use Laminas\Http\Request; | ||
| use Magento\Backend\App\Action; | ||
| use Magento\Backend\App\Action\Context; | ||
| use Magento\Framework\App\Action\HttpPostActionInterface; | ||
| use Magento\Framework\Controller\Result\Redirect; | ||
| use Magento\Framework\Controller\ResultFactory; | ||
| use Magento\Framework\Exception\NotFoundException; | ||
| use Packetery\Checkout\Model\ResourceModel\Packetdraft\CollectionFactory; | ||
|
|
||
| class SaveDraft extends Action implements HttpPostActionInterface | ||
| { | ||
| public const ADMIN_RESOURCE = 'Packetery_Checkout::packetery'; | ||
|
|
||
| /** | ||
| * Save constructor. | ||
| * | ||
| * @param Context $context | ||
| * @param \Packetery\Checkout\Model\ResourceModel\PacketDraft\CollectionFactory $packetDraftCollectionFactory | ||
| */ | ||
| public function __construct( | ||
| Context $context, | ||
| private readonly CollectionFactory $packetDraftCollectionFactory | ||
| ) { | ||
| parent::__construct($context); | ||
| } | ||
|
|
||
| /** | ||
| * @return Redirect | ||
| * @throws \Exception | ||
| */ | ||
| public function execute(): Redirect | ||
| { | ||
| /** @var Request $request */ | ||
| $request = $this->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']); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Packetery\Checkout\Model; | ||
|
|
||
| class Packetdraft extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface | ||
| { | ||
| public const CACHE_TAG = 'packetery_checkout_packetdraft'; | ||
|
|
||
| protected $_cacheTag = self::CACHE_TAG; | ||
|
|
||
| protected $_eventPrefix = 'packetery_checkout_packetdraft'; | ||
|
|
||
| protected function _construct() | ||
| { | ||
| $this->_init(\Packetery\Checkout\Model\ResourceModel\Packetdraft::class); | ||
| } | ||
|
|
||
| public function getIdentities() | ||
| { | ||
| return [self::CACHE_TAG . '_' . $this->getId()]; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Packetery\Checkout\Model\ResourceModel; | ||
|
|
||
| class Packetdraft extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb | ||
| { | ||
| public function __construct( | ||
| \Magento\Framework\Model\ResourceModel\Db\Context $context | ||
| ) { | ||
| parent::__construct($context); | ||
| } | ||
|
|
||
| protected function _construct() | ||
| { | ||
| $this->_init('packetery_packet_draft', 'id'); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
Packetery/Checkout/Model/ResourceModel/Packetdraft/Collection.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Packetery\Checkout\Model\ResourceModel\Packetdraft; | ||
|
|
||
| class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection | ||
| { | ||
| protected $_idFieldName = 'id'; | ||
DBelka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| protected $_eventPrefix = 'packetery_checkout_packetdraft_collection'; | ||
|
|
||
| protected $_eventObject = 'packetdraft_collection'; | ||
|
|
||
| /** | ||
| * Define resource model | ||
| * | ||
| * @return void | ||
| */ | ||
| protected function _construct() | ||
| { | ||
| $this->_init('Packetery\Checkout\Model\Packetdraft', 'Packetery\Checkout\Model\ResourceModel\Packetdraft'); | ||
| } | ||
|
|
||
| /** | ||
| * @return \Packetery\Checkout\Model\Packetdraft[] | ||
| */ | ||
| public function getItems(): array | ||
| { | ||
| return parent::getItems(); | ||
| } | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
Packetery/Checkout/Model/ResourceModel/Packetdraft/CollectionFactory.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Packetery\Checkout\Model\ResourceModel\Packetdraft; | ||
|
|
||
| use Magento\Framework\ObjectManagerInterface; | ||
|
|
||
| class CollectionFactory | ||
| { | ||
| /** | ||
| * Instance name to create | ||
| * | ||
| * @var string | ||
| */ | ||
| protected string $instanceName; | ||
|
|
||
| /** | ||
| * Factory constructor | ||
| * | ||
| * @param ObjectManagerInterface $objectManager | ||
| * @param string $instanceName | ||
| */ | ||
| public function __construct( | ||
| protected ObjectManagerInterface $objectManager, | ||
| string $instanceName = Collection::class | ||
| ) { | ||
| $this->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(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Packetery\Checkout\Ui\Packetdraft; | ||
|
|
||
| use Magento\Ui\DataProvider\AbstractDataProvider; | ||
| use Magento\Sales\Model\ResourceModel\Order\CollectionFactory; | ||
| use Packetery\Checkout\Model\Order; | ||
|
|
||
| class DataProvider extends AbstractDataProvider | ||
| { | ||
| public function __construct( | ||
| $name, | ||
| $primaryFieldName, | ||
| $requestFieldName, | ||
| CollectionFactory $orderCollectionFactory, | ||
| private readonly \Packetery\Checkout\Model\ResourceModel\Order\CollectionFactory $orderFactory, | ||
| array $meta = [], | ||
| array $data = [] | ||
| ) { | ||
| $this->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; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.