/** * Check catalogue URL's before we get to the CMS (if it exists) * * @param SS_HTTPRequest $request * @param DataModel|null $model * @return SS_HTTPResponse */ public function handleRequest(SS_HTTPRequest $request, DataModel $model) { $this->request = $request; $this->setDataModel($model); $catalogue_enabled = Catalogue::config()->enable_frontend; $this->pushCurrent(); // Create a response just in case init() decides to redirect $this->response = new SS_HTTPResponse(); $this->init(); // If we had a redirection or something, halt processing. if ($this->response->isFinished()) { $this->popCurrent(); return $this->response; } // If DB is not present, build if (!DB::isActive() || !ClassInfo::hasTable('CatalogueProduct') || !ClassInfo::hasTable('CatalogueCategory')) { return $this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null)); } $urlsegment = $request->param('URLSegment'); $this->extend('onBeforeInit'); $this->init(); $this->extend('onAfterInit'); // Find link, regardless of current locale settings if (class_exists('Translatable')) { Translatable::disable_locale_filter(); } $filter = array('URLSegment' => $urlsegment, 'Disabled' => 0); if ($catalogue_enabled && ($object = CatalogueProduct::get()->filter($filter)->first())) { $controller = $this->controller_for($object); } elseif ($catalogue_enabled && ($object = CatalogueCategory::get()->filter($filter)->first())) { $controller = $this->controller_for($object); } elseif (class_exists('ModelAsController')) { // If CMS installed $controller = ModelAsController::create(); } else { $controller = Controller::create(); } if (class_exists('Translatable')) { Translatable::enable_locale_filter(); } $result = $controller->handleRequest($request, $model); $this->popCurrent(); return $result; }
public function getItemSummary() { $modify_price = $this->ModifyPrice; $price = new Currency(); $tax_id = $this->Parent()->Parent()->TaxRateID; if ($tax_id && Catalogue::config()->price_includes_tax) { $modify_price += $modify_price / 100 * $this->Parent()->Parent()->TaxRate()->Amount; } $price->setValue($modify_price); if ($price->RAW() > 0) { $summary = $this->Title . ' +' . $price->nice(); } elseif ($price->RAW() < 0) { $summary = $this->Title . ' -' . str_replace(array("(", ")"), "", $price->nice()); } else { $summary = $this->Title; } $this->extend('updateItemSummary', $summary); return $summary; }
<?php // If subsites is installed if (class_exists('Subsite')) { CatalogueProduct::add_extension('SubsiteCatalogueExtension'); CatalogueCategory::add_extension('SubsiteCatalogueExtension'); TaxRate::add_extension('SubsiteCatalogueExtension'); CatalogueAdmin::add_extension('SubsiteMenuExtension'); } // Setup google sitemaps $catalogue_enabled = Catalogue::config()->enable_frontend; if ($catalogue_enabled && class_exists("GoogleSitemap")) { GoogleSitemap::register_dataobject('CatalogueProduct'); GoogleSitemap::register_dataobject('CatalogueCategory'); }
/** * Generate a string to go with the the product price. We can * overwrite the wording of this by using Silverstripes language * files * * @return String */ public function getTaxString() { if ($this->TaxRateID && Catalogue::config()->price_includes_tax) { $return = _t("Catalogue.TaxIncludes", "Includes") . " " . $this->TaxRate()->Title; } elseif ($this->TaxRateID && !Catalogue::config()->price_includes_tax) { $return = _t("Catalogue.TaxExcludes", "Excludes") . " " . $this->TaxRate()->Title; } else { $return = ""; } return $return; }