Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions commerce_quote_cart.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ type: module
description: 'Supports quote items for Drupal Commerce.'
version: 8.x-1.x
core: 8.x
core_version_requirement: ^8 || ^9
package: Commerce
dependencies:
- commerce_cart
- commerce_checkout
- commerce_order
- commerce_product
- commerce_shipping
- hook_event_dispatcher
82 changes: 77 additions & 5 deletions commerce_quote_cart.module
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

use Drupal\commerce\PurchasableEntityInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\commerce_quote_cart\QuoteCartHelper;
use Drupal\commerce_product\Entity\ProductInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;

/**
Expand Down Expand Up @@ -73,7 +75,7 @@ function commerce_quote_cart_submit_quote(array &$form, FormStateInterface $form

/** @var \Drupal\commerce_order\Entity\OrderItemInterface $order_item */
$order_item = $addToCartForm->getEntity();
$order_item->set('field_quote', ['value' => "1"]);
$order_item->set('quote', ['value' => "1"]);

$addToCartForm->submitForm($form, $form_state);
}
Expand All @@ -82,7 +84,7 @@ function commerce_quote_cart_submit_quote(array &$form, FormStateInterface $form
* Implements hook_preprocess_block().
*/
function commerce_quote_cart_preprocess_block(&$variables) {
if (in_array($variables['elements']['#id'], ['product_variations', 'product_variations_mobile'])) {
if (isset($variables['elements']['#id']) && in_array($variables['elements']['#id'], ['product_variations', 'product_variations_mobile'])) {
$variables['label'] = commerce_quote_cart_block_label($variables);
}

Expand Down Expand Up @@ -147,7 +149,7 @@ function commerce_quote_cart_block_label($variables) {
}

function commerce_quote_cart_product_is_purchasable(ProductInterface $product) {
$purchasableField = 'field_available_for_purchase';
$purchasableField = 'available_for_purchase';
$variations = $product->getVariations();

$purchasable = FALSE;
Expand All @@ -168,8 +170,8 @@ function commerce_quote_cart_preprocess_field(&$variables) {
/** @var FieldableEntityInterface $entity */
$entity = $variables['element']['#object'];

$purchasable = 'field_available_for_purchase';
$quotable = 'field_available_for_quote';
$purchasable = 'available_for_purchase';
$quotable = 'available_for_quote';

if ($entity->hasField($purchasable) && !$entity->get($purchasable)->value) {
if (isset($variables['items'][0])) {
Expand Down Expand Up @@ -242,3 +244,73 @@ function commerce_quote_cart_ga_push_add_alter(&$push_params, $type = GA_PUSH_TY
$push_params['params'] = NULL;
}
}

/**
* Implements hook_entity_base_field_info().
*
* Provides base fields for quote, purchase.
*/
function commerce_quote_cart_entity_base_field_info(EntityTypeInterface $entity_type) {
// Add base fields to commerce_order.
if ($entity_type->id() === 'commerce_order') {
$fields['quote'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Quote'))
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
]
])
->setDisplayConfigurable('view', TRUE);
$fields['purchase'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Purchase'))
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
]
])
->setDisplayConfigurable('view', TRUE);
return $fields;
}
// Add base field to commerce_order_item.
if ($entity_type->id() === 'commerce_order_item') {
$fields['quote'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Quote'))
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
]
])
->setDisplayConfigurable('view', TRUE);
return $fields;
}
// Add base fields to commerce_product_variation.
if ($entity_type->id() === 'commerce_product_variation') {
$fields['available_for_purchase'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Available for Purchase'))
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
]
])
->setDisplayConfigurable('view', TRUE);
$fields['available_for_quote'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Available for Quote'))
->setDisplayConfigurable('form', TRUE)
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'settings' => [
'display_label' => TRUE,
]
])
->setDisplayConfigurable('view', TRUE);
return $fields;
}
}
Loading