How to manipulate pricing using Order Processor in Commerce 2.x

Highly customizable business logic is the core of any e-commerce solution. For such functionality, Order processor comes in picture which helps us to define flexible pricing with dynamic discounts.

In this article I will walk you through order price manipulation and use of custom adjustment to fulfill complex business logics in Drupal commerce 2.x module.

What is Order Processor?

E-commerce order processing is part of the order refresh process. This is executed on draft orders to ensure that it has up to date adjustments and that its order items are up to date. E-commerce order processing is a part of e-commerce workflow in drupal commerce 2.x.

What are Adjustments in Drupal commerce 2.x compared to Drupal 7?

We know that from Commerce 1.x  each product place in the order was defined as a Line item. In Commerce 2.x, the line item is renamed to Order item, but it only holds purchasable products, wherein Drupal 7 line item was used for shipping costs and discounts.

Order Processor in Commerce 2.x

Let’s fulfill a basic business logic where, if the product has price more than 20$ and quantity less than 10, it should get a complete discount and get that product for free.

For programming business logic, first we will create a custom module named commerce_customization. In that we will create a custom adjustment for the discount feature.

We Create a yml file to initialize the custom adjustment

Now we need to create orderprocessor.php for our custom module as CustomOrderProcessor.php under Src folder of the module.

Code Snippet to set the custom adjustment.

 

$adjustments[] = new Adjustment([
           'type' => 'custom_adjustment',
           'label' => 'Discounted Price - ' . $product_title,
           'amount' => new Price('-' . $new_adjustment, 'USD'),
         ]);

Now, we need to set the priority for our custom order processor to be called at first place then the default order processor. For that we need to write services.yml as commerce_customizartions.services.yml

Hence, when we purchase a product having unit price as 10$ and taking in a quantity of 5, our business logic gets applied due to the order processor in our cart.

Order Processor Output

Order processor plays a key role in manipulations of prices and adjustments in Drupal Commerce 2.x for building complex ecommerce portals with programming business logic.

So here we achieved to implement a simple business logic of applying discount for products with quantity less than 10 and base price less than $20 by order processor.

Code Source : https://github.com/chishah92/commerce-customizations

How to build a custom Slider using the Slick Library in Drupal 8

It's easy to make a slider in Drupal 8. There are several modules available to render Drupal view slideshow. But for specifics in terms of requirement, it may change like we need different arrows, dots, the number  of slider items and so on. The important part of slideshow should allow responsive too.

The slick plugin allows responsive functionality without doing any extra effect in jQuery by nature. By using this plugin, we can add/remove arrows, dots, no of items in a slide based on device, no of items to scroll in a slide based on device, etc.

Create View Block

1. Create view block for slideshow contents and add your format to “unformatted list” and fields like “content”  or anything else that you want to the field settings.

Slideshow-view

2. View format should be “unformatted list” else we would need to alter the format by using CSS or render the contents in twig file.

Download slick library

  1. Download the slick library and paste it into /libraries folder in your Drupal site directory.
  2. Link: https://github.com/kenwheeler/slick.git
  3. Create a custom module and add the below code in module_name.libraries.yml file

Use hook_preprocess_page(&$variables)

 

Attach the library in Drupal hook_preprocess_page. Wherever you want to be based on the condition we can attach this library. Here I have attached on the front page.

Call Slick() function in js file

Here’s the trick for making the Drupal view slideshow responsive using jQuery by calling slick plugin function and attributes.

Calling slick function with the parent class of a view, slick starts rendering ultimately.

Page element screenshot

We should add .view-content while we call the slick function then only slick attributes will be added automatically with the generated HTML structure.

Add the below code in your js file i.e., custom.js

view-slideshow is nothing, but the parent class name of the view that we created here. For example, if the view name will be “slideshow” the view parent class will be as “view-slideshow” by calling the slick method from slick plugin it will automatically trigger the slider to slide.

By default, slick slider arrows are not showing because of white background. We can alter this through CSS or if you want to overwrite the arrows also possible in CSS by adding a background image.

Result will be like this

Slideshow Result


So now we have successfully integrated slick plugin and created the slideshow in Drupal 8. In the next blog, I will be discussing how we can make this plugin responsive using custom js.

