How to get PrestaShop employee language ID - get

How to get PrestaShop employee id lang? With default language I know:
$defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT'));
$languages = Language::getLanguages();
$iso = Language::getIsoById($defaultLanguage);
But how to get employee lang?
I tried this:
$cookie = new Cookie('ps');
$defaultLanguage = $cookie->id_lang;
$languages = Language::getLanguages();
$iso = Language::getIsoById((int)($defaultLanguage));`
But it does not work.

You can get it within an AdminController child objects:
$this->context->employee->id_lang

Related

Get the names of a dynamic product group with a subscriber in Shopware 6.1

how can I get the names of the dynamic product groups of a product?
Especially the names of that groups. The names are in the table 'product_stream_translation'.
I have a subscriber and have added this Criteria. When I am doing it like this:
$criteria->addFilter(new EqualsFilter('id', $id));
$criteria->addAssociation('streams');
$dynamicProductGroups = $this->productRepository->search($criteria, $context)->getEntities();
I just got back an empty streamEntity.
#streams: Shopware\Core\Content\ProductStream\ProductStreamCollection {#11805 ▼
#elements: []
#extensions: []
}
When I am doing it like this:
$criteria->addFilter(new EqualsFilter('productId', $id));
$dynamicProductGroups = $this->productStreamMappingRepository->searchIds($criteria, $context);
I just got back the Id I put in:
product_stream_mapping
I wonder how I will get the name of the dynamic product group.
With a query I can get all the assign 'product_stream_id's from the table 'product_stream_mapping' like this:
SELECT * FROM product_stream_mapping WHERE product_id =0x000000000000000000123b313030524b
And then get the associated name of the dynamic product group. With is like this:
SELECT psm.product_id, psm.product_stream_id, p.product_number, pst.name
FROM product_stream_mapping psm
JOIN product_stream_translation pst ON pst.product_stream_id = psm.product_stream_id
JOIN product p ON p.id = psm.product_id
WHERE psm.product_id = 0x000000000000000000123b313030524b
How can I get it in the Subscriber?
Do I have to use criteria or do I have to user a repository?
This line is wrong:
$dynamicProductGroups = $this->productRepository->search($criteria, $context)->getEntities();
It won't return dynamic product groups but a product collection. To get a product stream collection (dynamic product groups) replace it with:
/** #var ProductEntity $product */
$product = $this->productRepository->search($criteria, $context)->first();
$dynamicProductGroups = $product->getStreams();
Then you can read the names of the streams with:
$names = array_values(
$dynamicProductGroups->map(fn (ProductStreamEntity $productStream) => $productStream->getName())
);

FlexibleSearch using enum in WHERE clause

I am working with Hybris and trying to query all the products that have an approval status of APPROVED within Java code. It should look like below, but I cannot get it to work in either HAC, or in Java code.
What is the correct way to do it?
SELECT {p:pk} FROM {Product as p join EnumerationValue as enum on enum.pk = p.approvalStatus } WHERE {enum:code[en]} = 'APPROVED'
Thank you everyone, here is the final answer that works, see comments in other replies for some more questions I have and hopefully some wonderfully wise replies:
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("SELECT {p:").append(ProductModel.PK).append("} ");
stringBuilder.append("FROM {").append(ProductModel._TYPECODE).append(" as p join ")
.append(ArticleApprovalStatus._TYPECODE).append(" as enum on {enum.pk} = {p.").append(ProductModel.APPROVALSTATUS).append("} join ")
.append(CatalogVersionModel._TYPECODE).append(" as cv on {cv.pk} = {p.").append(ProductModel.CATALOGVERSION).append("} } ");
stringBuilder.append("WHERE ( {enum:code} = ?approvalStatus1 or {enum:code} = ?approvalStatus2} and {cv:")
.append(CatalogVersionModel.VERSION)
.append("} = ?version");
final String unapprovedString = ArticleApprovalStatus.UNAPPROVED.toString().toLowerCase();
params.put("approvalStatus1", unapprovedString);
params.put("approvalStatus2", ArticleApprovalStatus.UNAPPROVED.toString().toLowerCase());
You need to use the type of the enum. Also, the enum code is case-sensitive; it depends on what is defined in the items.xml.
SELECT * FROM {Product
JOIN ArticleApprovalStatus ON {Product.approvalStatus} = {ArticleApprovalStatus.pk}}
WHERE {ArticleApprovalStatus.code} = 'approved'
Try to wrap the attributes with {} like this:
SELECT {p:pk} FROM {Product as p join EnumerationValue as enum on {enum.pk} = {p.approvalStatus} } WHERE {enum:code[en]} = 'APPROVED'

Checking user name against LDAP directory without password c# 4.5

I'm working in C#.Net 4.5. I'm using below code to check whether a particular user belongs to the given AD group or not. But, it is not giving results, though I enter valid user details.
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://xyz.com";
DirectorySearcher deSearch = new DirectorySearcher();
deSearch.SearchRoot = de;
string usr = "test1";
deSearch.Filter = string.Format("(&(objectCategory=person)(anr={0}))", usr);
SearchResult result = deSearch.FindOne();
I have tried with below Filter criteria as well, but result is null. Please let me know what went wrong in my code.
deSearch.Filter ="(&(objectCategory=person)(objectClass=user)(sn="+usr+"))"
deSearch.Filter = "(uid=" + usr+ ")";
deSearch.Filter = "(&(objectCategory=person)(objectClass=user)(racfid="+usr+"))"
Try userPrincipalName like this:
deSearch.Filter = "(&(objectCategory=person)(objectClass=user)(userPrincipalName=" + usr + "#*))";
deSearch.PropertiesToLoad.Add("userPrincipalName");
deSearch.PropertiesToLoad.Add("displayName");
SearchResult result = deSearch.FindOne();

Enterprise Keyword not updating in SharePoint 2010

Any idea how to inject values to the Enterprise Keywords column of a List / Doc Lib Item using code?
Tried the following, it didn't give any error, but that column wouldn't update, while the Title did.
using (var site = new SPSite("http://testweb"))
{
using (var web = site.OpenWeb("testsite1"))
{
var list = web.Lists["testlist1"];
var item = list.AddItem();
item["Title"] = string.Format("Injected from code on {0}", DateTime.Now.ToString());
item["Enterprise Keywords"] = "1;#Opera|4eed0518-9676-4afc-be20-9027b3b69e42";
item.Update();
}
}
In this code, Opera keyword has been added previously, I've checked it against the TaxonomyHiddenList list as well using code to extract the correct ID and IdForTerm (the GUID).
What am I missing here?
To add a taxonomy field value the approach is a little bit different. Please try:
TaxonomyField entKeyword = (TaxonomyField)item.Fields["Enterprise Keywords"];
TaxonomyFieldValue term = new TaxonomyFieldValue("1;#Opera|4eed0518-9676-4afc-be20-9027b3b69e42");
entKeyword.SetFieldValue(item,term);
in stead of:
item["Enterprise Keywords"] = "1;#Opera|4eed0518-9676-4afc-be20-9027b3b69e42";

SubSonic 3 doesn't honor schemas for update

I am not running Mike's latest code because it does not build and he didn't update the templates to generate code for the new Load with columns he added. So I am one revision back in the source.
My database has tables in multiple schemas and they would not update properly.
In SubSonic.Query Update.cs I needed to change the constructor. I include some lines for context but I had to change line 122 to add tbl.SchemaName so that the correct DatabaseTable constructor was called and the schema name was carried through.
From this:
public Update(ITable table)
{
_query = new SqlQuery(table.Provider);
_provider = table.Provider;
_query.QueryCommandType = QueryType.Update;
ITable tbl = table;
DatabaseTable dbTable = new DatabaseTable(tbl.Name, _provider, tbl.ClassName);
dbTable.Columns = tbl.Columns;
_query.FromTables.Add(dbTable);
}
To this:
public Update(ITable table)
{
_query = new SqlQuery(table.Provider);
_provider = table.Provider;
_query.QueryCommandType = QueryType.Update;
ITable tbl = table;
DatabaseTable dbTable = new DatabaseTable(tbl.SchemaName, tbl.Name, _provider, tbl.ClassName);
dbTable.Columns = tbl.Columns;
_query.FromTables.Add(dbTable);
}
Is there a question here? This sounds like it needs to go on SubSonic's mailing list or as an issue in SubSonic's github page: http://github.com/subsonic/SubSonic-3.0

Resources