Skip to Content

New J2Commerce 6.6.5 is out. Here is everything in the release.

See What’s New
Account
Enter the email address on your account.
Forgot your username?
Enter your password.
Forgot your password?

Or continue with

Pending Public Category: Technical Support / Bugs Ticket #287

Fix addCSS()

This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Conversation

mmm98ninja@gmail.com

hi , administrator/components/com_j2store/helpers/strapper.php

addCSS() , css file not load in code.

im fixed code

public static function addCSS() {
$j2storeparams = J2Store::config ();
$app = Factory::getApplication();
$platform = J2Store::platform();
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();

// load full bootstrap css bundled with J2Commerce.
if ($app->isClient('site') && $j2storeparams->get('load_bootstrap', 0)) {
$wa->registerAndUseStyle('j2store-bootstrap', Uri::root().'media/j2store/css/bootstrap.min.css');
}

// for site side, check if the param is enabled.
if ($app->isClient('site') && $j2storeparams->get('load_minimal_bootstrap', 0)) {
$wa->registerAndUseStyle('j2store-minimal',Uri::root().'media/j2store/css/minimal-bs.css');
}

// jquery UI css
$ui_location = $j2storeparams->get ( 'load_jquery_ui', 3 );
switch ($ui_location) {

case '0' :
// load nothing
break;
case '1' :
if ($app->isClient('site')) {
$wa->registerAndUseStyle('j2store-custom-css',Uri::root().'media/j2store/css/jquery-ui-custom.css');
}
break;

case '2' :
if ($app->isClient('administrator')) {
$wa->registerAndUseStyle('j2store-custom-css',Uri::root().'media/j2store/css/jquery-ui-custom.css');
}
break;

case '3' :
default :
$wa->registerAndUseStyle('j2store-custom-css',Uri::root().'media/j2store/css/jquery-ui-custom.css');
break;
}

if ($app->isClient('administrator')) {
$wa->registerAndUseStyle('j2store-admin-css', Uri::root().'media/j2store/css/J4/j2store_admin.css');
$wa->registerAndUseStyle('listview-css', Uri::root().'media/j2store/css/backend/listview.css');
$wa->registerAndUseStyle('editview-css', Uri::root().'media/j2store/css/backend/editview.css');
$wa->registerAndUseStyle('j2store-fancybox-css',Uri::root().'media/j2store/css/jquery.fancybox.min.css');
} else {
J2Store::strapper()->addFontAwesome();
// Add related CSS to the <head>
if ($app->getDocument()->getType() === 'html' && $j2storeparams->get('j2store_enable_css', 1)) {
$template = self::getDefaultTemplate();
// j2store.css
if (file_exists(JPATH_SITE . '/templates/' . $template . '/css/j2store.css')){
$wa->registerAndUseStyle('j2store-css', Uri::root() . 'templates/' . $template . '/css/j2store.css');
} elseif (file_exists(JPATH_SITE . '/media/templates/site/' . $template . '/css/j2store.css')) {
$wa->registerAndUseStyle('j2store-css', Uri::root() .'media/templates/site/' . $template . '/css/j2store.css');
} else {
$wa->registerAndUseStyle('j2store-css', 'media/j2store/css/j2store.css');
}
}
else {
$wa->registerAndUseStyle('j2store-css', 'media/j2store/css/j2store.css');
}
$load_fancybox = $j2storeparams->get ( 'load_fancybox', 1 );
if($load_fancybox){
$wa->registerAndUseStyle('j2store-fancybox-css', Uri::root() .'media/j2store/css/jquery.fancybox.min.css');
}
}
J2Store::plugin ()->event ( 'AfterAddCSS' );
}

Olivier Buisard Staff

Hello,

thank you for your report.

The suggestion resolution may work for you but it is not fully correct.

  • the paths are missing 
    Uri::root()
    to ensure the path is always correct,
  • the setting 'enable j2store.css' is bypassed as the file is loaded in all cases.

Note that

$wa->registerAndUseStyle('j2store-css', 'j2store/j2store.css');

is not a mistake.

It is a shorthand that calls media/j2store/css/j2store.css without the need to specify the path to the media directory.

Olivier.