gpt4 book ai didi

javascript - 修改 POST 请求以表示数量

转载 作者:行者123 更新时间:2023-12-03 11:33:21 26 4
gpt4 key购买 nike

我目前正在努力允许管理员在管理后端的订单 -> 产品页面中选择要删除的数量,如下所示:

enter image description here

现在的默认行为是,如果您想删除产品,则整个数量都会被删除(无法选择要删除的数量)。

查看 /admin/view/template/sale/order_form.tpl 中 AJAX 发送的 POST 请求(当您按下红色的“删除”按钮时),我注意到以下代码下面,表示为 order_total 负责产品删除(对令人难以置信的长代码行表示歉意 - 这就是 OpenCart 的代码约定......一大行)。

for (i in json['order_total']) {
total = json['order_total'][i];

html += '<tr id="total-row' + total_row + '">';
html += ' <td class="right" colspan="4"><input type="hidden" name="order_total[' + total_row + '][order_total_id]" value="" /><input type="hidden" name="order_total[' + total_row + '][code]" value="' + total['code'] + '" /><input type="hidden" name="order_total[' + total_row + '][title]" value="' + total['title'] + '" /><input type="hidden" name="order_total[' + total_row + '][text]" value="' + total['text'] + '" /><input type="hidden" name="order_total[' + total_row + '][value]" value="' + total['value'] + '" /><input type="hidden" name="order_total[' + total_row + '][sort_order]" value="' + total['sort_order'] + '" />' + total['title'] + ':</td>';
html += ' <td class="right">' + total['value'] + '</td>';
html += '</tr>';

console.log(html + "\n");

total_row++;
}

$('#total').html(html);

正如我在这个隐藏的表单请求字符串中看到的那样,无法定义“数量”等键。事实上,我实际上并不知道它如何删除一个项目,更不用说修改数量的能力了。示例请求字符串如下所示:

<tr id="total-row0">  <td class="right" colspan="4"><input type="hidden" name="order_total[0][order_total_id]" value="" /><input type="hidden" name="order_total[0][code]" value="sub_total" /><input type="hidden" name="order_total[0][title]" value="Sub-Total" /><input type="hidden" name="order_total[0][text]" value="$0.00" /><input type="hidden" name="order_total[0][value]" value="0" /><input type="hidden" name="order_total[0][sort_order]" value="1" />Sub-Total:</td>  <td class="right">0</td></tr><tr id="total-row1">  <td class="right" colspan="4"><input type="hidden" name="order_total[1][order_total_id]" value="" /><input type="hidden" name="order_total[1][code]" value="total" /><input type="hidden" name="order_total[1][title]" value="Total" /><input type="hidden" name="order_total[1][text]" value="$0.00" /><input type="hidden" name="order_total[1][value]" value="0" /><input type="hidden" name="order_total[1][sort_order]" value="9" />Total:</td>  <td class="right">0</td></tr>

从我的基本理解来看,它似乎更新了整个订单总数。为我的无知道歉。我对 JS/jQuery 完全陌生。

最佳答案

好的,这是我打开 order_form.tpl 时发现的内容- 删除操作只需从表中删除一行(是的,在 HTML 中,从 <tr> 中删除 <tbody> )并保存订单(更新)。而且因为包含产品的整个表也是一个充满隐藏输入的表单(字面上,即 <form> ),所以应该可以以与 checkout/cart 中前端所做的相同方式更改数量。 .

如果我是你,我会添加一个旋转输入而不是数量的文本表示,因为此列(数量)如下所示:

<td class="right"><?php echo $order_product['quantity']; ?>
<input type="hidden" name="order_product[<?php echo $product_row; ?>][quantity]" value="<?php echo $order_product['quantity']; ?>" />
</td>

如果你可以将其更改为这样的内容:

<td class="right">
<input type="text" name="order_product[<?php echo $product_row; ?>][quantity]" value="<?php echo $order_product['quantity']; ?>" />
</td>

(即删除文本表示并将隐藏的输入更改为输入文本)同时可选择将输入设置为+/-(旋转器)字段,这可以解决您的问题。

当然,最后,您需要单击保存或在数量输入旁边添加另一个小按钮,例如

<td class="right">
<input type="text" name="order_product[<?php echo $product_row; ?>][quantity]" value="<?php echo $order_product['quantity']; ?>" />
<input type="image" src="view/image/update.png" alt="<?php echo $button_save; ?>" title="<?php echo $button_save; ?>" onclick="$('#button-update').trigger('click');" />
</td>

这可能对你有用;-)

关于javascript - 修改 POST 请求以表示数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26644621/

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