From 3016450f1adfd2b3a172485593f7fc182928e3fa Mon Sep 17 00:00:00 2001 From: Arlina Espinoza Date: Fri, 21 Feb 2020 14:56:20 -0800 Subject: [PATCH 1/3] Compatibility with commerce 8.x-2.16 --- .../apigee_m10n_add_credit.info.yml | 2 +- .../Requirement/AddCreditProductType.php | 34 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/modules/apigee_m10n_add_credit/apigee_m10n_add_credit.info.yml b/modules/apigee_m10n_add_credit/apigee_m10n_add_credit.info.yml index 89c1637d..2d7afbfe 100644 --- a/modules/apigee_m10n_add_credit/apigee_m10n_add_credit.info.yml +++ b/modules/apigee_m10n_add_credit/apigee_m10n_add_credit.info.yml @@ -6,7 +6,7 @@ type: module core: 8.x dependencies: - apigee_m10n:apigee_m10n - - commerce:commerce (>=8.x-2.12) + - commerce:commerce (>=8.x-2.16) - commerce:commerce_product - commerce:commerce_payment - commerce:commerce_price diff --git a/modules/apigee_m10n_add_credit/src/Plugin/Requirement/Requirement/AddCreditProductType.php b/modules/apigee_m10n_add_credit/src/Plugin/Requirement/Requirement/AddCreditProductType.php index a6dc5f9e..fdd7d7e3 100644 --- a/modules/apigee_m10n_add_credit/src/Plugin/Requirement/Requirement/AddCreditProductType.php +++ b/modules/apigee_m10n_add_credit/src/Plugin/Requirement/Requirement/AddCreditProductType.php @@ -55,6 +55,9 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + /* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */ + $display_repository = \Drupal::service('entity_display.repository'); + // Get or create the order item type. $order_item_type_storage = $this->getEntityTypeManager() ->getStorage('commerce_order_item_type'); @@ -66,8 +69,29 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s 'id' => 'add_credit', 'label' => 'Add credit', 'orderType' => 'default', + 'purchasableEntityType' => 'commerce_product_variation', ]); $order_item_type->save(); + + $display_repository + ->getFormDisplay('commerce_order_item', 'add_credit', 'add_to_cart') + ->removeComponent('quantity') + ->setComponent('add_credit_target', [ + 'type' => 'add_credit_target_entity', + 'weight' => 1, + 'region' => 'content', + ]) + ->setComponent('purchased_entity', [ + 'type' => 'commerce_product_variation_attributes', + 'weight' => 0, + 'region' => 'content', + ]) + ->setComponent('unit_price', [ + 'type' => 'commerce_unit_price', + 'weight' => 2, + 'region' => 'content', + ]) + ->save(); } // Get or create the variation type. @@ -98,15 +122,21 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s 'label' => 'Add credit', 'description' => 'This product is used to add credit to prepaid balances.', 'variationType' => $variation_type->id(), + 'multipleVariations' => TRUE, + 'injectVariationFields' => TRUE, ]) ->setThirdPartySetting('apigee_m10n_add_credit', 'apigee_m10n_enable_add_credit', TRUE) ->setThirdPartySetting('apigee_m10n_add_credit', 'apigee_m10n_enable_skip_cart', TRUE); $product_type->save(); // These functions add the appropriate fields to the type. - commerce_product_add_variations_field($product_type); - commerce_product_add_stores_field($product_type); commerce_product_add_body_field($product_type); + + $display = $display_repository->getViewDisplay('commerce_product', 'add_credit', 'default'); + $component = $display->getComponent('variations'); + $component['label'] = 'hidden'; + $display->setComponent('variations', $component) + ->save(); } } From 09999c23354c7be293b016aa1546e9780bbf237a Mon Sep 17 00:00:00 2001 From: Arlina Espinoza Date: Fri, 21 Feb 2020 15:23:50 -0800 Subject: [PATCH 2/3] [#223] Fix requirements runtime error. --- .../Requirement/OrderItemAddToCartFormDisplay.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/apigee_m10n_add_credit/src/Plugin/Requirement/Requirement/OrderItemAddToCartFormDisplay.php b/modules/apigee_m10n_add_credit/src/Plugin/Requirement/Requirement/OrderItemAddToCartFormDisplay.php index 8b97e99c..0aaa25bb 100644 --- a/modules/apigee_m10n_add_credit/src/Plugin/Requirement/Requirement/OrderItemAddToCartFormDisplay.php +++ b/modules/apigee_m10n_add_credit/src/Plugin/Requirement/Requirement/OrderItemAddToCartFormDisplay.php @@ -111,7 +111,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s * {@inheritdoc} */ public function isApplicable(): bool { - return $this->getModuleHandler()->moduleExists('apigee_m10n_add_credit'); + return $this->getModuleHandler()->moduleExists('apigee_m10n_add_credit') && $this->getEntityFormDisplay(); } /** @@ -127,8 +127,14 @@ public function isCompleted(): bool { * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface * The entity form display. */ - protected function getEntityFormDisplay(): EntityFormDisplayInterface { - return $this->entityDisplayRepository->getFormDisplay('commerce_order_item', 'add_credit', 'add_to_cart'); + protected function getEntityFormDisplay():? EntityFormDisplayInterface { + try { + $form_display = $this->entityDisplayRepository->getFormDisplay('commerce_order_item', 'add_credit', 'add_to_cart'); + } + catch (\RuntimeException $e) { + return NULL; + } + return $form_display; } /** From 81929daf94c71d1f5e8f9b9bb7446952b46aafd0 Mon Sep 17 00:00:00 2001 From: arshad Date: Tue, 25 Feb 2020 21:10:58 +0400 Subject: [PATCH 3/3] Update version for commerce in RoboFile --- .circleci/RoboFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/RoboFile.php b/.circleci/RoboFile.php index 6dab5c8d..26a226d5 100644 --- a/.circleci/RoboFile.php +++ b/.circleci/RoboFile.php @@ -432,7 +432,7 @@ public function configureM10nDependencies() // TODO Revert this when `andrewberry/drupal_tests` is updated to ~8.7.0. // We need Drupal\commerce_store\StoreCreationTrait for AddCreditProductAdminTest.php - $config->require->{"drupal/commerce"} = "2.13.0"; + $config->require->{"drupal/commerce"} = "^2.16"; $config->require->{"drupal/token"} = "~1.0"; // Add dependencies for phpunit tests.