mr_david Posted October 28, 2021 Share Posted October 28, 2021 (edited) Hi all, I'm trying to make a refund base on the docs provided for prestashop 1.7.7. $command = new IssuePartialRefundCommand ( $orderId, $refund_information['refund_items'], $refund_information['shipping_amount'], (bool)$refund_information['restock'], (bool)$refund_information['credit_slip'], (bool)$refund_information['voucher'], (int)$refund_information['voucher_refund_type'], ); $commandBus = $this->get('prestashop.core.command_bus'); $commandBus->handle($command); But I does not work, it seems that $commandBus is null. Is there anything more I have to configure to load the command_bus ? Edited October 28, 2021 by mr_david (see edit history) Link to comment Share on other sites More sharing options...
edwinaquino15 Posted November 17, 2021 Share Posted November 17, 2021 Could you find a solution? I have the same problem and I don't know how to fix it Link to comment Share on other sites More sharing options...
Janett Posted November 18, 2021 Share Posted November 18, 2021 Where did you call it ? Because there are 3 service containers on PrestaShop : BO Symfony (with CommandBus) only available on Symfony based controllers BO Legacy (no CommandBus) available on all old controllers (module configuration page & ModuleAdminController) FO (no CommandBus) (FrontController or ModuleFrontController) So you can only use it in a Symfony controller Link to comment Share on other sites More sharing options...
edwinaquino15 Posted November 18, 2021 Share Posted November 18, 2021 In my case my file is in the directory of my module (controllers/admin/refunds.php), and that file is like this <?php include('../../../../config/config.inc.php'); include('../../../../init.php'); use PrestaShop\PrestaShop\Core\CommandBus\CommandBusInterface; use PrestaShop\PrestaShop\Core\Domain\Order\Command\IssueStandardRefundCommand; class Refunds extends Module { public function createRefundTotal() { $order = new Order($_GET['order_id']); $order_details = OrderDetail::getList((int)$_GET['order_id']); $refunds = []; $refundShippingCost = ($_POST['shipping'] == 'true') ? true : false; $orderId = $_GET['order_id']; $generateCreditSlip = true; $generateVoucher = true; $voucherRefundType = '1'; for ($i = 0; $i < count($order_details); $i++) { $quantity = $order_details[$i]['product_quantity'] - $order_details[$i]['product_quantity_refunded']; if($quantity > 0) { $refunds[(int)$order_details[$i]['id_order_detail']] = [ 'quantity' => (int)$quantity ]; } } $command = new IssueStandardRefundCommand( $orderId, $refunds, $refundShippingCost, $generateCreditSlip, $generateVoucher, $voucherRefundType ); $this->commandBus->handle($command); } } This way it doesn't work and it gives me the following error Notice: Undefined property: Refunds::$commandBus Obviously the error is because the commandBus does not exist, but how can I use it ?, or if there is another way to generate the return of the order Link to comment Share on other sites More sharing options...
Janett Posted November 19, 2021 Share Posted November 19, 2021 You should create a Symfony admin controller on your module to use Symfony container and retrieves CommandBus https://github.com/PrestaShop/example-modules Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now