How to change sub-category to root category in CommerceTools - commercetools

I need to change a sub-category of my project so that it is located at the root of the categories and not like now that it is a sub-category of another.
I have tried the action "changeParent", but it requires me to put the id of another category and does not support giving it an empty or null value.
I would not like to have to delete the category as it already has associated products.
Is there any other way to do it?
Thanks in advance.

It's not possible to unset a parent category.
But you could recreate only the category you want to become a root category and change the parent of all children to the newly created category. But still you would have to assign these products to the new category.
As a general advice I would always create an explicit root category and use this as the entry point in your application. First you could circumvent in this case the limitation to unset a parent category. And you can even have multiple trees for different applications (e.g. mobile, desktop) or prepare an updated category tree (e.g. winter/summer season)

Related

How do I get the lookup objects field history tracking to show up in the related list of the child object?

I can see in my org that someone has a lookup to opportunity and can get the history tracking of opportunity in the related list of the custom object.
I tried to do it for another custom object and it didn't work.
To replicate this in a scratch org I created two custom objects custom object 1 and custom object 2.
Custom object 2 has a lookup to custom object 1 and I made a field "status" on 1 and turned on the field history tracking on it. While creating the objects object 1 didn't have field history tracking turned on and I turned it on but in the real org its turned on from what I can see.
Here is what I can see. As I have field history tracking turned on for both 1 and 2 I can see history object for both in their respective page layouts under the related tabs.
What I want to see is Custom object 1 's history on custom object 2 under the related list but I can't get it to show up. I can see that people have been successful in my org in doing so.

How do I create and save a set/array of objects for a given Core Data entity?

I have an app that will ideally compare luxury restaurants and their respective dishes against each other. This means I have a Core Data entity called Restaurant with attributes like restaurantName, location, averagePrice, and foodType. I have a second Core Data entity called MenuItem with attributes like foodName, caloryCount, price, and rating.
Since the goal is to compare, say, two steakhouses and their filet mignons on calories/price/rating, I'd really like to take a preloaded list of MenuItem objects I have (an array called selectedMenuItems) and somehow save that as an attribute of the Restaurant entity so that each individual restaurant will have an instance of those menu item objects attached to it (after which the user could edit the calories/price/rating for each menu item on a restaurant by restaurant basis). In the most ideal scenario, if anything was added or subtracted from the selectedMenuItems array of objects it would be reflected across all individual restaurants.
What I've tried so far:
1.) Many-to-many relationship between Restaurant and MenuItem
As you can probably guess from my above description, this didn't work out how I wanted it to since it only connected each restaurant to the selectedMenuItems array, and any alterations made in a restaurant propagated through the relationship to the array (this was a fundamental misunderstanding of relationships, on my part).
2.) Create an attribute of type Transformable in Restaurant to hold the selectedMenuItems array
This looked like it was going to work for a moment. As I said, I created an attribute called menuItems in my Restaurant entity of type Transformable, and then in the view controller for each restaurant's detail view (the view controller that displays the menuItems is an additional navigation step) I added the following inside of viewDidLoad():
// The selected Restaurant is passed from the prior screen to restaurant
restaurant.menuItems = selectedMenuItems as NSObject?
Which resulted in seemingly what I needed, except for the fact that if I made any changes to the selectedMenuItems array, it would cause the app to crash with the console readout 'NSInvalidArgumentException', reason: '-[Restaurant encodeWithCoder:]: unrecognized selector sent to instance.
3.) Break apart the selectedMenuItems array of objects into matched arrays of properties
After doing some experimenting with 2.), it appeared as though having an array of objects was the issue. Because of this, I iterated through selectedMenuItems and stripped out the properties into their own arrays (foodNameArray, caloryCountArray, priceArray, etc.). After that, I assigned each of those to newly created attributes of my Restaurant entity:
restaurant.foodNames = foodNameArray as NSObject?
restaurant.caloryCounts = caloryCountArray as NSObject?
restaurant.prices = priceArray as NSObject?
Now, this was already looking very dodgy and prone to catastrophic failure. It did, however, work pretty much how I wanted it to. The issue here was that any changes to selectedMenuItems (like adding/removing a new object) didn't pass through to my restaurants after the first load. This is in contrast with 1.) where the changes propagated from the restaurants to selectedMenuItems (bottom to top) compared to 3.), where I want the changes to flow top to bottom.
Given the above descriptions, does anyone have advice on how I can get the functionality I'm looking for?
Rather than a many-many relationship, I would use three entities:
Restaurant, as you currently have;
Dish, which represents the generic menu item, such as "Filet mignon" or "Rib-eye"; and
MenuItem, which is a particular Dish served by a particular Restaurant.
Because Dish is generic, it would have only one attribute foodName (though you might want others). MenuItem would have attributes caloryCount, price, rating.
Since each MenuItem represents a particular dish served by a particular restaurant, it would have "to-one" relationships to Restaurant and Dish. For each relationship, the inverse would be "to-many": a Restaurant will serve many MenuItems, and a Dish could feature in many MenuItems.
You can then preload the list of Dishes, from which users can select those which are served by a particular restaurant. You can then create corresponding MenuItems and can presumably let users record calories/price/rating. If the user deletes a MenuItem, the corresponding Dish is unaffected, so will be available for other existing and/or new Restaurants. If the user wants to add a MenuItem for which there is no existing Dish, you can add a new Dish, which will then be available for any subsequent MenuItems.

