Extension doesn't get enabled - opencart

I'm migrating extension for Opencart 2.3 to Opencart 3. Everything seems to work fine, except that I can't enable the extension. When I go to extension->shipping the status doesn't change it stays disabled, however if I go to settings, the drop down shows that enabled is selected. There aren't any errors on the front-end, or in the log files. I tried debugging but everything seems fine. Any ideas what may be wrong? Also the setting in the database(extensionName_status) is 1
Note: the extension is large, and it will be too much if I post it here. If you need specific fragment of code, I will provide it.

The tricky thing about the 2.3->3.0 migration was that some variable names changed in a subtle way (as noted in my comment above). The status variable could be your problem. Here's Better Together 3.0 (left) vs 2.3 (right) in the controller file:
< $data['total_better_together_status'] = $this->config->get('total_better_together_status');
---
> $data['better_together_status'] = $this->config->get('better_together_status');

If your OpenCart 3.x module is labeled in the Modules category, then:
if (isset($this->request->post['module_mymodule_status'])) {
$data['module_mymodule_status'] = $this->request->post['module_mymodule_status'];
} else {
$data['module_mymodule_status'] = $this->config->get('module_mymodule_status');
}
Or if it's labeled in the Analytics category, then you just change the module to analytics as shown below:
if (isset($this->request->post['analytics_mymodule_status'])) {
$data['analytics_mymodule_status'] = $this->request->post['analytics_mymodule_status'];
} else {
$data['analytics_mymodule_status'] = $this->config->get('analytics_mymodule_status');
}

Related

webview_flutter can't hide/change some elements

Using the webview_flutter with evaluateJavascript(), I've been able to modify the style of most elements of my website, but can't understand why some elements don't get modified.
My WebView is included, and the website to display within the WebView is https://dme.com.sg/index.php?dispatch=auth.login_form
I've included a snapshot as well, showing how I can hide and modify the colours for most of the elements, yet it seems all those that are within the "form" cannot be changed.
Would appreciate any help on how I can modify those as well, especially to change their colours to a darker theme to match the colours of the app.
WebView(
initialUrl: 'https://dme.com.sg/index.php?dispatch=auth.login_form',
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_controller = controller;
},
onPageStarted: (url) {
_controller.evaluateJavascript(
"document.getElementsByClassName('tygh-top-panel clearfix')[0].style.display='none';"
"document.getElementsByClassName('tygh-header clearfix')[0].style.display='none';"
"document.getElementsByClassName('tygh-header')[0].style.display='none';"
"document.getElementsByClassName('tygh-footer')[0].style.display='none';"
"document.getElementsByClassName('auth-information-grid')[0].style.display='none';"
"document.getElementsByClassName('ty-breadcrumbs clearfix')[0].style.display = 'none';"
"document.getElementsByClassName('container-fluid content-grid')[0].style.background = 'black';"
"document.getElementsByClassName('ty-mainbox-title')[0].style.color = 'pink';"
"document.getElementsByClassName('buttons-container clearfix')[0].style.display = 'none';"
);
},
),
Have kept tinkering around with it, and looking up JavaScript tutorial, and I managed to find a solution. So I'm not sure HOW or WHY, so still hoping someone could comment a response that explains so I can better understand.
Something else I've learnt, it's easier to just use the "console" tab of chrome to test the java scripts on the page before moving it into flutter webview.
Using the "document.getElementsByClassName("buttons-container clearfix")" command, I got a list of where the class was being used, and found the one I wanted to change was 1. It helps that when as you type the right index number, it gets highlighted on the website.
So then using "document.getElementsByClassName("buttons-container clearfix")1.style.background = 'black'" I managed to change the style of the element I wanted.
I've included a screengrab of the chrome console here if it can help anyone else.

Sitecore IsPageEditor and IsExperienceEditor

