From a292da37c8e27e10e2b7eed982fdd026be6b4441 Mon Sep 17 00:00:00 2001 From: Bachir Soussi Chiadmi Date: Sun, 27 Dec 2020 18:44:26 +0100 Subject: [PATCH] added product variations to home page on pricing --- ...ty_view_display.node.frontpage.default.yml | 12 ++++- ...ity_view_display.node.frontpage.teaser.yml | 10 +++- .../custom/materio_home/materio_home.module | 20 ++++++++ .../ComputedProdVariationsReferences.php | 50 +++++++++++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 web/modules/custom/materio_home/src/Plugin/Field/FieldType/ComputedProdVariationsReferences.php diff --git a/config/sync/core.entity_view_display.node.frontpage.default.yml b/config/sync/core.entity_view_display.node.frontpage.default.yml index f962b55..bedba17 100644 --- a/config/sync/core.entity_view_display.node.frontpage.default.yml +++ b/config/sync/core.entity_view_display.node.frontpage.default.yml @@ -98,6 +98,7 @@ third_party_settings: group_pricing: children: - field_pricing + - computed_products_reference parent_name: '' weight: 4 format_type: html_element @@ -247,6 +248,15 @@ content: third_party_settings: { } type: entity_reference_entity_view label: hidden + computed_products_reference: + label: hidden + weight: 6 + region: content + settings: + link: true + view_mode: default + third_party_settings: { } + type: entity_reference_entity_view computed_showrooms_reference: label: hidden weight: 6 @@ -314,7 +324,7 @@ content: region: content field_pricing: weight: 5 - label: above + label: hidden settings: { } third_party_settings: { } type: text_default diff --git a/config/sync/core.entity_view_display.node.frontpage.teaser.yml b/config/sync/core.entity_view_display.node.frontpage.teaser.yml index 37808a1..d848b15 100644 --- a/config/sync/core.entity_view_display.node.frontpage.teaser.yml +++ b/config/sync/core.entity_view_display.node.frontpage.teaser.yml @@ -1,6 +1,6 @@ uuid: c04cd92d-7d88-4dbe-b830-6fe45f5a7534 langcode: en -status: true +status: false dependencies: config: - core.entity_view_mode.node.teaser @@ -36,6 +36,14 @@ content: link: true third_party_settings: { } type: entity_reference_label + computed_products_reference: + label: hidden + weight: -5 + region: content + settings: + link: true + third_party_settings: { } + type: entity_reference_label computed_showrooms_reference: label: hidden weight: -5 diff --git a/web/modules/custom/materio_home/materio_home.module b/web/modules/custom/materio_home/materio_home.module index 1cab7e6..8a17068 100644 --- a/web/modules/custom/materio_home/materio_home.module +++ b/web/modules/custom/materio_home/materio_home.module @@ -98,6 +98,26 @@ function materio_home_entity_bundle_field_info(EntityTypeInterface $entity_type, ]) ->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedArticlesReferences::class); + $fields['computed_products_reference'] = BaseFieldDefinition::create('entity_reference') + ->setName('computed_products_reference') + ->setLabel(t('Computed Products References')) + ->setDescription(t('Computed Products References.')) + // // The Entity Type this field belongs to. + ->setTargetEntityTypeId($entity_type->id()) + // // The Entity Type bundle this field belongs to. + ->setTargetBundle($bundle) + ->setSetting('target_type', 'commerce_product_variation') + ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) + ->setComputed(TRUE) + ->setRevisionable(FALSE) + ->setTranslatable(FALSE) + ->setDisplayConfigurable('view', TRUE) + ->setDisplayOptions('view', [ + 'label' => 'hidden', + 'weight' => -5, + ]) + ->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedProdVariationsReferences::class); + return $fields; } } diff --git a/web/modules/custom/materio_home/src/Plugin/Field/FieldType/ComputedProdVariationsReferences.php b/web/modules/custom/materio_home/src/Plugin/Field/FieldType/ComputedProdVariationsReferences.php new file mode 100644 index 0000000..61bb553 --- /dev/null +++ b/web/modules/custom/materio_home/src/Plugin/Field/FieldType/ComputedProdVariationsReferences.php @@ -0,0 +1,50 @@ +entityTypeManager = \Drupal::entityTypeManager(); + } + + /** + * Compute the values. + */ + protected function computeValue() { + $query = \Drupal::entityQuery('commerce_product_variation') + ->condition('status', 1) + ->sort('created', 'DESC') + // ->exists('field_visuel') + // ->condition('type', 'article') + ->range(0,12); + $ids = $query->execute(); + foreach ($ids as $key => $id) { + $this->list[$key] = $this->createItem($key, $id); + } + } + +}