DataManager not committing

Hi I am quite new to the platform and I was wondering why does the code below work

for(OrderProduct op : productList){
        Product product = op.getProduct();
        Integer amount = op.getAmount();

        product.setAvailable(product.getAvailable() + amount);
        product.setTotal(product.getTotal() + amount);
        dataManager.commit(product);
}

while this doesn’t work and no error is raised

for(OrderProduct op : productList){
        Product product = op.getProduct();
        Integer amount = op.getAmount();
        
        OrderProduct o = dataManager.load(OrderProduct.class)
                .query("select e from salesman$OrderProduct e where e.id = :Id")
                .parameter("Id", op.getId()).one();
        if(o != null) {
            amount = op.getAmount() - o.getAmount();
        }

        product.setAvailable(product.getAvailable() + amount);
        product.setTotal(product.getTotal() + amount);
        dataManager.commit(product);
}

My goal is to update the product amount on the insertion of a new order and in the case of updating the amounts of products in an order update the product amount accordingly

No worries I figured it out was making the call in postCommit which meant the value for amount is always 0.