diff --git a/Controller/Adminhtml/Orders/Delete.php b/Controller/Adminhtml/Orders/Delete.php index c522212..1bf4f24 100644 --- a/Controller/Adminhtml/Orders/Delete.php +++ b/Controller/Adminhtml/Orders/Delete.php @@ -33,7 +33,7 @@ class Delete extends Action private $orderLogRepository; /** - * Import constructor. + * Delete constructor. * @param Action\Context $context * @param Logger $logger * @param Filter $filter @@ -75,7 +75,10 @@ public function execute() $checkoutFormId = $item->getCheckoutFormId(); try { $this->orderLogRepository->deleteByCheckoutFormId($checkoutFormId); - $this->logger->info("Order log with id '{$checkoutFormId}' has been successfully deleted"); + $this->logger->info(__( + "Order log with checkout form ID: %1 has been successfully deleted", + $checkoutFormId + )); $this->messageManager->addSuccessMessage(__( "Order log with checkout form ID: %1 has been successfully deleted", $checkoutFormId diff --git a/Controller/Adminhtml/Reservations/Delete.php b/Controller/Adminhtml/Reservations/Delete.php new file mode 100644 index 0000000..e05ff2a --- /dev/null +++ b/Controller/Adminhtml/Reservations/Delete.php @@ -0,0 +1,103 @@ +logger = $logger; + $this->filter = $filter; + $this->collectionFactory = $collectionFactory; + $this->allegroReservation = $allegroReservation; + $this->checkoutFormRepository = $checkoutFormRepository; + } + + /** + * @return ResponseInterface|Redirect|ResultInterface + */ + public function execute() + { + $result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); + $result->setPath('*/*/'); + + try { + /** @var Collection $collection */ + $collection = $this->filter->getCollection($this->collectionFactory->create()); + } catch (LocalizedException $e) { + $this->messageManager->addExceptionMessage($e); + return $result; + } + /** @var Reservation $item */ + foreach ($collection as $item) { + $checkoutFormId = $item->getCheckoutFormId(); + $reservationId = $item->getReservationId(); + try { + $checkoutForm = $this->checkoutFormRepository->get($checkoutFormId); + $this->allegroReservation->compensateReservation($checkoutForm); + $this->logger->info(__("Reservation with ID: %1 has been successfully deleted", $reservationId)); + $this->messageManager->addSuccessMessage(__( + "Reservation with ID: %1 has been successfully deleted", + $reservationId + )); + } catch (\Exception $e) { + $this->logger->exception($e); + $this->messageManager->addErrorMessage(__( + "Something went wrong while trying to delete reservation with ID: %1", + $reservationId + )); + } + } + return $result; + } +} diff --git a/etc/di.xml b/etc/di.xml index 6152443..3f31f0a 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -130,4 +130,11 @@ + + + allegro_reservations + Macopedia\Allegro\Model\ResourceModel\Reservation + + + diff --git a/i18n/pl_PL.csv b/i18n/pl_PL.csv index b6c8e3d..713dbc8 100644 --- a/i18n/pl_PL.csv +++ b/i18n/pl_PL.csv @@ -146,7 +146,7 @@ "This is not a valid EAN number","To nie jest poprawny numer EAN" "Debug mode enabled", "Tryb debugowania włączony" "Order with checkout form ID: %1 has been successfully imported","Zamówienie od ID: %1 zostało pomyślnie zaimportowane" -"Something went wrong while trying to import order with checkout form ID: %1","Coś poszło nie tak podczas próby zaimportowania zamówienia o ID:" %1" +"Something went wrong while trying to import order with checkout form ID: %1","Coś poszło nie tak podczas próby zaimportowania zamówienia o ID: %1" "Orders with errors","Zamówienia z błędami" "Checkout form ID","ID zamówienia" "Date of first import try","Data pierwszej próby importu" @@ -163,3 +163,11 @@ "Reservation ID","ID rezerwacji" "Reservations enabled","Rezerwacje włączone" "Buyer login","Login kupującego" +"Delete reservations","Usuń rezerwacje" +"Delete orders","Usuń zamówienia" +"Are you sure to delete selected orders?","Jesteś pewien, że chcesz usunąć wybrane zamówienia?" +"Are you sure to delete selected reservations?","Jesteś pewien, że chcesz usunąć wybrane rezerwacje?" +"Something went wrong while trying to delete order log with checkout form ID: %1","Coś poszło nie tak podczas próby usunięcia zamówienia o ID: %1" +"Order log with checkout form ID: %1 has been successfully deleted","Zamówienie o ID: %1 zostało pomyślnie usunięte" +"Reservation with ID: %1 has been successfully deleted","Rezerwacja o ID: %1 została pomyślnie usunięta" +"Something went wrong while trying to delete reservation with ID: %1","Coś poszło nie tak podczas próby usunięcia rezerwacji o ID: %1" diff --git a/view/adminhtml/ui_component/allegro_reservations_listing.xml b/view/adminhtml/ui_component/allegro_reservations_listing.xml index 5cf888a..91f659e 100644 --- a/view/adminhtml/ui_component/allegro_reservations_listing.xml +++ b/view/adminhtml/ui_component/allegro_reservations_listing.xml @@ -33,9 +33,39 @@ + + + + Magento_Ui/js/grid/tree-massactions + entity_id + + + + + + delete + Delete + + + Delete reservations + Are you sure to delete selected reservations? + + + + + - + + + + false + 55 + entity_id + + + + textRange @@ -44,7 +74,7 @@ - + textRange @@ -53,7 +83,7 @@ - + text @@ -61,7 +91,7 @@ - + text @@ -69,7 +99,7 @@ - + Quantity