added product variations to home page on pricing
This commit is contained in:
parent
b7f9d99790
commit
a292da37c8
|
@ -98,6 +98,7 @@ third_party_settings:
|
||||||
group_pricing:
|
group_pricing:
|
||||||
children:
|
children:
|
||||||
- field_pricing
|
- field_pricing
|
||||||
|
- computed_products_reference
|
||||||
parent_name: ''
|
parent_name: ''
|
||||||
weight: 4
|
weight: 4
|
||||||
format_type: html_element
|
format_type: html_element
|
||||||
|
@ -247,6 +248,15 @@ content:
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
type: entity_reference_entity_view
|
type: entity_reference_entity_view
|
||||||
label: hidden
|
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:
|
computed_showrooms_reference:
|
||||||
label: hidden
|
label: hidden
|
||||||
weight: 6
|
weight: 6
|
||||||
|
@ -314,7 +324,7 @@ content:
|
||||||
region: content
|
region: content
|
||||||
field_pricing:
|
field_pricing:
|
||||||
weight: 5
|
weight: 5
|
||||||
label: above
|
label: hidden
|
||||||
settings: { }
|
settings: { }
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
type: text_default
|
type: text_default
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
uuid: c04cd92d-7d88-4dbe-b830-6fe45f5a7534
|
uuid: c04cd92d-7d88-4dbe-b830-6fe45f5a7534
|
||||||
langcode: en
|
langcode: en
|
||||||
status: true
|
status: false
|
||||||
dependencies:
|
dependencies:
|
||||||
config:
|
config:
|
||||||
- core.entity_view_mode.node.teaser
|
- core.entity_view_mode.node.teaser
|
||||||
|
@ -36,6 +36,14 @@ content:
|
||||||
link: true
|
link: true
|
||||||
third_party_settings: { }
|
third_party_settings: { }
|
||||||
type: entity_reference_label
|
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:
|
computed_showrooms_reference:
|
||||||
label: hidden
|
label: hidden
|
||||||
weight: -5
|
weight: -5
|
||||||
|
|
|
@ -98,6 +98,26 @@ function materio_home_entity_bundle_field_info(EntityTypeInterface $entity_type,
|
||||||
])
|
])
|
||||||
->setClass(\Drupal\materio_home\Plugin\Field\FieldType\ComputedArticlesReferences::class);
|
->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;
|
return $fields;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
namespace Drupal\materio_home\Plugin\Field\FieldType;
|
||||||
|
|
||||||
|
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||||
|
use Drupal\Core\Field\EntityReferenceFieldItemList;
|
||||||
|
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
|
||||||
|
use Drupal\Core\Field\FieldItemList;
|
||||||
|
use Drupal\Core\TypedData\TypedDataInterface;
|
||||||
|
use Drupal\Core\Field\BaseFieldDefinition;
|
||||||
|
use Drupal\Core\TypedData\ComputedItemListTrait;
|
||||||
|
|
||||||
|
// https://www.drupal.org/node/2112677
|
||||||
|
// https://www.cornel.co/article/entity-reference-computed-field-example-drupal
|
||||||
|
// https://www.caxy.com/blog/drupal-custom-form-and-computed-fields
|
||||||
|
|
||||||
|
class ComputedProdVariationsReferences extends EntityReferenceFieldItemList
|
||||||
|
{
|
||||||
|
use ComputedItemListTrait;
|
||||||
|
/**
|
||||||
|
* The entity type manager.
|
||||||
|
*
|
||||||
|
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||||
|
*/
|
||||||
|
protected $entityTypeManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function __construct(BaseFieldDefinition $definition, $name, TypedDataInterface $parent) {
|
||||||
|
parent::__construct($definition, $name, $parent);
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue