commerce – How to restrict access to the Premium Content

I have just started to learn Drupal (v. 9), so I’m a beginner. I have got a project to developed on E-Learning. This website will have many courses to learn from. The basic structure of the courses could be:

Level 1 = School, College, Professionals

Level 2 = School=> Algebra, Chemistry, Physics and so on (these will be the courses)

Level 3 = Physics=> Module 1, Module 2, Module 3 and so on

Level 4 = Module 1=> Topic 1, Topic 2, Topic 3 and so on

Clicking on any topic will take the visitor to its content page (video and/or textual)

Some course will be free whereas some will be paid. Each course will have a credit system and on completion of a course(paid course) users will get a certificate of completion

I have created few custom tables (MySQL) to store the course content as per above schema. I have also created a custom module so user can navigate to the topic detail page. Now what remains is to restrict access to the premium content. I have googled to find some guidance and below is what i found:

A) https://www.drupal.org/docs/contributed-modules/role-paywall/set-up-payment-for-your-content

From here i think there are 2 modules (Role Paywall & Commerce License) which i need to install. Is there any thing else i need to install/create to achieve the above functionality

B) https://www.optasy.com/blog/how-do-you-restrict-access-content-drupal-8-6-modules-will-do-job-you

C) There are many modules in Drupal for integrating payment gateway

D) There is also Drupal Commerce, which i think is also a module for giving ECommerce power to Drupal website

I’m confused as to which way should i proceed. Can any one guide me in the right path.

Much Regards,

Javed

commerce – Custom state event subscriber isn’t invoked

I added a new order state called ‘refunded’. I’m trying to have an event get triggered when the order state transitions to ‘refund’, but I can’t get the event to fire.

commerce_order.workflows.yml

order_default:
  id: order_default
  group: commerce_order
  label: 'Default'
  states:
    draft:
      label: Draft
    completed:
      label: Completed
    canceled:
      label: Canceled
    refunded:
      label: Refunded
  transitions:
    place:
      label: 'Place order'
      from: (draft)
      to: completed
    cancel:
      label: 'Cancel order'
      from: (draft)
      to:   canceled
    refund:
      label: 'Refund order'
      from: (completed)
      to: refunded

(...)

This is my module services yml file:

services:
  my_module.order_refund.event_subscriber:
    class: 'Drupalmy_moduleEventSubscriberOrderRefundSubscriber'
    tags:
      - { name: 'event_subscriber' }

And finally the event subscriber class in my_module/src/EventSubscriber/OrderRefundSubscriber.php

<?php

namespace Drupalmy_moduleEventSubscriber;

use SymfonyComponentEventDispatcherEventSubscriberInterface;
use Drupalstate_machineEventWorkflowTransitionEvent;
use DrupalCoreEntityEntityTypeManager;

class OrderRefundSubscriber implements EventSubscriberInterface {
  /**
   * DrupalCoreEntityEntityTypeManager definition.
   *
   * @var DrupalCoreEntityEntityTypeManager
   */
  protected $entityTypeManager;

