Vues de base
- Catalogue produits
/shop - Blog
/blog - Promotions
/promotions
Créer une page listant les produits en promotion.
Ajoutez un champ field_on_sale (booléen) au type Product.
Créez la vue promotions avec :
/promotionsNos promotionsfield_on_sale = 1Ajoutez un bloc “Promos” pour le sidebar :
View name: PromotionsMachine name: promotionsShow: Content of type ProductCreate page: Yes Path: /promotions Title: Nos promotions Display format: Grid of teasers Items per page: 9Dans l’éditeur :
Content: On Sale (field_on_sale) = TrueContent: Price → Ascending+Add → Block :
Afficher les produits créés dans les 7 derniers jours.
Utilisez le filtre Content: Authored on avec l’opérateur >= et la valeur relative -7 days.
Créez une vue ou ajoutez un display block
Filter Criteria → Add → Content: Authored on
Configuration :
Operator: Is greater than or equal toValue type: An offset from the current timeValue: -7 daysPager : 4 items
Sort : Content: Authored on DESC
Créer une page /products-by-brand/{brand} qui affiche les produits d’une marque.
products_by_brandfield_brand/products-by-brand/nike → “Produits Nike”/products-by-brand/adidas → “Produits Adidas”Add view :
products_by_brand/products-by-brand/%Contextual Filters → Add → Content: Brand (field_brand)
Configuration :
When filter value is NOT available: Display a summary
When filter value IS available: Specify validation criteria: Validator: Taxonomy term Vocabularies: Brand Validate: Term name converted to Term ID Transform dashes: Yes
More: Override title: Yes Title: Produits {{ arguments.field_brand }}% dans l’URL capture le nom de la marqueCréer un tableau administratif listant tous les produits avec actions.
/admin/productsAdd view :
admin_products/admin/productsFormat → Table (sortable)
Fields (dans l’ordre) :
Content: Product Image → Formatter: ThumbnailContent: Title → Link to contentContent: SKUContent: PriceContent: Category → LabelContent: Stock → DefaultContent: Edit linkContent: Delete linkTable settings :
Filter Criteria exposés :
Access → Permission → Administer content
Exposer les produits via une API REST JSON.
/api/productscurl http://your-site.ddev.site/api/products | jqÉditez la vue products_catalog
+Add → REST export
Configuration :
/api/productsFormat → Serializer → JSON
Show → Fields
Fields :
Content: ID (nid) Administrative title: id
Content: Title Administrative title: title
Content: Price Administrative title: price
Content: Category Formatter: Entity ID Administrative title: category_id
Content: Product Image Formatter: URL to image Administrative title: image_urlSave et tester :
curl "http://tailstore.ddev.site/api/products" | jqRésultat :
[ { "id": "1", "title": "Nike Air Force 1", "price": "119.99", "category_id": "5", "image_url": "/sites/default/files/products/nike-af1.jpg" }]Afficher les avis clients sur la page produit.
Créez un type de contenu Review avec :
field_rating (Number, 1-5)field_review_text (Text long)field_product_reference (Entity Reference → Product)Créez quelques avis de test
Add view :
product_reviewsContextual Filters → Add :
Ou ajoutez d’abord une Relationship :
Content: Référenced Content (field_product_reference)Puis Contextual Filter :
Content: ID (from Relationship)Fields :
Content: Rating Rewrite: {{ field_rating }}/5 ★
Content: Review Text
Content: Author
Content: Authored on Format: Temps relatif (il y a 2 jours)Sort : Authored on DESC
Place le bloc avec visibilité : Content type = Product
Vues de base
/shop/blog/promotionsBlocs
Fonctionnalités
Avancé
# Exporter toutes les vuesdrush cex -y
# Commitergit add config/sync/views.view.*.ymlgit commit -m "feat: add all views for TailStore"À la fin de cette étape, vous savez :
Passez à l’Étape 5 - Navigation & Blocs pour créer les menus, configurer les régions et gérer les permissions.