修改POST请求以表示数量

时间:2014-10-30 03:35:11

标签: javascript jquery ajax opencart

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

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

正如我在这个隐藏的表单请求字符串中看到的那样,无法定义诸如“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完全不熟悉。

1 个答案:

答案 0 :(得分:1)

好的,这是我在打开order_form.tpl时发现的内容 - 只需从表中删除一行即可完成删除(是的,在HTML格式中,<tr>已从{{1}中删除并保存订单(更新)。并且因为包含产品的整个表格也是一个充满隐藏输入的表格(文字,即<tbody>),所以应该可以像<form>中的前端一样改变数量。 / p>

如果我是你,我会添加一个微调器输入而不是数量的文本表示,因为这个列(数量)是这样的:

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>

这可能对你有用; - )

相关问题