I'm currently experimenting with Hybris in preparation for a project and I have some trouble making Impex do what I want to do.
The example electronics store defines the CMS actions for the ProductAddToCartComponent
INSERT_UPDATE ProductAddToCartComponent;$contentCV[unique=true];uid[unique=true];name;actions(&actionRef);&componentRef
;;AddToCart;Product Add To Cart;AddToCartAction,PickUpInStoreAction,ShareOnSocialNetworkAction;AddToCart
My goal is to remove the ShareOnSocialNetworkAction from the AddToCart element.
I've tried several variations of REMOVE, which mostly resulted in the AddToCart element itself being deleted, as well as INSERT_UPDATE with only the actions I wanted to retain, which didn't have any effect at all.
How can I remove only the ShareOnSocialNetworkAction from the AddToCart component?
Have you tried INSERT_UPDATE with replace mode with adding all the actions but the one you want to remove ? :
UPDATE ProductAddToCartComponent;$contentCV[unique=true];uid[unique=true];actions(uid,$contentCV)[mode = replace];
;;AddToCart;AddToCartAction,PickUpInStoreAction;
Or using remove mode this way :
UPDATE ProductAddToCartComponent;$contentCV[unique=true];uid[unique=true];actions(uid,$contentCV)[mode = remove];
;;AddToCart;ShareOnSocialNetworkAction;
Hope this helps
Related
I am trying out JHipster (version 6.4.1) using a Monolith and disk-based H2 database. I have created some entities in JDL and have the basic CRUD webpages working. Now that I feel comfortable with the process, I want to add fields and rename others. I figured I could simply update the JDL, re-import the JDL, start the application, and see the result of my changes. What I see is ValidationFailedException from Liquibase and the application throwing HTTP 500 errors due to database problems.
I have looked all over for guidance on the proper process for handling this seemingly common development scenario. Most of the places I have looked for guidance (such as https://www.jhipster.tech/creating-an-entity) discuss importing JDL as a one-time-only operation and do not discuss how to incrementally change and import the JDL.
I have tried a number of suggestions as seen on SO, such as not overwriting the changelogs, doing a liquibase:diff, and adding that to master.xml. This still causes the ValidationFailedException. In the master.xml I see the comment <!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here --> which leads me to believe that JHipster should be doing the heavy lifting, but I am just missing a step.
I am by no means a JHipster nor a Liquibase expert, but I want to learn. How I can perform simple entity updates without a huge hassle?
[Update with more detail]
After re-importing the updated JDL, I have managed to get rid of the DB Validation Errors by blowing away the database with rm -rf target/h2db/db.
I'm happy with my changes and feel like a commit is in order. What I see is
master.xml is unchanged
the changelog from the first JDL import has been modified to include the updates I made
If I understand how liquibase works, I would have expected
None of the existing changelogs would be touched
A brand new changelog file would be created that contained just the JDL changes I made this round
master.xml to have changed only in that it would contain an additional changelog entry, pointing to the file created in item 2
Am I misinterpreting how Liquibase represents evolution of the DB schema?
It appears that the page you referenced does have some instructions for updating entities. Farther down the page I saw this:
Updating an existing entity
The entity configuration is saved in a
specific .json file, in the .jhipster directory. So if you run the
sub-generator again, using an existing entity name, you can update or
regenerate the entity.
When you run the entity sub-generator for an existing entity, you will
be asked a question ‘Do you want to update the entity? This will
replace the existing files for this entity, all your custom code will
be overwritten’ with following options:
Yes, re generate the entity - This will just regenerate your entity.
Tip: This can be forced by passing a --regenerate flag when running
the sub-generator
Yes, add more fields and relationships - This will
give you questions to add more fields and relationships
Yes, remove fields and relationships - This will give you questions to remove
existing fields and relationships from the entity
No, exit - This will exit the sub-generator without changing anything
You might want to
update your entity for the following reasons:
You want to add/remove fields and relationships to an existing entity
You want to reset your entity code to its original state
You have updated JHipster, and would like to have your entity generated with
the new templates
You have modified the .json configuration file (the
format is quite close to the questions asked by the generator, so it’s
not very complicated), so you can have a new version of your entity
You have copy/pasted the .json file, and want a new entity that is
very close to the copied entity
How multiple categories can be removed and added to a product using impex in HYbris
in a single row
Something like:
REMOVE CategoryProductRelation;target[unique=true](code,$catalogVersion);source[unique=true](code,$catalogVersion)
;xyz;cat1,cat2,cat3
You may also try :
$ProductCatalogVersion=catalogVersion(catalog(id[default='$catalogID']),version[default='$catalogVersionID_STAGED'])[unique=true,default='$catalogID:$catalogVersionID_STAGED']
$CategoryCatalogVersion=catalogVersion(catalog(id[default='$catalogID']),version[default='$catalogVersionID_STAGED'])[unique=true,default='$catalogID:$catalogVersionID_STAGED']
$superCategories=supercategories(code,$CategoryCatalogVersion)
INSERT_UPDATE Product;$ProductCatalogVersion;code[unique=true];$superCategories[mode = remove]
;;xyz;cat1,cat2,cat3
Hope this helps
Remove it 1 line each.
REMOVE CategoryProductRelation;target(code,$catalogVersion)[unique=true];source(code,$catalogVersion)[unique=true]
;xyz;cat1
;xyz;cat2
;xyz;cat3
When use jhipster entity generator by console a question like follow allows to change the display field on frontend:
When you display this relationship with AngularJS, which field from
'user' do you want to use? (id)
It is possible to make the same with jdl?
Edited
Ok, It appears that nobody has this problem, or maybe there aren't anybody in home?
So, I'm going to explain it. Let's suppose this scenario:
Create two (or more) entities with relationship with the console.
Choose a different field from id to manage the front-end.
Test the project (it works fine).
Export the model to jdl file
Import the jdl file, with no changes, in another new project.
Boom! The UI comes back to Id reference.
Is there any option to resolve it, or is this resolve in other tools like uml import? Future plans?
Resolved
Reading the documentation in detail, I've found a solution:
"Declare the field you want to use to display a relationship in AngularJS.
To do that you must add the field name between () after the injected field name."
Resolved
Reading the documentation in detail, I've found a solution:
"Declare the field you want to use to display a relationship in
AngularJS.
To do that you must add the field name between () after the injected
field name."
I'm trying to create a content part in Orchard that will perform a request to a web server and display the results of the request. The problem I'm running into is that my part requires no user input and thus I have left the part and part record classes empty. I have a Migrations.cs file that adds a description to the part and makes it attachable as well as creates a content item with the part attached to it. When I go to create a new instance of my content type it tries writing to the database and fails. How do you create a content part in orchard that doesn't try to save to the database? Thank you.
The actual error I receive is:
null id in Orchard.ContentManagement.Records.ContentTypeRecord
I'm pretty sure you don't need to create new table since there are many parts which don't have any in Orchard. Try to remove MyCustomPartRecord.cs and change MyCustomPart.cs
public class MyCustomPart : ContentPart<MyCustomPartRecord>
to
public class MyCustomPart : ContentPart
Then just add driver and view and you should be good without extra tables ... In theory :D
The answer to my problem is even when your part ins't actually saving anything in the database you still need to include a table for the part so it can store the id. I just added the following to my Migrations.cs file and it fixed the problem.
SchemaBuilder.CreateTable("MyCustomPartRecord",
table => table
.ContentPartRecord()
);
Hi once again :) My next question about Orchard CMS looks trivial but..
I have my custom NewsModule with NewsItem type which consists of TitlePart, BodyPrt, and my custom NewsPart. NewsPart is based on NewsPartRecord.
Now I have to extend my NewsItem document type with Image. So far I found that there are ImagePart and MediaLibraryPickerField.
ImagePart stores width and heihgt of image, so I think it is something for internal use.
The next one is MediaLibraryPickerField. After googling for a while, I found that I can extend my NewsPart using WithField() method.
But! First question here: when I'm configuring Page type with Admin UI, I can add field to the type. But using Migrations I can't add field to NewsItem, only to NewsPart.
The second question here. MediaLibraryPicker allows me to select any type of file from library, image, text, zip or any other. And this is not what I actually need.
So, what are the best practices in Orchard to extend Items with icons?
thanks.
You can add fields to NewsItem, it just requires a different type of definition. It confused me too as it's not as intuitive as you'd like it to be.
To add parts you are using AlterTypeDefinition.
this.ContentDefinitionManager.AlterTypeDefinition(
"NewsItem",
cfg => cfg.WithPart("NewsPart"));
But to add fields you have to also use AlterPartDefinition and specify the NewsItem not the NewsPart.
this.ContentDefinitionManager.AlterPartDefinition(
"NewsItem",
builder =>
builder.WithField(
"NewsImages",
fieldBuilder =>
fieldBuilder.OfType("MediaLibraryPickerField")
.WithDisplayName("News Images")
// Allow multiple images
.WithSetting("MediaLibraryPickerFieldSettings.Multiple", "true"))
Considering second question, MediaLibraryPickerField has option to display only selected types/parts.
.WithSetting(MediaLibraryPickerFieldSettings.DisplayedContentTypes="Document,Video")
If you need new media type you have to create new ContentType with Stereotype "Media", it also needs "MediaPart" and part that defines metadata for that type. You can look at how Document or Video is defined for sample code.