Reputation: 437
In reference to: How to remove delivery shipping step on prestashop 1.6.1?
I am looking for a solution for Prestashop v1.7.2.4, any ideas?
I tried to comment some code lines but it created extra problem like not submitting the order
Upvotes: 3
Views: 10030
Reputation: 214
On prestashop 1.7.* I managed to disable (make disappear) the whole delivery step. In my scenario, the business model for my customer is Cash on delivery.
To achieve that I commented it out in the source code.
in the file
controllers/front/OrderController.php
comment out checkoutDeliveryStep
Upvotes: 1
Reputation: 356
I managed to hide Address step by assigning all orders to a single Address and removing the Address step from checkout process. Let's say you have an address with id = 2, using code below, all orders will be created with this address.
1. Create an address from BO, let's say it has id_address
= 2
2. Hook actionDispatcher to update our cart in database
and hook your module to actionDispatcher
modules/yourmodule/yourmodule.php
<?php
public function hookActionDispatcher($params = []){
// every time we go to a payment controller, we update current cart id_addresses to 2
$payments_controllers = [
'ps_wirepaymentvalidationModuleFrontController',
'ps_checkpaymentvalidationModuleFrontController',
];
if($params['controller_type'] == Dispatcher::FC_FRONT &&
in_array($params['controller_class'], $payments_controllers) &&
$params['is_module']){
$cart = new Cart($this->context->cookie->id_cart);
if($cart->id_address_delivery == 0 || $cart->id_address_invoice){
$cart->id_address_delivery = 2;
$cart->id_address_invoice = 2;
$cart->update();
}
}
}
3. Override Address with hardcoded id_address
override/classes/Address.php
class Address extends AddressCore {
public static function getFirstCustomerAddressId($id_customer, $active = true){
return 2; // hardcoded id_address
}
}
4. Override Cart to have an always valid address
override/classes/Cart.php
class Cart extends CartCore {
public function checkAndUpdateAddresses(){
return true; // always valid
}
}
5. Override OrderController to remove Adress step from checkout
override/controllers/front/OrderController.php
class OrderController extends OrderControllerCore {
protected function bootstrap(){
// copy everything from https://github.com/PrestaShop/PrestaShop/blob/1.7.2.x/controllers/front/OrderController.php#L90
// but comment those lines:
// ->addStep(new CheckoutAddressesStep(
// $this->context,
// $translator,
// $this->makeAddressForm()
// ))
}
}
Address step is now hidden from the front office :
If you only do step 5, you will be redirected to checkout?step=1
because ps_wirepayment do a check on cart->id_address
at validation:
modules/ps_wirepayment/controllers/front/validation.php
if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->module->active){
Tools::redirect('index.php?controller=order&step=1');
}
Cheers,
Florian
Upvotes: 3
Reputation: 11
Simply comment out the following lines
->addStep(new CheckoutAddressesStep(
$this->context,
$translator,
$this->makeAddressForm()
));
in /controllers/front/OrderController.php
Upvotes: 1