We are currently writing a module for Sitecore and have ran into a problem.
We have a pipeline in which we do the following check:
if (Sitecore.Context.PageMode.IsExperienceEditor)
{
return;
}
The problem is that one of our clients are running and older version of Sitecore (8.0 update 5) where the property IsExperienceEditor does not exist yet. See Sitecore release notes for next update where it is introduced.
To quickly fix the error we used the older deprecated property which is this:
if (Sitecore.Context.PageMode.IsPageEditor)
{
return;
}
Now the question is, is there any way in which we can test for the Sitecore version so we can have backwards compatibility in the module?
You can use the code which is executed in Sitecore in background of both properties mentioned by you:
if (Sitecore.Context.Site.DisplayMode == Sitecore.Sites.DisplayMode.Edit)
{
return;
}
I know that using Sitecore.Context.PageMode.IsExperienceEditor (or Sitecore.Context.PageMode.IsPageEditor) is more elegant, but in a situation when you need to support both old and new Sitecore versions, that's sounds like a good option.
The deprecated property of IsPageEditor is still present specifically for the purpose of backward compatibility. IsExperienceEditor is just a renamed property that does the same thing that IsPageEditor does.
However you can check for the existence of a property like this:
public static bool HasProperty(this object obj, string propertyName)
{
return obj.GetType().GetProperty(propertyName) != null;
}
Another option is to make two different versions of the module, if the implementation becomes significantly different for the different versions of Sitecore.

Sitecore Glass Mapper always null

I am using Sitecore Glass Mapper for a new project I'm setting up.
We are using Sitecore 7.2, latest version of Team Development for Sitecore (TDS) code generation and the latest version of glass.
The code I am trying to execute:
var b = new SitecoreContext();
var c = b.GetCurrentItem<T01_Homepage>();
b is not null. c is null.
var d = b.GetItem<T01_Homepage>("path")
d is null.
I added my assembly in GlassMapperScCustom:
public static IConfigurationLoader[] GlassLoaders(){
var attributes = new AttributeConfigurationLoader(new[] { "Company.Framework.Websites.Corporate", "Company.Framework.Core", "Company.Framework.Common" });
return new IConfigurationLoader[] { attributes };
}
When I look into b.GlassContext.TypeConfigurations all my models are there.
I figured it could be a language issue because the site is in dutch and maybe the wrong language would be resolved incorrectly. This was also not the case.
I disabled WebActivator and added the GlassMapperSc.Start() in my Global.asax Application_Start method.
We are also using Autofac as DI framework. But without it, it still isn't working as you can see above. Also when I create my own custom models without TDS code generation the result of GetCurrentItem<T> is null.
Does anyone have an idea how I can fix this?
Did you check your Sites.config and the default language for this website? There could be a difference between the language which is defined in your Sitecore languages folder and your configuration.
I had a similar problem with one of my projects where I changed the Sitecore.Context.Language to "nl" instead of "nl-NL". The glass mapper will return null, but Sitecore.Context.Database.GetItem will return an object in this case.
Most of the times it is a language issue. The mapper returns a null object when you do not have versions in the current or given language.
What can be confusing is that Sitecore.Context.Database.GetItem returns an object, even if it does not have a version in the current language. Be sure to check that item.Versions has any.
Some things you may try (this didn't fit in the comments field)
1) Confirm that the related fields in the Sitecore Item object contain values (so Sitecore.Context.Item for your "c" var and Sitecore.Context.Database.GetItem("path") for your "d" var)
2) Try to encapsulate the GetItem/GetCurrentItem call in a VersionCountDisabler, like this:
T01_Homepage model = null;
using (new VersionCountDisabler())
{
var context = new SitecoreContext();
model = context.GetItem<T01_Homepage>("path");
}
// Do you have data in model now?
3) Try to encapsulate the same call with a SecurityDisabler. Just to confirm it's not a security issue.
4) If you still don't know what it is, please update your question with some (simplified) code for your model.

TYPO3 4.5 extbase test backend module