Elements of a Digital Platform that creates Value

I have been studying about platforms for sometime now. I wrote about the transforming business model of the platform enabled web. How traditional business model used the already present resources to create a platform, where the new product was not the product itself but the Platform which became a product. Like we have known, a platform enabled ecosystem sets the rules of how the business is supposed to be ruled by the leaders, provides a direction and brings together people who provide value to each other.

But before we put together an ecosystem, we need to understand what makes a platform and changes ecosystem. To successfully build a platform there is a lot to be learnt and unlearnt. For a change in business model and make a platform, there has to be a vision which looks at the broader aspects of a problem and aims to solve it. A platform always caters to the larger audience. For establishing a functional platform, a clear understanding of the business and technology is fundamental to its success.

Platforms mostly focus on reusing resources and sharing it among common elements in a network.  Most platform definitions focus on the reuse or sharing of common elements across complex products or systems of production. It has an architecture that enables features to be added or existing ones to be removed.

To build a platform that adds value and enables businesses or individuals to connect is a challenging task. To design a platform, it is an absolute necessary to keep the vision in place. The core value that is the driving force of the platform. For Amazon, it is to connect sellers and buyers, establish a place or platform for their interaction. This should be inevitable and the most important aspect that will shape the platform.
 
A platform will necessarily consist of a few elements like the following :

  • Infrastructure
  • Roles and rules
  • Network
  • Data

The infrastructure is the skeleton and backbone of any platform. It will be the product of the platform. For Uber it is the main phone application that acts as an infrastructure along with its main mission and values. The roles and rules make the platform a functional entity and the network acts as a matchmaker to bring on drivers and riders to the platform. In all of these data acts as the heart of the operation and makes it moving forward.

The future will see more and more transformation of traditional businesses and products into platforms. That will build services and ad values instead of tapping on our pockets like products do.

But the underlying question to all of these remain as to how would you create a platform that adds value?

How to hide Order ID from commerce checkout process in Drupal 8

In Drupal, many a time we come across a situation where we want to hide certain URL part from end users.

To achieve this we often use Drupal modules like Pathauto to hide node IDs, taxonomy IDs from URL and replacing them with some patterns (eg. Titles).

The above scenario can not be achieved for Drupal commerce checkout flow(URLs) as the Drupal modules like PathAuto do not support this. To achieve this in Drupal 7 we often used one of the following ways mentioned below:

In Drupal 8, At the point of writing this blog Commerce checkout paths module is yet to be ported and URL bounding hooks have been replaced by a certain way which will help us to achieve e-commerce security by hiding sensitive information from URL.

Let’s demonstrate how to achieve e-commerce security in Drupal Commerce module by the following method: 

  • Create a custom module. In my case, I will be creating a module name Example.

  • Create a example.info.yml file.

  • Create a example.services.yml file. In this file, we will be creating tagged service with tags ‘path_processor_outbound’ and ‘path_processor_inbound’. This tags will help Drupal to call this service automatically which defines the purpose of tagged services. In our case, I have created below services.yml file. 

  • Create the service class ExamplePathProcessor as mentioned in service definition and this class file is located at /modules/custom/example/src/PathProcessor/ExamplePathProcessor.php.

    • This class will implements interfaces, ‘InboundPathProcessorInterface’ and ‘OutboundPathProcessorInterface’.

    • These interfaces are located at namespace 'Drupal\Core\PathProcessor\OutboundPathProcessorInterface’ and 'Drupal\Core\PathProcessor\InboundPathProcessorInterface’, so we must use this interfaces in our class file.

    • Our class file should look like below:

  • Please note that we have used other namespace like 'Drupal\Core\Render\BubbleableMetadata’ and 'Symfony\Component\HttpFoundation\Request’ which are required by our interface functions.

  • In the class definition the functions:

    • processOutbound is provided by OutboundPathProcessorInterface  interface and this function behaves exactly same as hook_url_outbound_alter of Drupal 7.

    • processInbound is provided by InboundPathProcessorInterface  interface and this function behaves exactly same as hook_url_inbound_alter of Drupal 7.

