繁体   English   中英

修改POST请求以表示数量

[英]Modifying a POST request to denote quantity

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

在此处输入图片说明

现在的默认行为是,如果您要删除产品,则将删除全部数量(无法选择要删除的数量)。

查看/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);

正如我在该隐藏的表单请求字符串中看到的那样,无法定义诸如“ quantity”之类的键。 实际上,我实际上并不了解如何删除物品,更不用说修改数量的能力了。 一个示例请求字符串如下所示:

<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词从<tbody>删除<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>

这可能对您有用;-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM