Jump to content

AnthonyJane

Members
  • Posts

    6
  • Joined

  • Last visited

Profile Information

  • First Name
    Anthony
  • Last Name
    Jane

AnthonyJane's Achievements

Newbie

Newbie (1/14)

  • First Post Rare
  • Week One Done Rare
  • One Month Later Rare
  • One Year In Rare

Recent Badges

0

Reputation

  1. Hi Tresset, did you ever find a solution to this? We are using PS 1.7.7 and we are still having the same issue.
  2. Hi Jurist Did you ever resolve this? I am having exactly the same issue and need to fire from JS via ajax also. Thanks AJ
  3. Excellent thanks. So is addjsDef gone now?
  4. Not sure if this helps anyone but my problem with this error was due to the fact that my variable was null / empty. I had to wrap it in an if ! empty before trying to access it. {if !empty($variablename)} {if $variablename|strpos:"test" !== false} <div>Hi</div> {/if} {/if}
  5. In classes\assets\AbstractAssetManager.php protected $directories; protected $configuration; protected $list = array(); protected $server; const DEFAULT_MEDIA = 'all'; const DEFAULT_PRIORITY = 50; const DEFAULT_JS_POSITION = 'bottom'; use PrestaShop\PrestaShop\Adapter\Assets\AssetUrlGeneratorTrait; public function __construct(array $directories, ConfigurationInterface $configuration, $server = 'local') { $this->directories = $directories; $this->configuration = $configuration; $this->server = $server; $this->list = $this->getDefaultList(); } In classes\assets\CccReducer.php class CccReducerCore { private $cacheDir; protected $filesystem; protected $server; use PrestaShop\PrestaShop\Adapter\Assets\AssetUrlGeneratorTrait; public function __construct($cacheDir, ConfigurationInterface $configuration, Filesystem $filesystem, $server = 'local') { $this->cacheDir = $cacheDir; $this->configuration = $configuration; $this->filesystem = $filesystem; $this->server = $server; if (!is_dir($this->cacheDir)) { $this->filesystem->mkdir($this->cacheDir); } } public function reduceCss($cssFileList) { $files = array(); foreach ($cssFileList['external'] as $key => &$css) { if ('all' === $css['media'] && ('local' === $css['server'] || $this->server === $css['server'])) { $files[] = $css['path']; unset($cssFileList['external'][$key]); } } $cccFilename = 'theme-'.$this->getFileNameIdentifierFromList($files).'.css'; $destinationPath = $this->cacheDir.$cccFilename; if (!$this->filesystem->exists($destinationPath)) { CssMinifier::minify($files, $destinationPath); } if ('local' === $this->server) { $uri = $this->getFQDN().$this->getUriFromPath($destinationPath); } else { $uri = $this->server.$this->getUriFromPath($destinationPath); } $cssFileList['external']['theme-ccc'] = [ "id" => "theme-ccc", "type" => "external", "path" => $destinationPath, "uri" => $uri, "media" => "all", "priority" => StylesheetManager::DEFAULT_PRIORITY, ]; return $cssFileList; } public function reduceJs($jsFileList) { foreach ($jsFileList as $position => &$list) { $files = array(); foreach ($list['external'] as $key => $js) { // We only CCC the file without 'refer' or 'async' if ('' === $js['attribute'] && ('local' === $js['server'] || $this->server === $js['server'])) { $files[] = $js['path']; unset($list['external'][$key]); } } if (empty($files)) { // No file to CCC continue; } $cccFilename = $position.'-'.$this->getFileNameIdentifierFromList($files).'.js'; $destinationPath = $this->cacheDir.$cccFilename; if (!$this->filesystem->exists($destinationPath)) { JsMinifier::minify($files, $destinationPath); } if ('local' === $this->server) { $uri = $this->getFQDN().$this->getUriFromPath($destinationPath); } else { $uri = $this->server.$this->getUriFromPath($destinationPath); } $cccItem = []; $cccItem[$position.'-js-ccc'] = [ 'id' => $position.'-js-ccc', 'type' => 'external', 'path' => $destinationPath, 'uri' => $uri, 'priority' => JavascriptManager::DEFAULT_PRIORITY, 'attribute' => '', ]; $list['external'] = array_merge($cccItem, $list['external']); } return $jsFileList; } private function getFileNameIdentifierFromList(array $files) { return substr(sha1(implode('|', $files)), 0, 6); } } In classes\assets\StylesheetManager.php public function register( $id, $relativePath, $media = self::DEFAULT_MEDIA, $priority = self::DEFAULT_PRIORITY, $inline = false, $server = 'local' ) { if('' === $server){ $server = $this->server; } if ('remote' === $server) { $this->add($id, $relativePath, $media, $priority, $inline, $server); } else if ($fullPath = $this->getFullPath($relativePath)) { $this->add($id, $fullPath, $media, $priority, $inline, $server); } } protected function add($id, $fullPath, $media, $priority, $inline, $server) { if ('remote' !== $server && filesize($fullPath) === 0) { return; } $priority = is_int($priority) ? $priority : self::DEFAULT_PRIORITY; $media = $this->getSanitizedMedia($media); if ('remote' === $server) { $uri = $fullPath; $type = 'external'; } else if ('local' === $server) { $uri = $this->getFQDN().$this->getUriFromPath($fullPath); $type = ($inline) ? 'inline' : 'external'; } else { $uri = $server.$this->getUriFromPath($fullPath); $type = ($inline) ? 'inline' : 'external'; } $this->list[$type][$id] = array( 'id' => $id, 'type' => $type, 'path' => $fullPath, 'uri' => $uri, 'media' => $media, 'priority' => $priority, 'server' => $server, ); } In classes\assets\JavascriptManager.php public function register( $id, $relativePath, $position = self::DEFAULT_JS_POSITION, $priority = self::DEFAULT_PRIORITY, $inline = false, $attribute = null, $server = 'local' ) { if('' === $server){ $server = $this->server; } if ('remote' === $server) { $this->add($id, $relativePath, $position, $priority, $inline, $attribute, $server); } else if ($fullPath = $this->getFullPath($relativePath)) { $this->add($id, $fullPath, $position, $priority, $inline, $attribute, $server); } } protected function add($id, $fullPath, $position, $priority, $inline, $attribute, $server) { if ('remote' !== $server && filesize($fullPath) === 0) { return; } $priority = is_int($priority) ? $priority : self::DEFAULT_PRIORITY; $position = $this->getSanitizedPosition($position); $attribute = $this->getSanitizedAttribute($attribute); if ('remote' === $server) { $uri = $fullPath; $type = 'external'; } else if ('local' === $server) { $uri = $this->getFQDN().$this->getUriFromPath($fullPath); $type = ($inline) ? 'inline' : 'external'; } else { $uri = $server.$this->getUriFromPath($fullPath); $type = ($inline) ? 'inline' : 'external'; } $this->list[$position][$type][$id] = array( 'id' => $id, 'type' => $type, 'path' => $fullPath, 'uri' => $uri, 'priority' => $priority, 'attribute' => $attribute, 'server' => $server, ); } In classes\controllers\FrontController.php public function __construct() { $this->controller_type = 'front'; global $useSSL; parent::__construct(); if (Configuration::get('PS_SSL_ENABLED') && Configuration::get('PS_SSL_ENABLED_EVERYWHERE')) { $this->ssl = true; } $this->guestAllowed = Configuration::get('PS_GUEST_CHECKOUT_ENABLED'); if (isset($useSSL)) { $this->ssl = $useSSL; } else { $useSSL = $this->ssl; } $mediaUrl = Tools::getMediaServer("/"); if(substr($mediaUrl,0, 4) != "http"){ $mediaUrl = Tools::getCurrentUrlProtocolPrefix() . $mediaUrl; } $this->objectPresenter = new ObjectPresenter(); $this->cart_presenter = new CartPresenter(); $this->templateFinder = new TemplateFinder($this->context->smarty->getTemplateDir(), '.tpl'); $this->stylesheetManager = new StylesheetManager( array(_PS_THEME_DIR_, _PS_PARENT_THEME_DIR_, _PS_ROOT_DIR_), new ConfigurationAdapter(), $mediaUrl ); $this->javascriptManager = new JavascriptManager( array(_PS_THEME_DIR_, _PS_PARENT_THEME_DIR_, _PS_ROOT_DIR_), new ConfigurationAdapter(), $mediaUrl ); $this->cccReducer = new CccReducer( _PS_THEME_DIR_.'assets/cache/', new ConfigurationAdapter(), new Filesystem(), $mediaUrl ); }
  6. Well after some digging on PS 1.7.0.4 we found that the JavascriptManager, StyleSheetManager and CccReducer classes completely ignore the media server settings. We are not sure if this is by design but if it is it seems odd. We have updated these files and we now have our JS and CSS being served from our CDN when the CCC options are on and off. I am not sure if I should submit these changes anywhere so others can benefit from them (if the PS team agrees the changes should be made obviously). Also sorry to the OP for highjacking this thread :-)
  7. Thanks for that. We have tried that but it is almost like Prestashop 1.7.0.4 does not use the media url as the base for the js and css files in the same way as the previous versions did. I am hoping that it is a misconfiguration problem and not a problem with PS. We are using the default theme and default data at the moment so it is OOTB.
  8. Hi Dobre What version were you using....we have had this running successfully in 1.6 but in 1.7 we have the issue that images are cached on the media server (maxcdn) but CSS and JS files are not. Were you able to resolve this in your version and if so, how? Thanks AJ
×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More