我有一个购物车,我想在购物车会话中更新它的数量。
这是我的购物车会话:
StateMachine<Status, Event> build(long orderId) {
orderService.getOrder(orderId) //returns Optional
.map(order -> {
StateMachine<Status, Event> sm = stateMachineFactory.getStateMachine(Long.toString(orderId));
sm.stop();
rehydrateState(sm, sm.getExtendedState, order.getStatus());
sm.start();
return sm;
})
.orElseGet(() -> createNewStateMachine(orderId);
}
void rehydrateState(StateMachine<Status, Event> newStateMachine, ExtendedState extendedState, Status orderStatus) {
newStateMachine.getStateMachineAccessor().doWithAllRegions(sma ->
sma.resetStateMachine(new DefaultStateMachineContext<>(orderStatus, null, null, extendedState));
});
}
所以我知道我需要一个foreach来更新购物车中的商品,但是当我这样做并将其发送回要求时,它只会放入商品的数量。
我想收到的是仅金额将被更新,并将整个更新后的数组发送回购物车。
我希望有人能帮助我。
答案 0 :(得分:0)
因此,假设您将购物车数组另存为$cartItems
,则可以执行以下操作:
foreach ($cartItems as $cartItem) {
$cartItem['amount'] = NEWAMOUNTVALUE;
}
如果您需要进一步的帮助,请在评论中进行说明!
答案 1 :(得分:0)
import base64
# This is and example of decoding your message['data']
coded_string = "dGVzdCBwdWIgbW9kZQ=="
base64.b64decode(coded_string) # b'test pub mode'
如果要将其存储在集合中并正确返回,则可以使用此代码。如果要直接编辑数组然后进行更新,可以使用@ party-ring中的上述代码,并在下面提供一些额外信息。
$cartItems = new Collection();
foreach ($items as $item) {
$cartItem = new CartItem();
$cartItem->amount = $item['amount'];
$cartItem->save();
$cartItems.push($cartItem);
}
return $cartItems;
答案 2 :(得分:0)
我自己找到了解决方案 我做了以下的事,并且奏效了。
$realPath = $this->fileDriver->getRealPath($path);