Skip to content

Commit

Permalink
Merge pull request #69 from iqual-ch/issue/US-1278_php81-upgrade_2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe von Bergen committed Jun 15, 2023
2 parents ba2ab0b + 8a47c20 commit f361a7d
Show file tree
Hide file tree
Showing 46 changed files with 359 additions and 319 deletions.
27 changes: 13 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,25 @@
}
],
"require": {
"drupal/commerce": "*",
"drupal/hierarchical_taxonomy_menu": "*",
"drupal/commerce": "2.33.0",
"drupal/hierarchical_taxonomy_menu": "^1.0",
"drupal/media_entity_browser": "^2.0",
"drupal/commerce_variation_add_to_cart": "*",
"drupal/commerce_variation_cart_form": "*",
"drupal/commerce_shipping": "*",
"drupal/commerce_postfinance": "*",
"drupal/commerce_variation_add_to_cart": "^1.0",
"drupal/commerce_variation_cart_form": "^1.0",
"drupal/commerce_shipping": "^2.0",
"drupal/commerce_postfinance": "^3.0",
"drupal/pagedesigner_block_adaptable": "^2.0",
"iqual/iq_progressive_decoupler": "^2.0",
"drupal/term_reference_tree": "*",
"drupal/twig_tweak": "*",
"drupal/swiftmailer": "*",
"drupal/commerce_cart_api": "*",
"drupal/twig_tweak": "^2.0",
"drupal/swiftmailer": "^2.0",
"drupal/commerce_cart_api": "^1.0",
"iqual/iq_entity_browsers": "^2.0",
"drupal/commerce_combine_carts": "*",
"drupal/login_emailusername": "*",
"drupal/redirect_after_login": "*",
"drupal/single_datetime": "*",
"drupal/commerce_combine_carts": "^1.0",
"drupal/login_emailusername": "^2.0",
"drupal/redirect_after_login": "^2.0",
"drupal/single_datetime": "^1.0",
"drupal/entity_print": "2.x",
"dompdf/dompdf": "^0.8.6",
"drupal/commerce_repeat_order": "^2.2"
}
}
1 change: 0 additions & 1 deletion config/optional/mailsystem.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ modules:
none:
formatter: swiftmailer
sender: swiftmailer

1 change: 0 additions & 1 deletion config/schema/iq_commerce.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ iq_commerce.settings:
cart_header_size:
type: label
label: 'Cart Header Size'

41 changes: 25 additions & 16 deletions iq_commerce.module
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

/**
* @file
* Iq_commerce module file.
*/

