23 $this->_oConfig = &$oConfig;
24 $this->_oTemplate = &$oTemplate;
25 $this->_sLangsPrefix = $this->_oConfig->getLangsPrefix();
29 return $this->_oTemplate->displayHistoryBlock($iUserId, $iSellerId);
33 return $this->_oTemplate->displayCartJs($bWrapped);
35 function getAddToCartJs($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect =
false, $bWrapped =
true)
37 return $this->_oTemplate->displayAddToCartJs($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect, $bWrapped);
39 function getAddToCartLink($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect =
false)
41 return $this->_oTemplate->displayAddToCartLink($iVendorId, $iModuleId, $iItemId, $iItemCount, $bNeedRedirect);
43 function addToCart($iClientId, $iVendorId, $iModuleId, $iItemId, $iItemCount)
46 return array(
'code' => 1,
'message' =>
_t($this->_sLangsPrefix .
'err_wrong_data'));
49 return array(
'code' => 2,
'message' =>
_t($this->_sLangsPrefix .
'err_required_login'));
51 if($iClientId == $iVendorId)
52 return array(
'code' => 3,
'message' =>
_t($this->_sLangsPrefix .
'err_purchase_from_yourself'));
54 $aVendor = $this->_oDb->getVendorInfoProfile($iVendorId);
55 if($aVendor[
'status'] !=
'Active')
56 return array(
'code' => 4,
'message' =>
_t($this->_sLangsPrefix .
'err_inactive_vendor'));
58 $aVendorProviders = $this->_oDb->getVendorInfoProviders($iVendorId);
59 if(
empty($aVendorProviders))
60 return array(
'code' => 5,
'message' =>
_t($this->_sLangsPrefix .
'err_not_accept_payments'));
63 $sCartItem = $iVendorId . $sDd . $iModuleId . $sDd . $iItemId . $sDd . $iItemCount;
64 $sCartItems = $this->_oDb->getCartItems($iClientId);
66 if(strpos($sCartItems, $iVendorId . $sDd . $iModuleId . $sDd . $iItemId . $sDd) !==
false)
67 $sCartItems = preg_replace(
"'" . $iVendorId . $sDd . $iModuleId . $sDd . $iItemId . $sDd .
"([0-9])+'e",
"'" . $iVendorId . $sDd . $iModuleId . $sDd . $iItemId . $sDd .
"' . (\\1 + " . $iItemCount .
")", $sCartItems);
69 $sCartItems =
empty($sCartItems) ? $sCartItem : $sCartItems .
":" . $sCartItem;
71 $this->_oDb->setCartItems($iClientId, $sCartItems);
76 $iTotalQuantity += $aCart[
'items_count'];
78 return array(
'code' => 0,
'message' =>
_t($this->_sLangsPrefix .
'inf_successfully_added'),
'total_quantity' => $iTotalQuantity,
'content' => $this->_oTemplate->displayToolbarSubmenu(
$aInfo));
80 function deleteFromCart($iClientId, $iVendorId, $iModuleId = 0, $iItemId = 0)
83 return array(
'code' => 1,
'message' =>
_t($this->_sLangsPrefix .
'err_wrong_data'));
86 return array(
'code' => 2,
'message' =>
_t($this->_sLangsPrefix .
'err_required_login'));
89 $sPattern =
"'" . $iVendorId .
"_" . $iModuleId .
"_" . $iItemId .
"_[0-9]+:?'";
91 $sPattern =
"'" . $iVendorId .
"_[0-9]+_[0-9]+_[0-9]+:?'";
93 $sCartItems = $this->_oDb->getCartItems($iClientId);
94 $sCartItems = trim(preg_replace($sPattern,
"", $sCartItems),
":");
95 $this->_oDb->setCartItems($iClientId, $sCartItems);
97 return array(
'code' => 0,
'message' =>
_t($this->_sLangsPrefix .
'inf_successfully_deleted'));
107 return isset($aContent[$iVendorId]) ? $this->
_getInfo($iUserId, $iVendorId, $aContent[$iVendorId]) : array();
110 foreach($aContent
as $iVendorId => $aVendorItems)
111 $aResult[$iVendorId] = $this->
_getInfo($iUserId, $iVendorId, $aVendorItems);
117 return $iVendorId . self::$DESCRIPTOR_DIVIDER . $iModuleId . self::$DESCRIPTOR_DIVIDER . $iItemId . self::$DESCRIPTOR_DIVIDER . $iItemCount;
121 $aPending = is_array($mixedPending) ? $mixedPending : $this->_oDb->getPending(array(
'type' =>
'id',
'id' => (
int)$mixedPending));
122 if((
int)$aPending[
'processed'] == 1)
125 $iClientId = (int)$aPending[
'client_id'];
126 $sOrderId = $this->_oConfig->generateLicense();
128 $sCartItems = $this->_oDb->getCartItems($iClientId);
131 foreach($aItems
as $aItem) {
132 $aItemInfo =
ChWsbService::call((
int)$aItem[
'module_id'],
'register_cart_item', array($aPending[
'client_id'], $aPending[
'seller_id'], $aItem[
'item_id'], $aItem[
'item_count'], $sOrderId));
133 if(!is_array($aItemInfo) ||
empty($aItemInfo))
136 $this->_oDb->insertTransaction(array(
137 'pending_id' => $aPending[
'id'],
138 'order_id' => $sOrderId,
139 'client_id' => $aPending[
'client_id'],
140 'seller_id' => $aPending[
'seller_id'],
141 'module_id' => $aItem[
'module_id'],
142 'item_id' => $aItem[
'item_id'],
143 'item_count' => $aItem[
'item_count'],
144 'amount' => $aItemInfo[
'price'] * $aItem[
'item_count'],
147 $sCartItems = trim(preg_replace(
"'" . implode(self::$DESCRIPTOR_DIVIDER, $aItem) .
":?'",
"", $sCartItems),
":");
150 $this->_oDb->setCartItems($iClientId, $sCartItems);
151 $this->_oDb->updatePending($aPending[
'id'], array(
'processed' => 1));
155 $sItems = $this->_oDb->getCartItems($iUserId);
160 $sItems = $this->_oDb->getCartItems($iUserId);
166 foreach($aItems
as $aItem)
167 if(isset($aItem[$sKey]))
184 $aItemsInfo = array();
185 foreach($aItems
as $aItem) {
186 $aItemInfo =
ChWsbService::call((
int)$aItem[
'module_id'],
'get_cart_item', array($iClientId, $aItem[
'item_id']));
187 $aItemInfo[
'module_id'] = (int)$aItem[
'module_id'];
188 $aItemInfo[
'quantity'] = (int)$aItem[
'item_count'];
190 $iItemsCount += $aItem[
'item_count'];
191 $fItemsPrice += $aItem[
'item_count'] * $aItemInfo[
'price'];
192 $aItemsInfo[] = $aItemInfo;
195 $aVendor = $this->_oDb->getVendorInfoProfile((
int)$iVendorId);
197 'client_id' => $iClientId,
198 'vendor_id' => $aVendor[
'id'],
199 'vendor_username' => $aVendor[
'username'],
200 'vendor_profile_name' => $aVendor[
'profile_name'],
201 'vendor_profile_icon' => $aVendor[
'profile_icon'],
202 'vendor_profile_url' => $aVendor[
'profile_url'],
203 'vendor_currency_code' => $aVendor[
'currency_code'],
204 'vendor_currency_sign' => $aVendor[
'currency_sign'],
205 'items_count' => $iItemsCount,
206 'items_price' => $fItemsPrice,
207 'items' => $aItemsInfo
222 if(is_string($mixed))
223 $aItems = explode(
':', $mixed);
224 else if(is_array($mixed))
229 foreach($aItems
as $sItem) {
230 $aItem = explode(self::$DESCRIPTOR_DIVIDER, $sItem);
231 $aResult[] = array(
'vendor_id' => $aItem[0],
'module_id' => $aItem[1],
'item_id' => $aItem[2],
'item_count' => $aItem[3]);