So, we are ready with our module and file structure. Now in Drupal commerce, there are various checkout steps where Order ID can be seen in the URLs. Our goal is to hide this Order ID from the end user. 

Let’s understand how the Order ID encryption/decryption process will work. 

Step - 1:  Let’s say user will come to the checkout page. This checkout page URL will be pass to Drupal.

Step - 2:  Drupal will find all the tagged services in it’s database and will come across our path processor service called example.path_processor_example.

Step - 3:  This service class will receive the path URL in the $path variable of the processOutbound function. This function will help us in encrypting/hiding our order id.

Screen Shot 2017-06-13 at 7.10.22 PM.png

Please note,

  • We can use any of the encryption algorithm/business rules to encrypt our order ID in the $path variable and return it as the function output.

  • Example, The URL '/checkout/123/order_information’  will become ‘/checkout/###/order_information’.

  • The ‘###’ is the encrypted hash.

Step - 4: As the URL '/checkout/123/order_information’  has become ‘/checkout/###/order_information’, the service will also execute it’s inbound function where we can decrypt/unhide the ‘###’ and find out it’s original value(Order ID).

Screen Shot 2017-06-13 at 7.09.51 PM.png

So, this is how we can use interfaces ‘OutboundPathProcessorInterface' & ‘InboundPathProcessorInterface’ along with their functions ‘processOutbound' & ‘processInbound’ to encrypt/decrypt the URL in checkout process of Drupal Commerce module.

Hope this helps you, Please feel free to reach out to me in the case of any queries and improvements.

The Role of users in Media and Publishing Industry

Reading and Entertainment has always been a social activity, print took to digital and digital to being connected. The emphasis on social and collaborative reading has garnered a lot of enthusiasm.
 
Much has been studied by scholars on this front about the impacts but the question remains as to What will the future of Publishing hold?
 
Kevin Kelly describes his thoughts about what the future holds in “What Books Will Become ":

“Prototype face tracking software can already recognize your mood, and whether you are paying attention, and more importantly where on the screen you are paying attention. It can map whether you are confused by a passage, or delighted, or bored. That means that the text could adapt to how it is perceived. Perhaps it expands into more detail, or shrinks during speed reading, or changes vocabulary when you struggle or reacts in a hundred possible ways”.  
 
Determining what the readers want is a difficult task, and the Media and Publishing industry is looking out for something that is in tune with the times. When technology is built for publishers broader aspects of disruption like Artificial Intelligence. Working with AI throws at us questions which are yet to have better answers from human prospects.

Downfall of the traditional news publishing industry

Traditionally news used to be about what has already happened, but today it is more about predicting what will. People are no more just pay to passively look through pages of texts but are engaging, interacting and popularizing information digitally. And there has been a massive fall in paid circulation from 1990 to the early 2000s.

Drop in paid circulation

Why has this happened?

Because one size doesn’t fit all. Personalization needs to be in practice and it needs to be real time. We are all focused towards experiences because that is what will drive user engagement. Clubbing AI and Real Time Personalization will be big and will take user engagement to bigger heights. Based on previous user data or real time tracking Publishers will have the ability to serve readers what spikes their interest right at that point. Machine Learning will help to enable personalization of content in real time.

What is the relevance?

Content creators, publishers, and their audience will be influenced by search engines and more relevant information. But like we have been thinking, it will not overthrow journalists. What it will do is produce content in more volume.

Take a look at Netflix, because we are all familiar with it. It started way back in 2006 with the announcement of The Netflix Prize:
 
“In 2006 we announced the Netflix Prize, a machine learning and data mining competition for movie rating prediction. We offered $1 million to whoever improved the accuracy of our existing system called Cinematch by 10%. We conducted this competition to find new ways to improve the recommendations we provide to our members, which is a key part of our business.”
 
What Netflix did way back then has been getting better and today they use ML to continuously improve user experience through personalization. They published an article on the recommendation system Netflix Recommendations: Beyond the 5 stars and this relates to the industry in a much deeper manner because here the end user plays the ultimate role to shape the content being displayed or recommended.

How to manage page layout using Display Suit module in Drupal 8