use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\Core\Locale\CountryManager;
use Drupal\iq_commerce\Form\IqCommerceSettingsForm;
use Drupal\views\ViewExecutable;
Expand All @@ -28,50 +30,50 @@ function iq_commerce_mail($key, &$message, $params) {
function iq_commerce_theme($existing, $type, $theme, $path) {
return [
'block__menu_block__account' => [
'template' => 'block--menu-block--account',
'template' => 'block/block--menu-block--account',
'base hook' => 'block',
],
'commerce_checkout_form__with_sidebar' => [
'template' => 'commerce-checkout-form--with-sidebar',
'template' => 'commerce/commerce-checkout-form--with-sidebar',
'base hook' => 'commerce_checkout_form',
],
'commerce_order__user' => [
'template' => 'commerce--order--user',
'template' => 'commerce/commerce--order--user',
'base hook' => 'commerce_order',
],
'commerce_order_receipt__entity_print' => [
'template' => 'commerce-order-receipt--entity-print',
'template' => 'commerce/commerce-order-receipt--entity-print',
'base hook' => 'commerce_order_receipt',
],
'commerce_order_receipt' => [
'template' => 'iq-commerce-order-receipt',
'template' => 'commerce/iq-commerce-order-receipt',
'base hook' => 'commerce_order_receipt',
],
'commerce_product' => [
'render element' => 'elements',
],
'page__user__login' => [
'template' => 'page--user--login',
'template' => 'layout/page--user--login',
'base hook' => 'page',
],
'page__user__orders__%' => [
'template' => 'page--user--orders--%',
'template' => 'layout/page--user--orders--%',
'base hook' => 'page',
],
'page__user__password' => [
'template' => 'page--user--password',
'template' => 'layout/page--user--password',
'base hook' => 'page',
],
'page__user__register' => [
'template' => 'page--user--register',
'template' => 'layout/page--user--register',
'base hook' => 'page',
],
'menu__account' => [
'template' => 'menu--account',
'template' => 'navigation/menu--account',
'base hook' => 'menu',
],
'user__full' => [
'template' => 'user--full',
'template' => 'user/user--full',
'base hook' => 'user',
],
];
Expand Down Expand Up @@ -102,15 +104,17 @@ function iq_commerce_form_alter(&$form, FormStateInterface $form_state, $form_id
if (!is_string($a)) {
$a = $a->__toString();
}
$attribute_a_value = Drupal::entityTypeManager()->getStorage('commerce_product_attribute_value')->loadByProperties(['attribute' => $attribute_id, 'name' => $a]);
$attribute_a_value = Drupal::entityTypeManager()->getStorage('commerce_product_attribute_value')
->loadByProperties(['attribute' => $attribute_id, 'name' => $a]);
$attribute_a_value = reset($attribute_a_value);
if ($attribute_a_value instanceof ProductAttributeValue) {
$attribute_a_weight = $attribute_a_value->getWeight();
}
if (!is_string($b)) {
$b = $b->__toString();
}
$attribute_b_value = Drupal::entityTypeManager()->getStorage('commerce_product_attribute_value')->loadByProperties(['attribute' => $attribute_id, 'name' => $b]);
$attribute_b_value = Drupal::entityTypeManager()->getStorage('commerce_product_attribute_value')
->loadByProperties(['attribute' => $attribute_id, 'name' => $b]);
$attribute_b_value = reset($attribute_b_value);
if ($attribute_b_value instanceof ProductAttributeValue) {
$attribute_b_weight = $attribute_b_value->getWeight();
Expand Down Expand Up @@ -178,7 +182,12 @@ function iq_commerce_form_alter(&$form, FormStateInterface $form_state, $form_id
}

/**
* Set tax rate as third party setting on the entity type.
*
* @param array $form
* The submitted form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The submitted form state.
*/
function iq_commerce_product_type_form_submit(&$form, FormStateInterface $form_state) {
/** @var \Drupal\commerce_product\Entity\ProductType $product_type_entity */
Expand Down Expand Up @@ -220,7 +229,7 @@ function iq_commerce_views_pre_render(ViewExecutable $view) {
$cart = \Drupal::service('commerce_cart.cart_provider')
->getCart('default', $store);
$cart->recalculateTotalPrice();
$cart->setRefreshState(\Drupal\commerce_order\Entity\OrderInterface::REFRESH_ON_SAVE);
$cart->setRefreshState(OrderInterface::REFRESH_ON_SAVE);
$cart->save();
}
}
Expand All @@ -236,7 +245,7 @@ function iq_commerce_preprocess_commerce_order_receipt(&$variables) {

/** @var Drupal\commerce_order\Entity\OrderInterface $order */
$order = $variables['order_entity'];
$shipments = $order->get('shipments')->referencedEntities();
$shipments = $order->shipments->referencedEntities();
/** @var \Drupal\commerce_shipping\Entity\Shipment $shipment */
$shipment = reset($shipments);
/** @var \Drupal\address\Plugin\Field\FieldType\AddressItem $address */
Expand All @@ -248,7 +257,7 @@ function iq_commerce_preprocess_commerce_order_receipt(&$variables) {
$variables['shipping_address'] = $address->getGivenName() . ' ' . $address->getFamilyName() . '<br />' . $address->getAddressLine1() . '<br />' . $address->getPostalCode() . ' ' . $address->getLocality() . '<br/>' . $full_country_name;
}
$billing_profile = $order->getBillingProfile();
$billing_address = $billing_profile->get('address')->first();
$billing_address = $billing_profile->address->first();
$full_country_name = $countries[$billing_address->getCountryCode()]->__toString();
$variables['billing_address'] = $billing_address->getGivenName() . ' ' . $billing_address->getFamilyName() . '<br />' . $billing_address->getAddressLine1() . '<br />' . $billing_address->getPostalCode() . ' ' . $billing_address->getLocality() . '<br/>' . $full_country_name;
if (!empty($shipment->get('shipping_method')->entity)) {
Expand Down
2 changes: 1 addition & 1 deletion iq_commerce.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ services:

iq_commerce.event_subscriber:
class: Drupal\iq_commerce\EventSubscriber\RedirectAnonymousSubscriber
arguments: []
arguments: ['@current_user']
tags:
- {name: event_subscriber}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ public function blockForm($form, FormStateInterface $form_state) {
$form['link'] = [
'#type' => 'textfield',
'#title' => $this->t('Link Cart'),
'#default_value' => isset($this->configuration['link']) ? $this->configuration['link'] : '/cart',
'#default_value' => $this->configuration['link'] ?? '/cart',
];

$form['link_title'] = [
'#type' => 'textfield',
'#title' => $this->t('Link Title'),
'#default_value' => isset($this->configuration['link_title']) ? $this->configuration['link_title'] : 'Cart',
'#default_value' => $this->configuration['link_title'] ?? 'Cart',
];

$form['label_total'] = [
'#type' => 'textfield',
'#title' => $this->t('Label Total'),
'#default_value' => isset($this->configuration['label_total']) ? $this->configuration['label_total'] : 'Total',
'#default_value' => $this->configuration['label_total'] ?? 'Total',
];

$form['label_cart_empty'] = [
'#type' => 'textfield',
'#title' => $this->t('Label Cart empty'),
'#default_value' => isset($this->configuration['label_cart_empty']) ? $this->configuration['label_cart_empty'] : 'Empty',
'#default_value' => $this->configuration['label_cart_empty'] ?? 'Empty',
];
return $form;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
<?php

/**
* @file
* Iq_commerce_order module file.
*/

use Drupal\Core\Form\FormStateInterface;

/**
* Implements hook_form_alter().
*/
function iq_commerce_order_additional_fields_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
{
function iq_commerce_order_additional_fields_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Only show collection date if the customer has selected
// the option to pick up product(s) from store.
if ($form_id == 'commerce_checkout_flow_multistep_default' && !empty($form['collection_date_pane']) && !empty($form['shipping_information'])) {
$shipping_methods = $form['shipping_information']['shipments'][0]['shipping_method']['widget'][0]['#options'] ?? [];
/** @var \Drupal\Component\Render\FormattableMarkup $shipping_method */
foreach ($shipping_methods as $key => $shipping_method) {
$label = explode(':', $shipping_method->jsonSerialize())[0];
// @TODO The label should be configurable, since the shipping method
// @TODO might be named something else.
// @todo The label should be configurable, since the shipping method
// @todo might be named something else.
if ($label == 'Abholung vor Ort') {
$form['collection_date_pane']['collection_date']['#states'] = [
'visible' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Drupal\commerce\AjaxFormTrait;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface;
use Drupal\commerce_order\Entity\Order;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Form\FormStateInterface;

Expand Down Expand Up @@ -37,7 +36,7 @@ public function buildPaneForm(array $pane_form, FormStateInterface $form_state,
'#max_date' => \Drupal::service('date.formatter')->format(strtotime('+90 days'), 'custom', 'd.m.Y'),
'#min_date' => \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'custom', 'd.m.Y'),
'#date_timezone' => date_default_timezone_get(),
'#date_type' => 'date',
'#date_type' => 'date',
'#time' => FALSE,
'#hour_format' => 24,
'#allow_times' => 60,
Expand All @@ -46,7 +45,7 @@ public function buildPaneForm(array $pane_form, FormStateInterface $form_state,
'#datetimepicker_theme' => 'default',
'#exclude_date' => '',
'#year_start' => '1970',
'#year_end' => intval(date('Y') +1),
'#year_end' => intval(date('Y') + 1),
'#date_date_element' => 'date',
'#date_date_callbacks' => [],
'#date_time_element' => NULL,
Expand All @@ -69,14 +68,12 @@ public function submitPaneForm(array &$pane_form, FormStateInterface $form_state
}
}


/**
* {@inheritdoc}
*/
public function isVisible() {
// @TODO Only show if the pick up from store shipping method is selected.
// @TODO This can be done either through ajax or somehow through form alter.

// @todo Only show if the pick up from store shipping method is selected.
// @todo This can be done either through ajax or somehow through form alter.
return TRUE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ services:
class: Drupal\iq_commerce_related_product\EventSubscriber\RelatedProductEventSubscriber
arguments: [ '@entity_type.manager', '@entity.repository' ]
tags:
- { name: event_subscriber }
- { name: event_subscriber }

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\iq_commerce\Event\IqCommerceCartEvents;
use Drupal\iq_commerce\Form\IqCommerceProductSettingsForm;
use Drupal\rest\ModifiedResourceResponse;
use Drupal\iq_commerce_related_product\Form\RelatedProductSettingsForm;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\iq_commerce\Event\IqCommerceAfterCartAddEvent;

/**
* Handles related products on adding products to cart.
*/
class RelatedProductEventSubscriber implements EventSubscriberInterface {

/**
Expand All @@ -36,9 +37,8 @@ class RelatedProductEventSubscriber implements EventSubscriberInterface {
* The entity type manager.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
*
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager,EntityRepositoryInterface $entity_repository) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityRepositoryInterface $entity_repository) {
$this->entityTypeManager = $entity_type_manager;
$this->entityRepository = $entity_repository;
}
Expand Down Expand Up @@ -75,26 +75,26 @@ public function suggestRelatedProducts(IqCommerceAfterCartAddEvent $event) {
foreach ($related_field_names as $related_field_name => $field_settings) {
if ($purchased_entity->hasField($related_field_name)) {
$related_products = $purchased_entity->get($related_field_name)->getValue();
$related_products_reference_type = $purchased_entity->get($related_field_name)->getFieldDefinition()->get('entity_type');
$related_products_reference_type = $purchased_entity->get($related_field_name)->getFieldDefinition()->getTargetEntityTypeId();
}
elseif ($purchased_entity->getProduct()->hasField($related_field_name)){
elseif ($purchased_entity->getProduct()->hasField($related_field_name)) {
$related_products = $purchased_entity->getProduct()->get($related_field_name)->getValue();
$related_products_reference_type = $purchased_entity->getProduct()->get($related_field_name)->getFieldDefinition()->get('entity_type');
$related_products_reference_type = $purchased_entity->getProduct()->get($related_field_name)->getFieldDefinition()->getTargetEntityTypeId();
}

if (!empty($related_products)) {
foreach ($related_products as $related_product) {
// If the reference is of type product, then load all variations for each product and suggest them.
if ($related_products_reference_type == 'commerce_product') {
/** @var Product $related_product */
/** @var \Drupal\commerce_product\Entity\Product $related_product */
$related_product = Product::load($related_product['target_id']);
foreach ($related_product->getVariations() as $related_variation) {
$suggested_products[$related_variation->id()] = $related_variation;
}
}
// If the reference is of type variation, just suggest all of them.
else {
/** @var ProductVariation $related_variation */
/** @var \Drupal\commerce_product\Entity\ProductVariation $related_variation */
$related_variation = ProductVariation::load($related_product['target_id']);
$suggested_products[$related_variation->id()] = $related_variation;
}
Expand All @@ -107,4 +107,5 @@ public function suggestRelatedProducts(IqCommerceAfterCartAddEvent $event) {
$additional_data['related_products'] = array_values($suggested_products);
$event->addAdditionalData($additional_data);
}

}
Loading

0 comments on commit f361a7d

Please sign in to comment.