*/ /** * The implementation of the cart module * * @package Cart */ class CartModule extends GalleryModule /* and GalleryEventListener */ { function CartModule() { global $gallery; $this->setId('cart'); $this->setName('Cart'); $this->setDescription($gallery->i18n('Shopping Cart Module')); $this->setVersion('0.8.9'); $this->setGroup('commerce', $this->translate('Commerce')); $this->setCallbacks('getItemLinks|loadSystemContent'); $this->setRequiredCoreApi(array(4, 0)); $this->setRequiredModuleApi(array(0, 9)); } /** * @see GalleryModule::upgrade() */ function upgrade($currentVersion) { global $gallery; switch ($currentVersion) { case '0.8': case '0.8.1': case '0.8.2': case '0.8.3': case '0.8.4': case '0.8.5': case '0.8.6': case '0.8.7': case '0.8.8': $storage =& $gallery->getStorage(); $query = ' DROP TABLE [CartMap] '; $ret = $storage->execute($query); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } $query = ' DELETE FROM [Schema] WHERE [Schema::name] = \'CartMap\' '; $ret = $storage->execute($query); if ($ret->isError()) { return $ret->wrap(__FILE__, __LINE__); } } return GalleryStatus::success(); } /** * @see GalleryModule::isRecommendedDuringInstall */ function isRecommendedDuringInstall() { return true; } /** * @see GalleryModule::autoConfigure */ function autoConfigure() { /* We don't require any special configuration */ return array(GalleryStatus::success(), true); } /** * @see GalleryModule::getItemLinks() */ function getItemLinks($items) { $links = array(); foreach ($items as $item) { $itemTypeNames = $item->itemTypeName(); $links[$item->getId()][] = array('text' => $this->translate(array('text' => 'add %s to cart', 'arg1' => $itemTypeNames[1])), 'params' => array('controller' => 'cart:AddToCart', 'itemId' => $item->getId(), 'return' => true)); } return array(GalleryStatus::success(), $links); } /** * @see GalleryModule::loadSystemContent */ function loadSystemContent(&$template) { $content = array(); $view = GalleryUtilities::getRequestVariables('view'); if ($view == 'cart:ViewCart') { return array(GalleryStatus::success(), array()); } /* The "View Cart" link */ $links = array(); $links[] = array('text' => $this->translate('View Cart'), 'params' => array('view' => 'cart:ViewCart', 'return' => true)); $CartSystemContent['links'] = $links; /* The cart content's count */ GalleryCoreApi::requireOnce(dirname(__FILE__) . '/classes/CartHelper.class'); list ($ret, $cartItemIds) = CartHelper::fetchCartItemCounts(); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), null); } $CartSystemContent['count'] = 0; foreach ($cartItemIds as $itemId => $count) { $CartSystemContent['count'] += $count; } $template->setVariable('CartSystemContent', $CartSystemContent); $content = array('cart' => 'modules/cart/templates/CartSystemContent.tpl'); return array(GalleryStatus::success(), $content); } } ?>