The Contributed module Display suite (“DS”) allows you to take control on How do you want to render them using interface. admin has ability to arrange nodes, comment,user data, views etc. provides drag and drop after as we do for managing field section.

If you want to build a drupal custom page and really don't have any drupal technical knowledge or coding skill or, you don’t want to write custom templates, and  for smaller stuff then you can go ahead with this Display Suite module. Is really helpful when it comes to replacing the default view of an entity to user defined view using application interface. It’s straightforward and simple that is why developer build this for community.

To enable Display suits in Drupal 8 site it required layout_plugin as it has dependency
 

Display Suite enable

So, let’s get started. Download “Display suits” and “layout plugin” module from drupal.org and place it in your module directory as you do for enabling your module. Once the module is enabled  you can find “Display suit” available in  admin >> structure page. 

 

Display suite in structure list

 To Create a Display Suit for your node create test node first for test purpose. Below content i have created in one of my local system.

Default article node view

To create/change the layout go to admin >> structure >> ds
On this page you will find “Manage display” for all the entity type. This manage display apply not only to the content type but also to all the entity on the site. On this page you will find 2 more menu item in quick tab.  

   1.Classes
     -- You can create custom css classes for your new region and assign back to them.
   2.Fields
     -- You can manage different display field to your region. By assigning some of the block , view or tem to the region.
 

Displays list

 

So, let’s go ahead and create display suits for article node.by clicking on “Manage display” 
Admin >> structure  >> types >> manage >> article >>display 

At the bottom you will find Layout for article in default tab, Select a layout and click on save button. As soon as you will select the layout you will get a layout preview. I have selected Three column

Layout for article
 

As soon as you save the configuration you will find the page layout with some of the group called left, middle, right. Assign your field to those group using drag and drop feature. And you are almost done. The below screen will help you to build drupal custom layout.

Group configuration

After rearranging my page looks like below screen. 

rearranging-dispaly

Let’s check out the entity view for article. As you can see page having 3 column left, middle, right

Firebug result for class

 

dispaly suite test page

 

Did you we have discussed #2 Classes quick tab, you can access them from below path 
Admin >> structure >> ds >>classes

This page is used for adding extra classes to the section you assign. We have seen it earlier, while creating Display suit it provide their own classes. If you want to add your own class then you can do this here.  
 

CSS classes for regions

As i have created three classes cust_class_left,cust_class_middle,cust_class_right

Added CSS classes for regions

 

So far we already created our custom class. It’s time to assign those classes to our region. Follow below path to add classed to the article bundle.
Admin >> structure >> types >> manage >> article >> display

You will find your new classes under custom classes quick tab.
manage custom classes


I have assigned for layout cust_class_left for left region , cust_class_right for right  region and cust_class_middle for middle region.
 

custom classes assigned

So let’s see how does it work in browser. Ok Perfect

firebug test

To add a Custom Wrapper to each region of you article entity you can add them from below path
Admin >> structure >> types >> manage >> article >>display
Go to “Custom wrappers” and select wrapper for each of the region.


custom wrappers

You will find new markup available for left, middle, center and outside container. So without writing any custom code you can add wrapper.

Custom wrapper in firebug

So far you must be familiar of Display suites and their usage. Some of the front end Developer must be thinking it’s similar to Panels. Yes you are absolutely right.  In this blog i have gone through creating a Display suit assigning their field to different region and adding custom wrapper & classes.

How to create Content Workflow for Media Enterprises

A Content Management Workflow is used by Media Enterprises to have control over authorship, editing and publishing accesses and roles assignment for altering states, cycles and content types for users.

Content Workflow is also known as Content Governance Model. A Content Workflow can define the roles, responsibilities, documentations and workflow of Content. Media enterprises have responsibilities to ensure they have a smooth workflow because it usually involves a lot of processes and people ranging from the author to the editor a publisher and also a creatives team. 

A defined model of workflow involves all the stakeholders from planning to publishing stage.

Content Workflow

Common Challenges

  • Access & Permissions
  • Extensible workflow states
  • Review contents before publishing it
  • Changes to content can be reviewed
  • Modify published contents without going live

Solutions prior to Drupal 8

  • Workbench Moderation
  • Workbench
  • Save as Draft

