Hybris export data of two joined tables using flexible search - sap-commerce-cloud

I am new to Hybris. what I am trying to do is Export Data (code from product and name from catalog) of two joined tables using flexible search. I Wrote a query but cant understand how use it as impex export.
This will be My Query
SELECT {p:code},{c:name} FROM {product AS p JOIN catalog AS c ON {p:catalog}={c:pk}}
WHERE {p:description} LIKE '%meat%'
How write Impex header for this export ?

Try this
INSERT_UPDATE Product;code[unique=true];catalogVersion(catalog(name[lang=en]));
"#% impex.exportItemsFlexibleSearch(""SELECT {p:pk} FROM {product AS p} WHERE {p:description} LIKE '%meat%'"");"
For export with flexible search, you need to select only PK.
To get the catalog's name from the product model, you need to get it from
product -> catalogVersion -> catalog -> name.
Note that name in the catalog is localized, hence I put "lang" there, change en to any language code that you use.

Related

How to get the view definition in SQL server using NodeJS through code

I am having a requirement where I need to change the definition of view based on the user requirement.
Suppose if the definition of the view is like this:
create view view_name as select tableA.col_3 as colTabA3 from tableA ,tableB where 1=1;
now if the user has a requirement such that colTabA3 column should have the data from tableB.col_3 then I need to change the view definition to
create view view_name as select tableB.col_3 as colTabA3 from tableA ,tableB where 1=1;
I am going to show some UI to the user to give the expression for colTabA3 and when he gives the expression then I will have to get the definition of the table, modify that definition and add the new expression.
SELECT OBJECT_DEFINITION (OBJECT_ID('${view_name}')) AS ObjectDefinition;
this query is giving the view definition, I can connect to the database through code and run this query to get the view definition.

How to query the "Props" table from Flexible Search?

Inside my code I have the primary keys of some page components in Hybris and I have to find all their attributes (properties like title, content etc.)
I can query the "Props" table using an SQL query, but I'm not sure how to find the equivalent in Flexible Search, since querying the database directly is not recommended.
Is there any other simpler way to retrieve all the properties of a component having just the primary key?
What you can do is retrieve the required component using it's primary key. Example:
select {pk} from {SimpleCMSComponent} where {pk} ='8796093056060'
Usually flexible searches are used in DAO classes(Platform example: DefaultProductDao).
When this flexible search is run by the flexible search service you get a ComponentModel. Please see below a groovy script I just created in order to exemplify how to print the ID of a Component retrieved based on its PK(In the same way by using getters you can get the title, content, etc.. ):
import de.hybris.platform.cms2.model.contents.components.SimpleCMSComponentModel;
def flexibleSearchService = spring.getBean("flexibleSearchService");
SimpleCMSComponentModel simpleCmsComponent = flexibleSearchService.search("select {pk} from {SimpleCMSComponent} where {pk} ='8796093056060'").getResult().get(0);
println(simpleCmsComponent.getUid())
I believe though that the best practice in case of CMS Components is to use their IDs instead of PK.

Hybris: Mark products with no super-category as inactive

We are performing catalog clean up task and require all products which have no super-category to be marked as inactive. Such products can be seen lying directly under the catalog root in PCM and not under any super-category.
I want to get the list of all such products and via impex I can update the approvalStatus of all such products as 'check', so that they are no longer visible to user at storefront.
Any help is greatly appreciated!
Get your target products
The idea is to extract all products from 'YOUR_CATALOG_ID' except (not in) all the products that have at least one category.
You could use this flexible search:
select {p.pk}
from { Product as p join CatalogVersion as cv on {p.catalogversion}={cv.pk}
join Catalog as catalog on {cv.catalog}={catalog.pk} }
where {catalog.id}='YOUR_CATALOG_ID'
and {cv.version}='Staged'
and {p.pk} not in ({{
select {p.pk}
from {Product as p join CategoryProductRelation as pc on {p.pk}={pc.target}
join Category as c on {pc.source}={c.pk}
join CatalogVersion as cv on {p.catalogversion}={cv.pk}
join catalog as catalog on {cv.catalog}={catalog.pk}}
where {catalog.id}='YOUR_CATALOG_ID'
and {cv.version}='Staged'
}})
You should replace "Product" with your custom Product Type if your data model has been customized.
Update products approvalStatus
As second step you could create an impex in order to change the approvalStatus:
INSERT_UPDATE Product;code[unique=true];approvalstatus(code);
;target_product_pk;check;

