/** * trigger login after * @param $logged_info */ function triggerLoginAfter($logged_info) { $cartRepo = new CartRepository(); if ($this->cartBeforeLogin instanceof Cart) { if ($memberCart = $cartRepo->getCart($this->module_info->module_srl, NULL, $logged_info->member_srl, session_id())) { if ($memberCart->cart_srl != $this->cartBeforeLogin->cart_srl) { $memberCart->merge($this->cartBeforeLogin); } Context::set('cart', $memberCart); } else { $this->cartBeforeLogin->member_srl = $logged_info->member_srl; $this->cartBeforeLogin->save(); } } }
public function testCount() { $cRepo = new CartRepository(); $pRepo = new ProductRepository(); $cart = $cRepo->getCart(NULL, 14); $cart->emptyCart(); $cart->addProduct($pRepo->getProduct(130)); $cart->addProduct($pRepo->getProduct(132)); $this->assertEquals(2, $cart->count()); }
/** * shop init service **/ public function initService(&$oModule, $is_other_module = FALSE, $isMobile = FALSE){ if (!$oModule) $oModule = $this; /** @var $oShopModel shopModel */ $oShopModel = getModel('shop'); $this->initCommon($is_other_module); Context::addJsFile($this->module_path.'tpl/js/shop_service.js'); $preview_skin = Context::get('preview_skin'); if(!$isMobile) { if($is_other_module){ $path_method = 'setLayoutPath'; $file_method = 'setLayoutFile'; $css_path_method = 'getLayoutPath'; Context::set('shop_mode', 'module'); Context::set('external_module', $oModule->module); }else{ $path_method = 'setTemplatePath'; $file_method = 'setTemplateFile'; $css_path_method = 'getTemplatePath'; } if(!$preview_skin){ $oShopModel->checkShopPath($this->module_srl, $this->module_info->skin); $oModule->{$path_method}($oShopModel->getShopPath($this->module_srl)); }else{ $oModule->{$path_method}($this->module_path.'skins/'.$preview_skin); } $oModule->{$file_method}('shop'); Context::addCssFile($oModule->{$css_path_method}().'shop.css',TRUE,'all','',100); } Context::set('root_url', Context::getRequestUri()); Context::set('home_url', getFullSiteUrl($this->shop->domain)); Context::set('profile_url', getSiteUrl($this->shop->domain,'','mid',$this->module_info->mid,'act','dispShopProfile')); if(Context::get('is_logged')) Context::set('admin_url', getSiteUrl($this->shop->domain,'','mid',$this->module_info->mid,'act','dispShopToolDashboard')); else Context::set('admin_url', getSiteUrl($this->shop->domain,'','mid','shop','act','dispShopToolLogin')); Context::set('shop_title', $this->shop->get('shop_title')); // set browser title Context::setBrowserTitle($this->shop->get('browser_title')); // Load cart for display on all pages (in header) $cartRepo = new CartRepository(); $logged_info = Context::get('logged_info'); // If cart doesn't exist, create new one $cart = $cartRepo->getCart($this->module_srl, NULL, $logged_info->member_srl, session_id(), TRUE); Context::set('cart', $cart); // Load cart preview (for ajax cart feature in header) $cart_preview = new CartPreview($cart, 3); Context::set('cart_preview', $cart_preview); // Load menu for display on all pages (in header) $shop = Context::get('shop'); $menus = $shop->getMenus(); foreach($menus as $menu_key => $menu_srl) { $menu = new ShopMenu($menu_srl); Context::set($menu_key, $menu->getHtml()); } // Load categories for display in search dropdown (header) $category_repository = new CategoryRepository(); $tree = $category_repository->getNavigationCategoriesTree($this->module_srl); $flat_tree = $tree->toFlatStructure(); Context::set('search_categories', $flat_tree); }