Skip to content

Adding sub items qty's increase the wrong item #65

Description

@lukepolo

add x1 (shows qty_x = 1)
add x1 with sub y1 (shows qty_xy = 1)
add x1 with sub y1 again and all of a sudden qty_x = 2
qty_xy should = 2

The solution would be to change the qty of x1. And re-add x2 as a new item with the sub item (which is no problem). The problem is x2 is no longer x2. For instance

    $x1 = $this->addItem();
    // $x2 is really just $x1 now since we increased the qty to 2
    $x2 = $this->addItem();
    // $x2 is now with the sub item
    $x2->addSubItem([
        'size' => 'XXL',
        'price' => 2.50
    ]);
    // and $x2 should be its own item but its attached to x1

The TEST :

public function testSubItemQtys()
{
    $item_1 = $this->addItem();

    $item_2 = $this->addItem();

    $subItem = $item_2->addSubItem([
        'size' => 'XXL',
        'price' => 2.50
    ]);

    $this->assertEquals(1, $item_1->qty);
    $this->assertEquals(1, $item_2->qty);

    $item_3 = $this->addItem();

    $subItem = $item_3->addSubItem([
        'size' => 'XXL',
        'price' => 2.50
    ]);

    $this->assertEquals(1, $item_2->qty);
    $this->assertEquals(2, $item_2->qty);
}

This test fails because of these issues.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions