A bit of a bigger undertaking but I feel this needs to be done for a couple reasons:

  • Module will be standalone
  • Easier to integrate into custom solutions
  • Easier to control our own entities rather than hooking existing ones
  • Potentially simplified handling of Alexander orders

Comments

gmem created an issue. See original summary.

gmem’s picture

StatusFileSize
new13.19 KB

Pretty hefty patch with first version of entities, I realize there is some "don't reinvent the wheel" going on here but I want to be truly free of Commerce and the API requires all fields.

gmem’s picture

Status: Active » Needs work
gmem’s picture

StatusFileSize
new20.55 KB

Some more progress, moving hooks to submodule and translate to Alexanders entities

gmem’s picture

Status: Needs work » Needs review
StatusFileSize
new30.66 KB

Wow, this is a big patch, but I think I've eliminated most of the reliance on Drupal Commerce

joshmiller’s picture

Status: Needs review » Needs work
  1. +++ b/modules/commerce_alexanders/commerce_alexanders.module
    @@ -0,0 +1,48 @@
    +      if ($product->hasField('field_alexanders_send')) {
    

    This field should be prefixed with the alxdr_ field prefix I've mentioned elsewhere. And remove the field_ prefix altogether.

  2. +++ b/modules/commerce_alexanders/commerce_alexanders.module
    @@ -0,0 +1,48 @@
    +//          'file' => $item->get('field_file_url')->getValue()[0],
    +//          'foil' => $item->get('field_alexanders_foil_url')->getValue()[0],
    

    These need to be deleted or updated. But it's against code standards to have code commented out.

  3. +++ b/modules/commerce_alexanders/commerce_alexanders.module
    @@ -0,0 +1,48 @@
    +      'rush' => FALSE,
    

    You're hard coding the rush value?

  4. +++ b/modules/commerce_alexanders/commerce_alexanders.routing.yml
    @@ -0,0 +1,7 @@
    +    _permission: 'administer site configuration'
    

    We really don't ever want to increase the scope of any of the permissions that come with Drupal. Please create custom permissions for all routes.

  5. +++ b/modules/commerce_alexanders/src/Form/CommerceAlexandersManagementForm.php
    @@ -0,0 +1,111 @@
    +      '#description' => $this->t('Send Alexander these product types.'),
    

    Better description: "Send Alexanders orders that contain these types of products."

  6. +++ b/modules/commerce_alexanders/src/Form/CommerceAlexandersManagementForm.php
    @@ -0,0 +1,111 @@
    +      'field_alexanders_send' => $this->t('Send to Alexanders API'),
    

    If we go with alxdr_ for a field prefix, then this field name should be alxdr_send.

  7. +++ b/modules/commerce_alexanders/src/Form/CommerceAlexandersManagementForm.php
    @@ -0,0 +1,111 @@
    +            $field->delete();
    

    Deleting fields is pretty terrible action to just casually do. I'd recommend instead of a normal form, we use a confirmation form.

  8. +++ b/src/Controller/ApiController.php
    @@ -39,24 +38,49 @@ class ApiController extends ControllerBase {
    +      // If in a sandbox, don't save the order, or pass 401 status code.
    +      switch ($auth) {
    +        case 'sandbox':
    +          break;
    

    Note that #3026635: ApiController.php Nitpicks addresses some issues in this file.

  9. +++ b/src/Entity/AlexandersOrder.php
    @@ -0,0 +1,116 @@
    + * @ContentEntityType(
    + *   id = "alexanders_order",
    + *   label = @Translation("Alexanders Order"),
    + *   label_singular = @Translation("Alexanders Order"),
    + *   label_plural = @Translation("Alexanders Orders"),
    + *   label_count = @PluralTranslation(
    + *     singular = "@count order",
    + *     plural = "@count orders",
    + *   ),
    + *   base_table = "alexanders_order",
    + *   data_table = "alexanders_order_data",
    + *   admin_permission = "administer site settings",
    + *   fieldable = TRUE,
    + *   translatable = FALSE,
    + *   entity_keys = {
    + *     "id" = "order_id",
    + *     "label" = "order_number",
    + *   },
    + * )
    
    +++ b/src/Entity/AlexandersOrderPhotobook.php
    @@ -0,0 +1,73 @@
    + * @ContentEntityType(
    + *   id = "alexanders_order_photobook",
    + *   label = @Translation("Alexanders Order Photobook"),
    + *   label_singular = @Translation("Alexanders Order Photobook"),
    + *   label_plural = @Translation("Alexanders Order Photobooks"),
    + *   label_count = @PluralTranslation(
    + *     singular = "@count photobook",
    + *     plural = "@count photobooks",
    + *   ),
    + *   base_table = "alexanders_order_photobook",
    + *   data_table = "alexanders_order_item_photobook_data",
    + *   admin_permission = "administer site settings",
    + *   fieldable = TRUE,
    + *   translatable = FALSE,
    + *   entity_keys = {
    + *     "id" = "book_id",
    + *     "label" = "sku",
    + *   },
    + * )
    
    +++ b/src/Entity/AlexandersShipment.php
    @@ -0,0 +1,107 @@
    + * @ContentEntityType(
    + *   id = "alexanders_shipment",
    + *   label = @Translation("Alexanders Shipment"),
    + *   label_singular = @Translation("Alexanders Shipment"),
    + *   label_plural = @Translation("Alexanders Shipments"),
    + *   label_count = @PluralTranslation(
    + *     singular = "@count shipment",
    + *     plural = "@count shipments",
    + *   ),
    + *   base_table = "alexanders_shipments",
    + *   data_table = "alexanders_shipments_data",
    + *   admin_permission = "administer site settings",
    + *   fieldable = TRUE,
    + *   translatable = FALSE,
    + *   entity_keys = {
    + *     "id" = "shipment_id",
    + *     "label" = "method",
    + *   },
    + * )
    

    We need views integration for these entities. To provide views data for an entity create a class implementing \Drupal\views\EntityViewsDataInterface and reference this in the "views" annotation in the entity class. The return value of the getViewsData() method on the interface is the same as the old hook_views_data() hook.

    Also, we need to ship with admin/content view of Alexanders Orders that provides search/filter/edit/delete functionality. The commerce version should provide a views reference that brings in all the related Alexanders information.

  10. +++ b/src/Entity/AlexandersOrder.php
    @@ -0,0 +1,116 @@
    +    $fields['photobookItems'] = BaseFieldDefinition::create('entity_reference')
    +      ->setLabel(t('Photobook Items'))
    +      ->setDescription(t('Photobook items associated with the order'))
    +      ->setSetting('target_type', 'alexanders_order_photobook')
    +      ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED);
    

    Missing an entire entity for this. Though, I'd like to point out we don't have to ship this module with any photobook capabilities initially.

  11. +++ b/src/Entity/AlexandersOrderItem.php
    @@ -0,0 +1,98 @@
    + * Defines the Alexanders Order entity.
    
    +++ b/src/Entity/AlexandersShipment.php
    +++ b/src/Entity/AlexandersShipment.php
    @@ -0,0 +1,107 @@
    
    @@ -0,0 +1,107 @@
    +
    ...
    + * Defines the Alexanders Order entity.
    

    Comment is a copy paste typo.

  12. +++ b/src/Entity/AlexandersOrderItem.php
    @@ -0,0 +1,98 @@
    + *   list_class = "\Drupal\alexanders\Plugin\Field\FieldType\AlexandersOrderItemList",
    

    You're missing this list classes

  13. +++ b/src/Entity/AlexandersOrderItem.php
    @@ -0,0 +1,98 @@
    +    $fields['sku'] = BaseFieldDefinition::create('string')
    ...
    +    $fields['quantity'] = BaseFieldDefinition::create('integer')
    ...
    +    $fields['foil'] = BaseFieldDefinition::create('string')
    
    +++ b/src/Entity/AlexandersOrderPhotobook.php
    @@ -0,0 +1,73 @@
    +    $fields['cover'] = BaseFieldDefinition::create('string')
    ...
    +    $fields['guts'] = BaseFieldDefinition::create('string')
    
    +++ b/src/Entity/AlexandersShipment.php
    @@ -0,0 +1,107 @@
    +    $fields['method'] = BaseFieldDefinition::create('string')
    ...
    +    $fields['tracking'] = BaseFieldDefinition::create('string')
    ...
    +    $fields['timestamp'] = BaseFieldDefinition::create('datetime')
    ...
    +    $fields['cost'] = BaseFieldDefinition::create('integer')
    

    Field names are not namespaced in a way that is easy (unless base fields are simply columns on the main entity data table, but I don't think so). You must prefix all fields with something short. Maybe alxdr_

  14. +++ b/src/Entity/AlexandersOrderItem.php
    @@ -0,0 +1,98 @@
    +    $fields['file'] = BaseFieldDefinition::create('string')
    

    An additional feature we need (can be a separate issue) is the ability to override these urls by uploading a file. Might make sense to add the override files here as a simple file field and handle the overriding in the API class.

  15. +++ b/src/Entity/AlexandersOrderItem.php
    @@ -0,0 +1,98 @@
    +      ->setDescription(t('Location of foil for Alexanders to print'))
    

    Location of foil file? Otherwise it reads like we're talking about a physical location.

  16. +++ b/src/Entity/AlexandersOrderPhotobook.php
    @@ -0,0 +1,73 @@
    + * Defines the Alexanders Order entity.
    
    +++ b/src/Entity/AlexandersShipment.php
    @@ -0,0 +1,107 @@
    +/**
    

    What is this class? Photobook? Should it be more generic, like Alexanders Order Item with File?

  17. +++ b/src/Entity/AlexandersShipment.php
    @@ -0,0 +1,107 @@
    +    $fields['address'] = BaseFieldDefinition::create('address')
    

    Make sure you add address module to dependencies if it isn't there.

  18. +++ b/src/Entity/AlexandersShipmentInterface.php
    @@ -0,0 +1,29 @@
    +  public function getMethod();
    +
    +  public function setMethod($method);
    +
    +  public function getAddress();
    +
    +  public function setAddress($address);
    

    You need to run phpcs --standard=Drupal on all these things to make sure you're passing code standards. For example, all of these functions are missing comments.

gmem’s picture

StatusFileSize
new14.97 KB

Addresses code standards

gmem’s picture

StatusFileSize
new40.9 KB

Added missing files

joshmiller’s picture

Please post interdiffs. I'd rather not review 40kb everytime you post something :)

https://www.drupal.org/documentation/git/interdiff

gmem’s picture

StatusFileSize
new40.95 KB

How would we feel about splitting the views stuff into a separate issue? As it stands now this patch is pretty big , so I'd rather commit what's here now and move the other stuff to issues.

gmem’s picture

StatusFileSize
new25.61 KB

Interdiff I missed on #9 :)

joshmiller’s picture

Status: Needs work » Reviewed & tested by the community
joshmiller’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/modules/commerce_alexanders/commerce_alexanders.module
@@ -1,30 +1,34 @@
+          'file' => $item->get('field_file_url')->getValue()[0],
+          'foil' => $item->get('field_alexanders_foil_url')->getValue()[0],

Pretty sure these fields are wrong.

  • gmem committed 6e02039 on 8.x-1.x
    Issue #3026725 by gmem, joshmiller: Decouple module from Commerce
    
gmem’s picture

Status: Needs work » Fixed

*wipes brow* Whew

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.