The Content Management Workflow is a module on Drupal 8. It can be used to create a content moderator experience for supporting content authorship and publishing.

Let's take a look at the ppt and video for more. I have also shared a demo at the end of the video.

How can a good Project Management ensure happy Drupal project delivery?

There is no tools or modules available for Drupal project management in drupal.org. It's all about your men and how you manage them. A few weeks back my colleague wrote about ‘How to set the right expectations for project delivery?’. 
 
I am a Drupal Project Manager and in this blog, I have written about the ways I manage a Drupal Project.
 
Let’s list down the core objectives of any project manager
 
A Drupal project is not something out of the world but a project which has focused Drupal development and maintenance tasks.
 
The main objectives are:

  • To Stay On Budget
  • Finish On-Time
  • Stay In-Scope
  • Create Quality 

But when it come to Drupal Project Management then these core objectives changes


Managing a Drupal Project
 
Involve your team in the planning and preparation process. This will enable you and your team to know how long things are going to take. You’ll be able to identify conditions and interdependencies. And after all, your team is based on Drupal expertise.
Include your team members while you are discussing the project, you also gain needed perspectives for architecture, development, and quality assurance, whether to create a module, whether to update, what components to take and what to drop.
 
What to do as a manager?

 

 

via GIPHY


Drupal project manager starts with creating a healthy team atmosphere, one in which everyone will bloom. Do remember that you represent the whole team when you face the client. 
 
How will you allocate resources?
 

via GIPHY


As a Drupal project manager we need to keep stakeholders happy and your Drupal developers busy. To ensure this, you must make sure to allocate resources and reduce drainage. The requirements and scope updates coming from client end are a good thing. 
Changes are inescapable in a project, and you need to find that balance between maintaining flexibility and assessing risk
Do take a stand regarding changes(suggested by the client) to do now or later; ask yourself are these changes for the right product needed?
 
How to make stuff work?
 

via GIPHY


 If you were a Drupal developer who is now a Drupal project manager: Don’t get involved in the coding. You can sure do get into the nitty gritty but that is not preferred. You are not to be obsessing over every line of codes. That is what your team is for. Let them do their job.
 
Don’t be afraid to get feedback from team members, stakeholders, or anybody else.
Admitting mistakes and accepting constructive criticism is leading by example. The rest of your team makes them, and so do you. Making the project about your pride is never a good idea. Feedback helps you become better than you were yesterday. How else can you expect to become otherwise?
 
How do you manage your time?
 

via GIPHY


Maintaining a daily and a weekly objective list might come off as pretty silly in today’s world, but it works. This isn’t just a to-do list it’s a motivator. Marking items as done will create satisfaction and maintain drive.
 
It's advice that you should first manage your own time and then others because you’re not only managing your time but everyone else too.
Almost everything can be broken down into small tasks, and that’s good news. Even the most complex projects are a mass of small tasks. Set targets and then break that into smaller entities. These could be weekly objectives and goals 
 
Talk Talk Talk - Communicate
 

via GIPHY


If there’s a delay, early communication with stakeholders is best. Client communications maintaining high levels of trust will increase confidence in the project team and ensure a smoother project flow.
 
I cannot stress more on the importance of this. Talk. That solves half the troubles. If your team is able to let you know about bottlenecks, you could at least make sure that is attended to.
 
Bonding with your colleagues is important. Being sure you take time out of your day to ask them about themselves is a must.
 
Drupal project management isn’t just a career it’s a mindset. I find myself addressing everything as a project. We put a lot of emphasis on client communication and stress on the details, that way it ensures we set the right expectations for a project delivery.
 
We create high-end experiences in Drupal for Media and Publishing, Hi - Tech and Pharma, all of these for a global clientele while ensuring the right tracks for handling a project. 

How will Artificial Intelligence power the future of Media and Publishing ?

The most important technology that is shaping the Media and Publishing Industry is Artificial Intelligence. Ideas have come and gone, business models have been scrapped. Publishing used to be only about Content and Distribution but now with the internet in everyone's hands problems like these have taken a back seat. The digital publishing industry is looking out for disruption and Digital Experience has become the key with personalization.