  /**
   * Constructor.
   */
  public function __construct(EntityTypeManager $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  static function getSubscribedEvents() {
    $events('commerce_order.refund.post_transition') = ('orderRefundHandler');
    return $events;
  }

  /**
   * This method is called whenever the commerce_order.refund.post_transition event is
   * dispatched.
   *
   * @param WorkflowTransitionEvent $event
   */
  public function orderRefundHandler(WorkflowTransitionEvent $event) {
    // Do something here ...
  }
}

This is the part of the code that is supposed to trigger the event:

(...)
    $order_state = $order->getState();
    $order_state_transitions = $order_state->getTransitions();
    if (isset($order_state_transitions('refund'))) {
      $order_state->applyTransitionById('refund');
      $order->save();
    }
(...)

Any ideas why my event subscriber code is not firing?

References: https://git.drupalcode.org/project/state_machine/blob/8.x-1.x/README.md

9 – Drupal commerce 2 custom state event subscriber not firing

I added a new order state called ‘refunded’. I’m trying to have an event get triggered when the order state transitions to ‘refund’, but I can’t get the event to fire.

commerce_order.workflows.yml

order_default:
  id: order_default
  group: commerce_order
  label: 'Default'
  states:
    draft:
      label: Draft
    completed:
      label: Completed
    canceled:
      label: Canceled
    refunded:
      label: Refunded
  transitions:
    place:
      label: 'Place order'
      from: (draft)
      to: completed
    cancel:
      label: 'Cancel order'
      from: (draft)
      to:   canceled
    refund:
      label: 'Refund order'
      from: (completed)
      to: refunded

(...)

This is my module services yml file:

services:
  my_module.order_refund.event_subscriber:
    class: 'Drupalmy_moduleEventSubscriberOrderRefundSubscriber'
    tags:
      - { name: 'event_subscriber' }

And finally the event subscriber class in my_module/src/EventSubscriber/OrderRefundSubscriber.php

<?php

namespace Drupalmy_moduleEventSubscriber;

use SymfonyComponentEventDispatcherEventSubscriberInterface;
use Drupalstate_machineEventWorkflowTransitionEvent;
use DrupalCoreEntityEntityTypeManager;

class OrderRefundSubscriber implements EventSubscriberInterface {
  /**
   * DrupalCoreEntityEntityTypeManager definition.
   *
   * @var DrupalCoreEntityEntityTypeManager
   */
  protected $entityTypeManager;

  /**
   * Constructor.
   */
  public function __construct(EntityTypeManager $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  static function getSubscribedEvents() {
    $events('commerce_order.refund.post_transition') = ('orderRefundHandler');
    return $events;
  }

  /**
   * This method is called whenever the commerce_order.refund.post_transition event is
   * dispatched.
   *
   * @param WorkflowTransitionEvent $event
   */
  public function orderRefundHandler(WorkflowTransitionEvent $event) {
    // Do something here ...
  }
}

This is the part of the code that is supposed to trigger the event:

(...)
    $order_state = $order->getState();
    $order_state_transitions = $order_state->getTransitions();
    if (isset($order_state_transitions('refund'))) {
      $order_state->applyTransitionById('refund');
      $order->save();
    }
(...)

Any ideas why my event subscriber code is not firing?

References: https://git.drupalcode.org/project/state_machine/blob/8.x-1.x/README.md

Drupal Commerce Checkout Pane Does Not Display Custom Panes

I’m using the documentation example and for some reason I can not get the custom pane to display in the checkout. What am I missing here. I’m using the latest version of Drupal Commerce on Drupal 9.2

<?php

namespace Drupalmy_checkout_panePluginCommerceCheckoutPane;

use Drupalcommerce_checkoutPluginCommerceCheckoutPaneCheckoutPaneBase;
use DrupalCoreFormFormStateInterface;

/**
 * Provides a custom message pane.
 *
 * @CommerceCheckoutPane(
 *   id = "my_checkout_pane_custom_message",
 *   label = @Translation("Custom message"),
 *   display_label = @Translation("Another display label"),
 *   default_step = "review",
 *   wrapper_element = "fieldset",
 * )
 */
class CustomMessagePane extends CheckoutPaneBase {

/**
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
  $form_display = EntityFormDisplay::collectRenderDisplay($this->order, 'checkout');
  $form_display->buildForm($this->order, $pane_form, $form_state);
  return $pane_form;
}
/**
* {@inheritdoc}
*/
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
  $form_display = EntityFormDisplay::collectRenderDisplay($this->order, 'checkout');
  $form_display->extractFormValues($this->order, $pane_form, $form_state);
  $form_display->validateFormValues($this->order, $pane_form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
  $form_display = EntityFormDisplay::collectRenderDisplay($this->order, 'checkout');
  $form_display->extractFormValues($this->order, $pane_form, $form_state);
}

}

magento2 – How to get all scheduled changes for a product in Magento commerce?

I have added 2 schedules to a product in Magento as shown below.

enter image description here

Below code gives list of all schedules present in our database but there is no sku/product_id relation here.

<?php

namespace VendorCustomImportModel;

use MagentoFrameworkApiSearchCriteria;

class Test
{
  
