public function saveOrderCoupons($coupon, $totalC, $orderId)
{
$app = Factory::getApplication();
$db = Factory::getDbo();
$d = array();
$d['order_id'] = (int) $orderId;
$d['coupon_id'] = (int) $coupon['id'];
$d['title'] = $coupon['title'];
if (isset($coupon['code'])) {
$d['code'] = $coupon['code'];
}
$d['amount'] = $totalC['dnetto'];
// get the value from total
$d['netto'] = $totalC['dnetto'];
$d['brutto'] = $totalC['dbrutto'];
$row = Table::getInstance('PhocacartOrderCoupons', 'Table', array());
if (!$row->bind($d)) {
//throw new Exception($row->getError());
$msg = Text::_($row->getError());
$app->enqueueMessage($msg, 'error');
return false;
}
if (!$row->check()) {
//throw new Exception($row->getError());
$msg = Text::_($row->getErrorMsg());
$app->enqueueMessage($msg, 'error');
return false;
}
if (!$row->store()) {
//throw new Exception($row->getError());
$msg = Text::_($row->getErrorMsg());
$app->enqueueMessage($msg, 'error');
return false;
}
return true;
}