Beyond creating content that is tailored for the audience, AI can help content creators to provide with more data and relevant details for research relating to information which is difficult to be found even by the most experienced of authors in the Publishing sector.

What does the future look like?

While Machine Learning and Deep Learning can help and go a long way to assist in the Media and Publishing industry, it lacks in the ability to understand human behavior to give explanatory answers like Why Donald Trump did something he did? Here is where researchers say yet and that there is a future where AI might have answers to that too. If so be the case, is that journalists and content creators will lose jobs to Machines?

For the best, AI is all about making the best out of information and research on content. It aids to add context to come to a relevant decision.

The end of this decade will see the massive impact that AI is creating in the digital publishing industry. What is there today is just the beginning of it. The capabilities are vast and experience for an audience will be ever evolving.

How are companies evolving?

More and more companies in the Digital Publishing sphere will need to interact and understand the gap between them and consumers, communications will have to be more open and understanding about how content is perceived by individuals will have to be separated out and dealt with accordingly.

The best way to stay relevant is to stay ahead of the crowd. Be in sync with what Technology has to offer to the Publishing industry.

To cross the barriers of relevance or territory publishers will have access to information that helps to decide what kind of content gets traction, what exactly makes or break news and use prediction algorithms to keep the audience glued, boost site engagement.

Last year, Tribune Publishing announced that it has called tronc to focus on producing content using artificial intelligence. BuzzFeed is another company making around 65 to 75 videos per week.

The overall amount of content will explode for sure, but do you think Artificial Intelligence will help write content with a human context?

How is the ecosystem of a Platform Strategy

In a previous article I spoke briefly about how we have transformed as businesses and how platform strategy has disrupted traditional business models. A lot of industries are coming into action with an all inclusive model of platform strategy rather than a product and that is changing the pipeline of transactions. These are changing directions of organizations and holding out world leaders who are transforming lives of a lot of people.

Platforms have been here for hundreds of years. Traditional markets for one are those, but what technology has done is reducing the need of the entity to be a physical one. It reduces physical assets and added value by scaling up the platform, making it cheaper and enabling easier communications.

Uber and Airbnb will never cease to be examples of how platforms are disrupting traditional models. Uber has one platform and a number of products each geared towards a specific audience. What this has created is to provide value to an entire ecosystem and not a segregated community. What I’m trying to emphasis here with these mentions is that companies like the ones above are doing a business as a whole, it is complete in itself.

How does a platform shape a traditional business?

Not a lot of employees and customers are bothered by what your vision or mission statement is. What an end user sees is how much value are they getting out of such an interaction. To create and put into force a business platform for an organization and traditional business is disruptive and is a paradigm shift.

  • It creates a visibility and focuses on to the organization as a whole.
  • It puts you “out there”. Showcasing the values in truest of terms, it is like a vision or a mission what you are actually working on.
  • It creates endless connections and networking opportunities.

Out of these 3 aspects, one of the most important thing is the creation of networks.
To understand the bridge between gaps we must first understand the stakeholders involved. There will be a producer and a consumer. The producer can also be termed as a buyer and the consumer as a seller.

A seller or a producer in a business platform is the one who responds to the needs of a consumer, or in other words a producer can be the one to help create a demand in a market he is trying to establish himself.

A consumer or a buyer will be the one who is the one with the need and consumes a supply.

An important thing to understand here is that these are just roles and not two separate entity. They often exchange places and roles. LinkedIn is one such platform which best holds up interchanging roles of producers and consumers. The roles change rapidly but in the process makes sure that the interaction was of some value.

The network effect in enables scaling up of stakeholders in a large number. A lot of times, producers are consumers too. Exchanging the roles of buyers and sellers maintains the health of the ecosystem and ensures the flow of information and revenue in both directions.

“In an organization, enabling a platform enabled system sets the rules of how the business is supposed to be ruled by the leaders, provides a direction and brings together people who provide value to each other.”

 This happens without any direct involvement of any third party and here is where platforms come into play. They are governed by themselves. This is a system which leads businesses and leaders to greatness.

What differentiates your platform is how you create that value. Are you creating value?

 

Download the Drupal Guide
Enter your email address to receive the guide.
get in touch