简体   繁体   English

修改POST请求以表示数量

[英]Modifying a POST request to denote quantity

I am currently working on allowing the administrator to choose the quantity to remove in the Orders -> Product page in the administrative backend, as shown here: 我目前正在努力允许管理员在管理后端的“ Orders -> Product页面中选择要删除的数量,如下所示:

在此处输入图片说明

The default behavior right now is that if you want to remove the product, the entire quantity is remove (with no way to select how many to remove). 现在的默认行为是,如果您要删除产品,则将删除全部数量(无法选择要删除的数量)。

Looking at the POST requests sent in the AJAX (when you press the red "remove" button) in /admin/view/template/sale/order_form.tpl , I noticed that the following code below, denoted as order_total is in charge of product removal (apologies for the incredibly long line of code - that's just how OpenCart's code convention is.. One big line). 查看/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);

As I saw within this hidden form request string, there is no way to define a key such as "quantity." 正如我在该隐藏的表单请求字符串中看到的那样,无法定义诸如“ quantity”之类的键。 In fact, I actually don't really have an idea on how it even removes an item, let alone the ability to modify the quantity. 实际上,我实际上并不了解如何删除物品,更不用说修改数量的能力了。 An example request string look like this: 一个示例请求字符串如下所示:

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

From my basic understanding, it seems to update the entire order total. 根据我的基本了解,它似乎可以更新整个订单总数。 Apologies for my ignorance.. I am totally new to JS/jQuery. 抱歉,我的无知..我是JS / jQuery的新手。

OK, here is what I found out when I opened the order_form.tpl - the deletion is done simply by removing a row from table (yes, in HTML words a <tr> is removed from <tbody> ) and saving the order (updating). 好的,这是我打开order_form.tpl时发现的-删除只需通过从表中删除一行即可完成(是的,用HTML词从<tbody>删除<tr> <tbody> )并保存顺序(更新)。 And because the whole table containing products is also a form (literaly, ie <form> ) full of hidden inputs it should be possible to change the quantity the very same way as is done on frontend in checkout/cart . 并且由于包含产品的整个表格也是充满隐藏输入的表格(字面意义,即<form> ),因此应该有可能以与checkout/cart前端相同的方式更改数量。

If I were you I'd add a spinner input instead of textual representation for quantity, because this column (quantity) goes like this: 如果您是我,我会添加一个微调输入而不是数量的文本表示,因为此列(数量)如下所示:

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

If you could change it for something like this: 如果您可以将其更改为以下内容:

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

(ie remove textual representation and change input hidden to input text) while optionally making the input as +/- (spinner) field, this could solve your problem. (即删除文本表示并更改隐藏为输入文本的输入),同时可以选择将输入设为+/-(旋转)字段,这可以解决您的问题。

Of course, in the end, you'd need to either click on Save or add also another small button next to the quantity input, something like 当然,最后,您需要单击“ 保存”或在数量输入旁边添加另一个小按钮,例如

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

This could work for you ;-) 这可能对您有用;-)

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

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