我想完全禁用结账订单流程中的地址步骤,因为我只销售数字产品,对了解客户地址不感兴趣
我按照Address.php、Cart.php和OrderController.php中的答案进行了覆盖,但我只得到一个空白页面
从 BO 创建一个地址,假设它的 id_address = 2
挂钩actionDispatcher以更新数据库中的购物车
并将你的模块挂接到actionDispatcher
模块/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();
}
}
}
覆盖/类/Address.php
class Address extends AddressCore {
public static function getFirstCustomerAddressId($id_customer, $active = true){
return 2; // hardcoded id_address
}
}
覆盖/classes/Cart.php
class Cart extends CartCore {
public function checkAndUpdateAddresses(){
return true; // always valid
}
}
覆盖/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()
// ))
}
}
这就是你需要做的,我在搞乱代码库很长时间后发现了它:
转到 checkout-process.tpl
替换这个:
{foreach from=$steps item="step" key="index"}
{render identifier = $step.identifier
position = ($index + 1)
ui = $step.ui
}
{/foreach}
与:
{foreach from=$steps item="step" key="index"}
{if $index != 2}
{if $index == 3}
{assign var="position" value=3}
{else}
{assign var="position" value=($index + 1)}
{/if}
{render identifier = $step.identifier
position = $position
ui = $step.ui
}
{/if}
{/foreach}
你的工作已经完成了!希望这有效 我的 prestashop 版本:8.1.6