简体   繁体   English

销售点系统

[英]Point of Sale System

I am developing an web-based Point-of-Sale system for a client.我正在为客户开发基于 Web 的销售点系统。 The system is nearly finished but I am experiencing a couple of small issues.系统即将完成,但我遇到了一些小问题。

The order items are stored in a array, which is stored in a session variable, which looks like this:订单项存储在一个数组中,该数组存储在会话变量中,如下所示:

[items] => Array
    (
        [0] => Array
            (
                [id] => 15
            )

        [2] => Array
            (
                [id] => 16
            )

        [3] => Array
            (
                [id] => 15
            )

        [4] => Array
            (
                [id] => 16
            )

    )

This code displays the items:此代码显示项目:

Note: For each ID in the $items variable I do a lookup in the database to extract addition information about that item.注意:对于 $items 变量中的每个 ID,我都会在数据库中进行查找以提取有关该项目的附加信息。

  foreach($items as $item) {
    $cc++;
    $id = $item['id'];
    $item_db = $db->query("SELECT * FROM inventory WHERE id='$id' LIMIT 1")->fetch_array();
    $subtotal += $item_db['price'];

    $quantity = 1;

    if(!empty($item_db['name'])) {
    ?>
    <tr style="visibility: hidden">
    <td> <a href="?deleteItem=<?=$cc?>" style="color:#000"><i class="fa fa-trash"></i></a> </td>
    <td> <?=$item_db['name']?> </td>
    <td> <?=$quantity?> </td>
    <td> <?=$currency?><?=round($item_db['price'],2)?> </td>
    </tr>
    <?
    }
    }
    ?>

How would I group the items so instead of displaying the same item multiple times with quantity of 1, group the entries and display the total quantity of all entries (which are the same)?我将如何对项目进行分组,而不是多次显示数量为 1 的同一项目,而是将条目分组并显示所有条目的总数(相同)?

For example, instead of:例如,而不是:

Laptop 1
Laptop 1

I want to display:我想显示:

Laptop 2
  • First create an array to hold the results of counting the ids.首先创建一个数组来保存对 id 进行计数的结果。
  • Then loop over items, with each array get the value of the subarray id.然后循环遍历项目,每个数组获取子数组 id 的值。
    • If the counter array does not have that id as a key, add it with id as key and value 1.如果计数器数组没有该 id 作为键,则将其添加为 id 作为键,值为 1。
    • If the counter array does have that id as key, increase the value of that id with 1.如果计数器数组确实将该 id 作为键,则将该 id 的值增加 1。

Now you have the id of products as keys with the count of products as value.现在您将产品的 id 作为键,将产品的数量作为值。

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

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