Kentico - Display List of related articles based on categories/subcategories

I have many articles and each is assigned under different categories/subcategories.
What I'd like to do is at the end of individual article, I'll display a list of Related Articles based on the category(s) that the current article is placed. I've added a Repeater but don't really know what to put in Content Filter/Category Name to achieve this. Hope it's not so complex. Thanks for your input!
You can achieve this in Portal without touching the code if you need to. The following steps are how you can achieve it (though they are rough and ready!)
In your Article page type, create a new query. This queries job is going to be to link the existing Document to any others that share the exact same categories. Your query should look like this:
SELECT ##TOPN## ##COLUMNS##
FROM View_CMS_Tree_Joined rel
INNER JOIN CMS_DocumentCategory relcat ON relcat.DocumentID=rel.DocumentID
INNER JOIN CMS_DocumentCategory doccat ON relcat.CategoryID=doccat.CategoryID
WHERE ##WHERE##
AND rel.DocumentID doccat.DocumentID
ORDER BY ##ORDERBY##
Now, replace you Repeater with a Repeater with custom query. In the setting, choose your newly created query for the Query name field using the selector control.
Set the WHERE clause to be doccat.DocumentID={% CurrentDocument.DocumentID #%}
Pick the appropriate transformation and you should be good to go.
This method requires an exact category match, so Categories > Cars > Mazda will not match to Categories > Cars.
Hopefully this is of some use :)
This article may give you some idea on creating a filter, but I don't think this is exactly what you want. It does show you have to get the documents thru the API.
You could do a custom query, something like this
SELECT *
FROM dbo.View_CMS_Tree_Joined vctj
WHERE vctj.DocumentID IN
(
SELECT DocumentID
FROM CMS_DocumentCategory
WHERE CategoryID IN
(
SELECT CategoryID
FROM CMS_Category
WHERE dbo.CMS_Category.CategoryName = 'Name Here'
)
);

SharePoint FullTextSqlQuery Search FREETEXT with multiple columns

I have a custom FullTextSqlQuery used to retrieve some specific pages.
The query contains multiples FREETEXT predicates and gives unusable rankings, which is expected behavior according to MSDN, the query should contain only one FREETEXT
The basic query that gives expected results is
SELECT Title, ACLanguage, ACContent, ACCategory, ACKeywords, ACID
FROM scope()
WHERE (FREETEXT(Title,'text') OR FREETEXT(ACContent, 'text') OR FREETEXT(ACSubtitle, 'text'))
The documentation says this query can be rewritten to use a single predicate using a group alias, but it isn't clear about syntax. I tried multiple statements ending with :
SELECT Title, ACLanguage, ACContent, ACCategory, ACKeywords, ACID
FROM scope()
WHERE WITH(Title, ACSubtitle, ACContent) AS #SearchColumns FREETEXT(#SearchColumns,'text')
But all my attemps ended with a QueryMalformedException
How should this query be written ?
Specify multiple columns like this:
SELECT Title, ACLanguage, ACContent, ACCategory, ACKeywords, ACID
FROM scope()
WHERE (FREETEXT((Title,ACContent,ACSubtitle),'text'))
Or, shorthand for searching all full text indexed columns:
SELECT Title, ACLanguage, ACContent, ACCategory, ACKeywords, ACID
FROM scope()
WHERE (FREETEXT(*,'text'))
(source)

Resources