bool value, ...] */ public static function getCartItemCapabilities() { return []; } public function setErrors(array $errors) { $this->_errors = $errors; return $this; } public function addErrors(array $errors) { $this->_errors = $this->_errors + $errors; return $this; } /** * Method should set primary key and init item object * @param array $data ['id' =>, 'cartId' =>, 'productId' =>, ...] * * @return CartItemObj */ public function setCartItemData(array $data) { $this->_cartItemData = $data; $this->setPrimaryKey($this->_cartItemData['productCategoryId']); return $this; } public function getCartItemData() { return $this->_cartItemData; } /** * Prepare item data (from db) * @return array */ public function prepareCartItemData() { $allowChangeQuantity = in_array(ItemObjFactory::CAPABILITY_CHANGE_QTY, $this->getCartItemCapabilities()) ? 'y' : 'n'; $userFullName = ''; if (UserAuth::getInstance()->isLoggedIn()) { $userFullName = UserAuth::getInstance()->getData('firstName') . ' ' . UserAuth::getInstance()->getData('lastName'); } $this->_cartItemData = array_merge($this->_cartItemData, [ 'cartItemType' => static::ITEM_TYPE, 'typeTitle' => static::ITEM_TYPE_TITLE, 'description' => $userFullName, 'applyTax' => 'n', 'applyShipping' => 'n', 'allowChangeQuantity' => $allowChangeQuantity, 'showDescription' => 'n', 'url' => View::getPage('url'), ] ); return $this->_cartItemData; } public function beforeValidateCart() { return $this; } /** * @return bool */ public function validateCartItem() { $this->setPrimaryKey($this->_cartItemData['productCategoryId']); if (!$this->clearData()->getData()) { $this->_addError(static::MSG_NOT_EXISTS); return false; } return true; } public function completeItemList(array $itemList) { $cartIds = \Qs_Array::fetchCol($itemList, 'cartId'); if (empty($cartIds)) { return $this; } $cartId = reset($cartIds); $submissionData = []; if (UserAuth::getInstance()->isLoggedIn()) { $loggedUserData = UserAuth::getInstance()->getData(); if (!empty($loggedUserData['nickname'])) { $submissionData['name'] = $loggedUserData['nickname'] . ' ' . $loggedUserData['lastName']; } else { $submissionData['name'] = $loggedUserData['firstName'] . ' ' . $loggedUserData['lastName']; } $submissionData['userId'] = $loggedUserData['id']; $submissionData['email'] = $loggedUserData['email']; } else { $cartObj = new App_ECommerce_Cart_Obj(); $cartObj->setPrimaryKey($cartId); $cartObj->getData(); $orderObj = new App_ECommerce_Order_Obj(); $orderObj->setPrimaryKey($cartObj->getData('transactionId')); $orderData = $orderObj->getData(); $submissionData['name'] = $orderData['billingFirstName'] . ' ' . $orderData['billingLastName']; $submissionData['email'] = $orderData['billingEmail']; } $submissionTable = new Qs_Db_Table('SponsorshipSubmission'); $cartItemTable = new Qs_Db_Table('CartItem'); foreach($itemList as $submission) { $submissionData['categoryId'] = $submission['productCategoryId']; $submissionData['categoryTitle'] = $submission['title']; $submissionData['amount'] = Zend_Locale_Math::Mul($submission['price'], $submission['quantity'], 4); $productId = $submissionTable->insert($submissionData); $cartItemTable->updateByKey(['productId' => $productId], $submission['id']); } return $this; } public function afterCartItemRemove() { return $this; } /** * assign additionalData to $_cartData for displaying at cart full list * * @return mixed */ public function prepareCartItemForCartList() { $this->_cartItemData['additionalData'] = ''; return $this; } }