How to remove delivery shipping step on prestashop 1.7?

故事扮演 提交于 2019-12-11 02:58:47

问题


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


回答1:


Simply comment out the following lines

->addStep(new CheckoutAddressesStep(
            $this->context,
            $translator,
            $this->makeAddressForm()
        ));

in /controllers/front/OrderController.php




回答2:


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();
    }
  }
}
  1. 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
  }
}
  1. Override Cart to have an always valid address

override/classes/Cart.php

class Cart extends CartCore {
  public function checkAndUpdateAddresses(){
    return true; // always valid
  }
}
  1. 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




回答3:


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



来源:https://stackoverflow.com/questions/47228469/how-to-remove-delivery-shipping-step-on-prestashop-1-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!