/*
* Catid is only for information from which place the product was added to the cart
* When making order, this will be recheck
*/
public function addItems($id = 0, $catid = 0, $quantity = 0, $attributes = array(), $idKey = '')
{
$app = Factory::getApplication();
if ($idKey != '') {
// we get idkey as string - from checkout update or remove - used in CHECKOUT
} else {
// we get id as int standard id of product - attributes can be listed in form - used in CATEGORY, ITEM, ITEMS
//- $k = (int)$id . ':';
$checkP = PhocacartProduct::checkIfAccessPossible($id, $catid, $this->type);
if (!$checkP) {
//$uri = JUri::getInstance();
//$action = $uri->toString();
$app->enqueueMessage(Text::_('COM_PHOCACART_PRODUCT_NOT_ADDED_TO_SHOPPING_CART_NO_RIGHTS_FOR_ORDERING_PRODUCT'), 'error');
return false;
}
// Check if there is required attribute
// In fact this should not happen in item Online Shop view, as this should be checked per html5 checking form
// This is security check on server side - e.g. when testing attributes in items or category view
// But in POS EAN and SKU can be added with help of Advanced stock management so check direct adding of SKU or EAN
$checkedA = PhocacartAttribute::checkRequiredAttributes($id, $attributes);
if (!$checkedA) {
//$uri = JUri::getInstance();
//$action = $uri->toString();
$app->enqueueMessage(Text::_('COM_PHOCACART_PRODUCT_NOT_ADDED_TO_SHOPPING_CART_SELECTING_ATTRIBUTE_IS_REQUIRED'), 'error');
return false;
}
/*if (!empty($attributes)) {
// Remove empty values, so items with empty values (add to cart item view) is the same
// like item without any values (add to cart category view)
foreach($attributes as $k2 => $v2) {
if ($v2 == 0 || $v2 == '') {
unset($attributes[$k2]);
}
}
if (!empty($attributes)) {
$k .= base64_encode(serialize($attributes));
}
}
$k .= ':';*/
$k = PhocacartProduct::getProductKey($id, $attributes);
}
if ($k != '' && (int) $catid > 0) {
$this->items[$k]['catid'] = (int) $catid;
}
if ($k != '' && (int) $quantity > 0) {
if (isset($this->items[$k]['quantity']) && (int) $this->items[$k]['quantity'] > 0) {
$this->items[$k]['quantity'] = $this->items[$k]['quantity'] + (int) $quantity;
} else {
$this->items[$k]['quantity'] = (int) $quantity;
}
$this->updateItems();
//$this->updateSubTotal();
return true;
} else {
$app->enqueueMessage(Text::_('COM_PHOCACART_PRODUCT_NOT_ADDED_TO_SHOPPING_CART_QUANTITY_WAS_NOT_SET'), 'error');
}
return false;
}