You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
896 B
C++
38 lines
896 B
C++
#include "shopservice.h"
|
|
|
|
ShopService::ShopService()
|
|
{
|
|
|
|
}
|
|
|
|
QSharedPointer<Voucher> ShopService::createVoucher()
|
|
{
|
|
QSharedPointer<Voucher> voucher(new Voucher);
|
|
voucher->setStatus(Voucher::NEW);
|
|
return voucher;
|
|
}
|
|
|
|
void ShopService::addShopItem(QSharedPointer<Voucher> voucher, QSharedPointer<IShopItem> item, int count)
|
|
{
|
|
QSharedPointer<VoucherItem> vItem(new VoucherItem);
|
|
vItem->setName(item->name());
|
|
vItem->setUnitPrice(item->unitPrice());
|
|
vItem->setCount(count);
|
|
vItem->setRefId(item->id());
|
|
vItem->setItemPlugin(item->pluginId());
|
|
|
|
voucher->addItem(vItem);
|
|
}
|
|
|
|
void ShopService::calculate(QSharedPointer<Voucher> voucher)
|
|
{
|
|
QDecDouble total;
|
|
|
|
foreach (QSharedPointer<VoucherItem> item, voucher->items()) {
|
|
QDecDouble itemPrice = item->unitPrice() * item->count();
|
|
total += itemPrice;
|
|
}
|
|
|
|
voucher->setTotalPrice(total);
|
|
}
|