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

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.

Related

How to display all data from a paragraph field in views (Drupal 7)

I am currently a caretaker for a Drupal 7 website and I can't figure out how to group paragraph items in views. I have created a content type Products and one of the fields is called product variation which is field type paragraphs. I have created a paragraph bundle for that field.
Then I created a view to show the products on the front page. To display the paragraph fields I created a content relationship. When I open the relationship option and select delta to display one it only shows one and I can't get data from the others. If I select delta to display all it shows like in the image below (Current view displays like). The goal is shown on the same image. Could someone help me solve this:
My setup on the fields I want to display in the view are setup like this
`content-type: Products
product name - field type: Node module element
proudct image - field type: Image
product variation - field type: paragraph
paragraph bundle: product variations
color (Term reference)
view:
Display: product name, product image,product variation
Relationship: Content: product variation (field_product_variation)
Hopefully, someone can help me solve this problem.

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 Views: Term filter with relationship

I have 2 content types:
One content type is named: "Offer". This content type includes a reference field to choose one hotel, form the other content type: "Hotel". The content type "Hotel" has a term reference field called "sports".
Now I want to build a view filter, which uses the content type "Offer", and uses the sport terms which i get over the hotel relationship.
I already tried to create a relationship on my own:
Reference to the hotel
Added taxonomy field sport with the relationship to the hotel, which i created before
Then i added the taxonomy field to my filter, and selected the Relationship in the drop down menu.
But this doesn't work at all.
Anyone can help me?
Regards M.
The view should initially return the hotel content type.
Add a optional relationship to the offer reference field, this will give you access to the fields in the offer content type. Once you've done that you should be able to add whatever field you want as an exposed filter.
To get the sports working you may have to add the relationship Has taxonomy term in order to get what you want and then add the term as an exposed filter.
Use the patch over at https://www.drupal.org/node/1492260 for autocomplete.
A select list should work the same way as with this patch, but it's built-in. In either case, you have to enable it by checking the checkbox in the content type field config.

How display article from category and show it in block

I have created a content type which has some fields, and I want these fields to be displayed as a block.
I need to display some article like 5 articles from category called sport news only.
How can I do that in drupal 7?
You need to install Views
https://drupal.org/node/1960048
Then create a new view as a block.

Create views from field values Drupal-7

So if I understand correctly I have will a few content types "Category", "Sub Category", "Product", "Images" I am just not sure how I will associate the content types with each other to build views. So based on my structure below: I would create a Category name "Home" with the "Category" type. The category would have a view that shows all Sub Categories that are associated with this view "Category". This is my question: When I go to create my new Sub Category "Furniture" how do I associate it with the view that is on my "Home" Category page? And so on with the Products which will all belong to sub category and the images will all belong to a product. Can I use a custom field that the user adds a string?
Home (category)
-Furniture (sub category)
-Sofa(product)
-images
-Lamp(product)
-images
Outdoors(category)
-Deck Furniture(sub category)
-Table(product)
-images
-Fire-pit(product)
-images
I am sure this was confusing so if anyone has questions please ask. Any help would be amazing. Thanks in advance.
Your question is a little confusing because it seems that there are two parts to it that aren't clearly defined.
If you're looking to relate content to each other, check out the References module.
As for creating the display you're looking for, the Views module is likely what you're looking for. There is also a Views Hierarchy module which you may need but is currently unavailable for Drupal 7.

Resources