gpt4 book ai didi

prestashop 1.7 新模块

转载 作者:行者123 更新时间:2023-12-05 07:38:48 24 4
gpt4 key购买 nike

我在 prestashop 1.7 中遇到问题,当我在我的模块中加载 form.tpl 时,我无法执行 setAction。我需要的是,当我继续付款时,我会使用支付平台进行新的销售,并在平台的 prestashop 中进行验证,我会留下代码。请帮忙

prestashop模块的主文件

         public function hookPaymentOptions($params) {

if (!$this->active) {
return;
}

$this->smarty->assign(
$this->getPaymentApiVars()
);

$apiPayement = new PaymentOption();
$apiPayement->setModuleName($this->name)
->setLogo($this->context->link->getBaseLink().'/modules/hhpayment/views/img/pago.jpg')
// ->setCallToActionText($this->l(''))
//Définition d'un formulaire personnalisé
->setForm($this->fetch('module:hhpayment/views/templates/hook/payment_api_form.tpl'))
->setAdditionalInformation($this->fetch('module:hhpayment/views/templates/hook/displayPaymentApi.tpl'))
->setAction($this->context->link->getModuleLink($this->name, 'validation', array(), true));


return [$apiPayement];
}

这是我在没有方法的情况下收取这个的form.tpl,但它是通过测试

<form action="{$payment_url}" target="_blank" >
<div class="form-group">
{* choix du mode de carte *}
{l s='please choose your card type' mod='hhpayment'}
<div class="radio">
<label>
<input type="radio" name="cb_type" value="mastercard" id="cb_type1" checked="checked" /> Pago internacional
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="cb_type" id="cb_type2" value="visa"/> Pago Nacional
</label>
</div>
</div>
{* Informations pour l'api *}
<input type="hidden" name="success_url" value="{$success_url}" />
<input type="hidden" name="error_url" value="{$error_url}" />
<input type="hidden" name="id_cart" value="{$id_cart}" />
<input type="hidden" name="cart_total" value="{$cart_total}" />
<input type="hidden" name="id_customer" value="{$id_customer}" />
</form>

这是验证文件

class hhpaymentvalidationModuleFrontController extends ModuleFrontController
{


/**
* Validation du paiement standard
* Puis redirection vers la page de succès de commande
*/
public function postProcess()
{
$cart = $this->context->cart;

$this->abrir("http://davivienda.com");


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');
}

$customer = new Customer($cart->id_customer);

if (!Validate::isLoadedObject($customer)) {
Tools::redirect('index.php?controller=order&step=1');
}

$currency = $this->context->currency;
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);

//La command passe directement en statut payé
$this->module->validateOrder((int)$cart->id, Configuration::get('PS_OS_PAYMENT'), $total, $this->module->displayName, null, array(), (int)$currency->id, false, $customer->secure_key);
Tools::redirect('index.php?controller=order-confirmation&id_cart='.(int)$cart->id.'&id_module='.(int)$this->module->id.'&id_order='.$this->module->currentOrder.'&key='.$customer->secure_key);
}

public function abrir($param)
{
echo" <script> window.open(URL,'ventana1,'width=300,height=300,scrollbars=NO')</script> ";


}

}

最佳答案

我找到了解决这个问题的方法,我不知道它是否正确,但它已经对我有用了:

postProcess 方法将其传递给主文件,validation.php 文件将其传递给主文件所在的同一文件夹。

然后是时候修改validation.php文件了,改到和main同级目录下,这个文件应该是这样的。

应该是导入

require_once dirname(__FILE__) . '/config/config.inc.php';
require_once dirname(__FILE__) . '/main.php';

然后为了避免内核错误,必须实现以下代码片段

global $kernel;
if(!$kernel){
require_once _PS_ROOT_DIR_.'/app/AppKernel.php';
$kernel = new \AppKernel('prod', false);
$kernel->boot();
}

在此之后,需要执行逻辑并通过get接收参数,支付完成后支付屏幕将返回给我们,一旦收到此数据,必须恢复购物车并将数据发送到迁移到主文件的函数

ob_start();
$context = Context::getContext();

if (is_null($context->cart)) {
$context->cart = new Cart($context->cookie->id_cart);
}
if (is_null($context->cart->id_currency)) {
$context->cart->id_currency = $context->cookie->id_currency;
}

$cart = $context->cart;
$customer = new Customer($cart->id_customer);
$currency = $cart->id_currency;
$total = (float)$cart->getOrderTotal(true, Cart::BOTH);
$object = new filemain();

$order = $object->methodCreateInMain($cart->id, Configuration::get('PS_OS_PAYMENT'), $total, $currency, $customer->secure_key);

基本上,validation.php 中的先前代码会检索购物车数据并将其通过参数发送到传递给 main 的函数,在该函数中将验证和创建订单。

需要注意的是支付后的返回url必须是ulrCommerce/module/validation.php

上面的方法对我来说非常有效,是基于查看的各种博客和论坛的解决方案

关于prestashop 1.7 新模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47589441/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com