    protected $searchCriteriaBuilder;
    protected $updateRepository;

    public function __construct
        MagentoFrameworkApiSearchCriteriaBuilder $searchCriteriaBuilder,
        MagentoStagingApiUpdateRepositoryInterface $updateRepository
    ) {
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
        $this->updateRepository = $updateRepository;
    }

    public function getSchedule()
    {
    try {
        $searchCriteria = $this->searchCriteriaBuilder->create();

        $items = $this->updateRepository->getList($searchCriteria)->getItems();
    echo '<pre>';
    foreach ($items as $item) {
        print_r($item->getData());exit;
    }

    }   catch (Exception $e){
    echo $e->getMessage();
    }
    }
}

Question: How to get all scheduled changes for a product by sku?

content staging – How to delete/unschedule scheduled updates for product programatically in Magento 2 commerce edition?

I have added a scheduled update for a product as shown below

enter image description here

Now I want to delete this schedule programatically. How to achieve that?

I see the product staging class MagentoCatalogStagingApiProductStagingInterface which has a function unschedule($product, $version)

Where I can get the information about the version of a specific product which needs to be passed to this function?

installing – Drupal Commerce installation fails

I used ‘composer create-project drupalcommerce/project-base commerce –stability dev’ from ‘https://docs.drupalcommerce.org/commerce2/developer-guide/install-update/installation’, (subdomain ‘https://pood2.veskimees.eu/’ directs to ‘/commerce/web’) Installation starts normally, but after db credentials fails with:

Error
The website encountered an unexpected error. Please try again later.
Error: Class “DrupalshortcutEntityShortcut” not found in commerce_base_install() (line 25 of profiles/contrib/commerce_base/commerce_base.install).

commerce_base_install()
call_user_func_array(‘commerce_base_install’, Array) (Line: 392)
DrupalCoreExtensionModuleHandler->invoke(‘commerce_base’, ‘install’, Array) (Line: 343)
DrupalCoreExtensionModuleInstaller->install(Array, ) (Line: 83)
DrupalCoreProxyClassExtensionModuleInstaller->install(Array, ) (Line: 1653)
install_install_profile(Array) (Line: 694)
install_run_task(Array, Array) (Line: 565)
install_run_tasks(Array, NULL) (Line: 118)
install_drupal(Object) (Line: 48)

Any ideas whats wrong?

commerce – Using Simple Hierarchical or Client-side Hierarchical Select with conditional field

I am working on Drupal 9. I created a content type where I have to do a test to know the values obtained after a selection: As explained at the very bottom, if at the first level I select Printer and Network, I have to do a treatment appropriate, except that it doesn’t work at all.

How can I get the actual values selected for the test to pass?

If you have any other solution I am interested.

Using Simple Hierarchical or Client-side Hierarchical Select
with conditional field

  1. Create a taxonomy (Property Type) with 2 levels:
  • Printer
    Local
    Multifunction
    Network
  • Laptop
    Notebook
    Tablet
  • Backup
    Tape Backup
    Tape Library

commerce – Can’t edit or add addresses in customer’s profile “Address book” page

With Drupal 9 and Commerce core 2.25

The problem only occur when “Allow multiple profiles” is checked in the “customer” profile, it is supposed to give the possibility to add several addresses to the address book as described in Commerce 2 documentation.

On the user’s Address book page (or customer profile page), “Edit” and “Add address” buttons are not activated (rendered as simple text, not links) preventing access to these actions. Nevertheless, on the checkout page, user as the right to create new addresses which can be seen in the Address Book but cannot be edited anymore…

Connected as authenticated user or admin makes no difference. The rights for creating and updating, viewing, deleting own profile are granted.

I can’t figure out what’s happening and can’t find any existing issue reporting this.

Any help to solve it?

Customer's profile page

enter image description here

How to add product filter dropdown in woo commerce order page?

How to add filter by product in woo commerce order page in admin side?
filter by product