<?php
function updateItems()
{
foreach (\Components\Commerce\Carts\Current::getAll() as $iRow => $arrCartItem)
{
$iQty = false;
$iContactId = false;
$arrOrderOptions = false;
if (isset($_POST['product_quantity_' . $iRow]))
{
$iQty = $_POST['product_quantity_' . $iRow];
}
if (isset($_POST['product_order_options_' . $iRow]))
{
$arrOrderOptions = \Components\Commerce\Carts\Current::convertPostedProductOptionsToAssoc(\Components\Commerce\Carts\Current::getRowProductId($iRow), $_POST['product_order_options_' . $iRow]);
}
if (isset($_POST['bought_for_contact_id_' . $iRow]) && $_POST['bought_for_contact_id_' . $iRow] != 'someone else')
{
$iContactId = $_POST['bought_for_contact_id_' . $iRow];
}
\Components\Commerce\Carts\Current::updateRow($iRow, $iQty, $arrOrderOptions, $iContactId);
}
}
updateItems();
function handleChangeContactForRow($iRowId, $iContactId)
{
// Nullify if empty
if (!$iContactId)
{
$iContactId = null;
}
\Components\Commerce\Carts\Current::updateRow($iRowId, false, false, $iContactId);
}
function applyDiscount($pDiscountCode, $pValidationLabel, $bThrow)
{
try
{
\Components\Commerce\Discounts::activateCodeDiscountWithCode($pDiscountCode->getValue());
$pDiscountCode->setValueIgnore('ajax');
} catch (\Framework\Exceptions\Validation $pException)
{
$pValidationLabel->setValue('<small>' . $pException->getTitle() . '</small><br />');
if ($bThrow)
{
throw $pException;
}
}
}
function applyDiscountOnSubmit($pDiscountCode, $pValidationLabel)
{
if ($pDiscountCode && $pDiscountCode->getValue())
{
try
{
applyDiscount($pDiscountCode, $pValidationLabel, true);
} catch (\Framework\Exceptions\Validation $pException)
{
$pDiscountCode->setValueIgnore('client');
throw $pException;
}
}
}
?>
<?php
function updateItems()
{
foreach (\Components\Commerce\Carts\Current::getAll() as $iRow => $arrCartItem)
{
$iQty = false;
$iContactId = false;
$arrOrderOptions = false;
if (isset($_POST['product_quantity_' . $iRow]))
{
$iQty = $_POST['product_quantity_' . $iRow];
}
if (isset($_POST['product_order_options_' . $iRow]))
{
$arrOrderOptions = \Components\Commerce\Carts\Current::convertPostedProductOptionsToAssoc(\Components\Commerce\Carts\Current::getRowProductId($iRow), $_POST['product_order_options_' . $iRow]);
}
if (isset($_POST['bought_for_contact_id_' . $iRow]) && $_POST['bought_for_contact_id_' . $iRow] != 'someone else')
{
$iContactId = $_POST['bought_for_contact_id_' . $iRow];
}
\Components\Commerce\Carts\Current::updateRow($iRow, $iQty, $arrOrderOptions, $iContactId);
}
}
updateItems();
function handleChangeContactForRow($iRowId, $iContactId)
{
// Nullify if empty
if (!$iContactId)
{
$iContactId = null;
}
\Components\Commerce\Carts\Current::updateRow($iRowId, false, false, $iContactId);
}
function applyDiscount($pDiscountCode, $pValidationLabel, $bThrow)
{
try
{
\Components\Commerce\Discounts::activateCodeDiscountWithCode($pDiscountCode->getValue());
$pDiscountCode->setValueIgnore('ajax');
} catch (\Framework\Exceptions\Validation $pException)
{
$pValidationLabel->setValue('<small>' . $pException->getTitle() . '</small><br />');
if ($bThrow)
{
throw $pException;
}
}
}
function applyDiscountOnSubmit($pDiscountCode, $pValidationLabel)
{
if ($pDiscountCode && $pDiscountCode->getValue())
{
try
{
applyDiscount($pDiscountCode, $pValidationLabel, true);
} catch (\Framework\Exceptions\Validation $pException)
{
$pDiscountCode->setValueIgnore('client');
throw $pException;
}
}
}
?>