I search for a way to test my extbase-extension. I work with two different templatepaths for front- and backend.
module.myext{
view {
templateRootPath = myext/Resources/Private/Backend/Templates/
partialRootPath = myext/Resources/Private/Backend/Partials/
layoutRootPath = myext/Resources/Private/Backend/Layouts/
}
}
The backendmodule works without any problem, but my test will not get the different templatepath. If i write the view.templateRootPath to config.tx_extbase in the ext_typoscript_setup.txt it works, but in this case all my frontendtests do not work any more. The simplest way to resolve this issue is to merge the templatepaths and work with only one, but there must be a way around this solution.
Does somebody has an idea?
Did you statically include the extension setup in your root page?
Then the backend module should work as long as you include it in the web tools and select the root page in the page-tree...
If you include your module in the user tools, this is a known bug. See here:
http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2011-December/011174.html
You could put this code in your *ext_localconf.php*:
if (TYPO3_MODE === 'BE') {
t3lib_extMgm::addTypoScript($_EXTKEY, 'constants', $tsIncludeConstants);
t3lib_extMgm::addTypoScript($_EXTKEY, 'setup', $tsIncludeSetup);
}
where $tsIncludeXXis your TS code to include the configuration files of your extension:
$tsIncludeConstants = "<INCLUDE_TYPOSCRIPT: source=FILE:EXT:$_EXTKEY/Configuration/TypoScript/constants.txt>";
$tsIncludeSetup = "<INCLUDE_TYPOSCRIPT: source=FILE:EXT:$_EXTKEY/Configuration/TypoScript/setup.txt>";
This is kind of brute force, but it works...

How to programmatically update references in sitecore?

I have 2 templates: ArticleItem and ArticlePageItem, the ArticlePageItem has a ReferenceField 'Content.Reference' that links to an ArticleItem. Below is the code to create an article:
Item articlePageItem = articlePageParentItem.Add(articleItem.Name, new TemplateItem(master.GetItem(ConstantString.ArticlePageTemplateID)));
using (new UserSwitcher(Sitecore.Context.User))
{
articlePageItem.Editing.BeginEdit();
articlePageItem.Fields["Content.Reference"].Value = articleItem.ID.ToString();
articlePageItem.Editing.EndEdit();
}
But after I execute the code above, I cannot get the ArticleItem reference through Globals.LinkDatabase.GetReferences(articlePageItem), even though I use Globals.LinkDatabase.UpdateReference(articlePageItem).
Does anyone know how to implement this?
[Update]
Below is our environment:
We have a website based on Sitecore, and we're developing another system aims to simplify the article management. We use .NET 4 & ASP.NET MVC 3 to implement this system, and reference Sitecore.Kernal.dll & Sitecore.Client.dll to our project. But our sitecore version is 6.2 which is incomplatible with .NET 4, so I just copied part of the configurations. I think it maybe dues to the incomplete web.config.
If you are executing the above code you should also consider publishing the item changes.
This can be done by using the following code snippet:
// publish all changed content
Database webDatabase = Sitecore.Configuration.Factory.GetDatabase("web");
PublishOptions publishOptions = new PublishOptions(masterDatabase, webDatabase, PublishMode.Smart, Sitecore.Context.Language, DateTime.Now);
publishOptions.RootItem = vacatureRoot;
publishOptions.Deep = true;
Publisher publisher = new Publisher(publishOptions);
publisher.Publish();
Where 'vacatureRoot' is the root -> in your case articlePageParentItem
After publishing the references should be set automatically and should be retrievable by using the normal way of getting Fields.
It looks like you are using a ReferenceField and therefore your code should look something like this:
ReferenceField rfRef = Sitecore.Context.Item.Fields["Content.Reference"];
if(rfRef != null && rfRef.TargetItem != null)
{
//Your logic here
}
Answer for comment:
I think you could best use the following code fragment ->
Sitecore.Globals.LinkDatabase.UpdateReferences(articlePageItem);
I think this will do what the name says, update the references for this item.
Hope this will work for you!