/** * Returns the cache key parts for this product group * * @return string * * @author Sebastian Diel <*****@*****.**> * @since 15.11.2014 */ public function CacheKeyParts() { if (is_null($this->cacheKeyParts)) { $product = singleton('SilvercartProduct'); $products = $this->getProducts(); $productMapIDs = ''; $productMapLastEdited = ''; $groupIDs = ''; if ($products instanceof SS_List && $products->count() > 0) { $productMap = $this->getProducts()->map('ID', 'LastEditedForCache')->toArray(); if (!is_array($productMap)) { $productMap = array(); } $productMapIDs = implode('_', array_keys($productMap)); sort($productMap); $productMapLastEdited = array_pop($productMap); if (Member::currentUserID() > 0) { $groupIDs = implode('-', SilvercartCustomer::currentUser()->getGroupIDs()); } } $cacheKeyParts = array(i18n::get_locale(), $this->LastEdited, $productMapIDs, $productMapLastEdited, $groupIDs, $this->getProductsPerPageSetting(), $this->getSqlOffset(), SilvercartProduct::defaultSort(), SilvercartGroupViewHandler::getActiveGroupView(), $product->getDefaultSort()); $this->extend('updateCacheKeyParts', $cacheKeyParts); $this->cacheKeyParts = $cacheKeyParts; } return $this->cacheKeyParts; }
/** * We set checkbox field values here to false if they are not in the post * data array. * * @param SilvercartWidget_Controller $widget Widget to initialize * @param array $data The post data array * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 28.03.2012 */ public static function populateFromPostDataForProductSliderWidget(SilvercartWidget_Controller $widget, $data) { $widget->write(); if (!array_key_exists('isContentView', $data)) { $widget->isContentView = 0; } if (!array_key_exists('GroupView', $data)) { $widget->GroupView = SilvercartGroupViewHandler::getDefaultGroupViewInherited(); } if (!array_key_exists('Autoplay', $data)) { $widget->autoplay = 0; } if (!array_key_exists('buildArrows', $data)) { $widget->buildArrows = 0; } if (!array_key_exists('buildNavigation', $data)) { $widget->buildNavigation = 0; } if (!array_key_exists('buildStartStop', $data)) { $widget->buildStartStop = 0; } if (!array_key_exists('autoPlayDelayed', $data)) { $widget->autoPlayDelayed = 0; } if (!array_key_exists('autoPlayLocked', $data)) { $widget->autoPlayLocked = 0; } if (!array_key_exists('stopAtEnd', $data)) { $widget->stopAtEnd = 0; } if (!array_key_exists('useSlider', $data)) { $widget->useSlider = 0; } }
/** * Returns the cache key parts for this product group holder * * @return array * * @author Sebastian Diel <*****@*****.**> * @since 20.01.2014 */ public function CacheKeyParts() { if (is_null($this->cacheKeyParts)) { $lastEditedChildID = 0; if ($this->dataRecord->Children()->Count() > 0) { $this->dataRecord->Children()->sort('LastEdited', 'DESC'); $lastEditedChildID = $this->dataRecord->Children()->First()->ID; } $cacheKeyParts = array(i18n::get_locale(), $this->dataRecord->LastEdited, $this->getSqlOffsetForProductGroups(), SilvercartGroupViewHandler::getActiveGroupHolderView(), $lastEditedChildID); $this->extend('updateCacheKeyParts', $cacheKeyParts); $this->cacheKeyParts = $cacheKeyParts; } return $this->cacheKeyParts; }
/** * set the group view to use by default for product group lists * * @param string $defaultGroupHolderView the class name of the group view to use by default * * @return void */ public static function setDefaultGroupHolderView($defaultGroupHolderView = null) { SilvercartGroupViewHandler::setDefaultGroupHolderView($defaultGroupHolderView); }
} // ---------------------------------------------------------------------------- // add possible group views // ---------------------------------------------------------------------------- SilvercartGroupViewHandler::addGroupView('SilvercartGroupViewList'); SilvercartGroupViewHandler::addGroupView('SilvercartGroupViewTile'); SilvercartGroupViewHandler::addGroupHolderView('SilvercartGroupViewList'); SilvercartGroupViewHandler::addGroupHolderView('SilvercartGroupViewTile'); // ---------------------------------------------------------------------------- // set default group view if not existant // ---------------------------------------------------------------------------- if (is_null(SilvercartGroupViewHandler::getDefaultGroupView())) { SilvercartGroupViewHandler::setDefaultGroupView('SilvercartGroupViewList'); } if (is_null(SilvercartGroupViewHandler::getDefaultGroupHolderView())) { SilvercartGroupViewHandler::setDefaultGroupHolderView('SilvercartGroupViewList'); } if (class_exists('GoogleSitemap') && method_exists('GoogleSitemap', 'register_dataobject')) { GoogleSitemap::register_dataobject('SilvercartProduct', null, '0.2'); } // ---------------------------------------------------------------------------- // add silvercart branding if no other branding is set // ---------------------------------------------------------------------------- if (Config::inst()->get('LeftAndMain', 'application_name') == 'SilverStripe') { Config::inst()->update('LeftAndMain', 'application_name', 'SilverCart - ' . SilvercartConfig::SilvercartFullVersion()); Config::inst()->update('LeftAndMain', 'application_link', 'http://www.silvercart.org'); } // ---------------------------------------------------------------------------- // Register menus for the storeadmin // ---------------------------------------------------------------------------- SilvercartConfig::registerMenu('default', _t('SilvercartStoreAdminMenu.DEFAULT'));
/** * Returns the inherited DefaultGroupHolderView * * @param SilvercartProductGroupPage $context Context * * @return string */ public function getDefaultGroupHolderViewInherited($context = null) { if (is_null($context)) { $context = $this->owner; } $defaultGroupHolderView = $context->DefaultGroupHolderView; if (empty($defaultGroupHolderView) || SilvercartGroupViewHandler::getGroupHolderView($defaultGroupHolderView) === false) { if ($context->Parent() instanceof SilvercartProductGroupPage || $context->Parent() instanceof SilvercartProductGroupHolder) { $defaultGroupHolderView = $this->getDefaultGroupHolderViewInherited($context->Parent()); } else { $defaultGroupHolderView = SilvercartGroupViewHandler::getDefaultGroupHolderView(); } } return $defaultGroupHolderView; }
/** * set the group view to use by default for product group lists * * @param string $defaultGroupHolderView the class name of the group view to use by default * * @return void */ public static function setDefaultGroupHolderView($defaultGroupHolderView = null) { if (is_null($defaultGroupHolderView) || !in_array($defaultGroupHolderView, self::$groupHolderViews)) { foreach (self::$groupHolderViews as $code => $groupHolderView) { self::$defaultGroupHolderView = $code; return; } self::addGroupHolderView($defaultGroupHolderView); } $tmp = array_flip(self::$groupHolderViews); self::$defaultGroupHolderView = $tmp[$defaultGroupHolderView]; }
/** * Returns the input fields for this widget. * * @return FieldList * * @author Sebastian Diel <*****@*****.**> * @since 27.03.2012 */ public function getCMSFields() { $fields = SilvercartDataObject::getCMSFields($this, 'ExtraCssClasses', false); $fetchMethods = array('random' => $this->fieldLabel('fetchMethodRandom'), 'sortOrderAsc' => $this->fieldLabel('fetchMethodSortOrderAsc'), 'sortOrderDesc' => $this->fieldLabel('fetchMethodSortOrderDesc')); $fetchMethodsField = $fields->dataFieldByName('fetchMethod'); $fetchMethodsField->setSource($fetchMethods); $fields->replaceField('GroupView', SilvercartGroupViewHandler::getGroupViewDropdownField('GroupView', $this->fieldLabel('GroupView'))); // Temporary disabled slider functions. //SilvercartWidgetTools::getCMSFieldsSliderTabForProductSliderWidget($this, $fields); $fields->removeByName('numberOfProductsToShow'); return $fields; }
/** * returns, wether the group view is active or not * * @return bool */ public function getActiveHolder() { if (is_null($this->activeHolder)) { $this->setActiveHolder($this->Code == SilvercartGroupViewHandler::getActiveGroupHolderView()); } return $this->activeHolder; }