- Issue created by @lhubbert
It seems like this module has a dependency on another module named
su_events
, but after searching around I could not find a module with this name. Is that a custom module that is only used internally within Students' Union UCL?It is, apologies. That should have been removed before it was published. I'll release a fix in the next few days.
@maxwellkeeble after further testing, there is also an unnecessary dependency on
commerce_stock
which prevents installation on fresh instances of Drupal Commerce sites;
The class\Drupal\commerce_cart_webform\EventSubscriber\OrderEventSubscriber
uses the trait\Drupal\commerce_stock\ContextCreatorTrait
but never calls any methods implemented by the trait.All the phpdoc of the methods also imply that they are doing something with the product stock, even though they don't.
I also found that the::validateForm()
and::submitForm()
methods of\Drupal\commerce_cart_webform\Form\AddToCartForm
assume that the form display has the variation selection field visible, but since the form display is user-configurable, this may not be the case:if ($this->variation_webform == NULL) { // $purchased_entity_id may be null causing null ID error when trying to load the webform. $purchased_entity_id = $form_state->getValue('purchased_entity')[0]['variation']; $variation = ProductVariation::load($purchased_entity_id); $variation_webform = $this->getVariationCartWebform($variation); $this->variation_webform = $variation_webform; }
Suggestion
Add a check for existence of the
purchased_entity
submitted value and use the order item's default purchased entity as a fallback.if ($this->variation_webform == NULL) { if ($form_state->hasValue('purchased_entity')) { $purchased_entity_id = $form_state->getValue('purchased_entity')[0]['variation']; $variation = ProductVariation::load($purchased_entity_id); } else { $order_item = $this->entity; $variation = $order_item->getPurchasedEntity(); } $variation_webform = $this->getVariationCartWebform($variation); $this->variation_webform = $variation_webform; }