Drupal 7 - assign several products (items) under each category

In D7, I have created a taxonomy (say categories) and set some terms (say category 1, category 2 etc) within it. I have also created a 'View' based on the 'categories' taxonomy and show the categories (category 1, category 2 etc) within the sidebar (block) of the website. Just let me know how can I assign several products (items) under each category so that site visitors can see the product lists on clicking a category from the sidebar. Basically I want to develop a catalogue based website to show products/items under each category.
Kindly help me in this regard.
Good morning,
If you have not done yet, you have to create a custom content type (Structure > Content Types > Add content type) and add as many fields as you need. When you are done, you have to add an extra field named Category, of type "Taxonomy Term Reference" (or something similar, I don't know exactly). You can configure this field so that you can assign several categories to a single product.
Once your contents are created, if you access the taxonomy term's URL, all contents assigned to that category should be displayed. However, you could also define a custom view that receives the name of the category as a parameter in the URL, and displays all contents in this category in a grid, table, list, ... whatever.
Hope it helps.

How to know the link clicked by the user to set the breadcrumb using views in drupal 7?

I'll try to explain my problem giving a little context first.
I'm building a catalog of products and to categorize them I'm using a taxonomy tree with 4 sublevels. Each product can be related with one or more subcategories.
I used views to navigate the taxonomy tree to access the products related with each subcategory. To manage the breadcrumbs in here I redefined the hook_breadcrumb() function on my template.php and this is working perfectly.
The problems start here: when I get to the last level of subcategories I have the respective products and when I click one of the products it will enter the node page of that product. At this time I lose my breadcrumb trail because I entered the node. I could get the taxonomy tree of that product to build the breadcrumbs but the problem is that the product can be related with multiple subcategory terms.
So, in order to solve this problem I think that I need to know from wich path trail the visitor arrived to the product. In other words, I need to know the last taxonomy subcategory that the user visited to enter a specific product so that I can build the breadcrumbs correctly with that information.
So, can someone help me on how to know the path that the user was before entering a node?
Thanks in advance!
You can check http://drupal.org/project/cookiecrumbs a recent project which uses browsers history to show breadcrumb

Show custom object in related list under page layout

I have been trying this whole day but cant figure out... I have custom object called Dev which has many to many relationship with Accounts... I want this object Dev to show under related list of page layout of account... But it is not showing there how can i add that to related list?
Assuming you have a lookup relation from Account to Dev and also a lookup from Dev to Account (creating your many-to-many), then this will work fine.
Try re-creating your lookup relationship from Account to Dev. Then make sure that you add the related list and add to the page layouts in steps 5 & 6:
Step 5. Add reference field to Page Layouts (Yes to All)
Step 6. Add custom related lists (Yes)
That's all you need. If, however, your many-to-many relationship is unique or otherwise configured differently (with a junction table, for example) then the above may not work for you.
We always tend to use joining objects for these relationships, obviously you can show the list of joining objects as a related list, and you could display other fields from the dev object by use of formulae.
One thing we've tended to do is create an inline VF page which can then show all of the objects related to the current record.

Resources