Adding a Custom Method to a nopCommerce Core Service in a Plugin

In nopCommerce, you can extend a core service to include a new method and new functionality using both dependency injection and inheritance. For this example, we’ll use TaxService provided in Nop.Services.

Implementation

First, create a new interface in your plugin that inherits from the core service interface:

// ICustomTaxService.cs

using Nop.Services.Tax;

namespace YourNamespace
{
    public interface ICustomTaxService : ITaxService
    {
        void YourCustomMethod(); 
    }
}

After creating the interface, create the implementation class, inheriting from both the newly created interface and the base service:

// CustomTaxService.cs

namespace YourNamespace
{
    public class CustomTaxService : TaxService, ICustomTaxService
    {
        // constructor passing in all dependencies using base()
        public CustomTaxService(...) : base(...)
        
        public void YourCustomMethod() {
            // implementation here
        }
    }
}

Finally, make sure to connect the interface to the implementation in your plugin’s DependencyRegistrar.cs file:

class DependencyRegistrar : IDependencyRegistrar
{
    public int Order { get { return 1; } }

    public void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
    {
        builder.RegisterType<CustomTaxService>().As<ICustomTaxService>();
    }
}

Usage

Once the above is created, you can reference the new service using the interface created (usually, this is done in a controller or a service):

private readonly ICustomTaxService _customTaxService;

public WarrantyTaxService(
    ICustomTaxService customTaxService
){
    _customTaxService = customTaxService;
}

// now use the service for anything you need!

Book Notes – Digital Minimalism

Digital Minimalism by Cal Newport lays out the benefits and then steps of using a more deliberate approach of selecting technology that benefits oneself. This book shares the same writing tone of Deep Work, providing a lot of examples for the different principles explained in the book.

Digital Minimalism is defined as “a philosophy of technology use in which you focus your online time on a small number of carefully selected and optimized activities that strongly support things you value, and then happily miss out on everything else.”

Overall, a pretty good read. For someone that generally follows Cal’s line of thinking, it was nice to read some of the examples (gives some inspiration) alongside the different ideas provided to balance between using technology for your own benefit and getting sucked into overuse.

Outline

The book provides a collection of steps that can be outlined below:

Digital Minimalism Principles:

  • Clutter is costly.
  • Optimization is important.
  • Intentionality is satisfying (intention trumps convenience)

Digital Declutter process – set aside all optional technologies for 30 days, then reintroduce them slowly into life after the habit for checking regularly disappears.

Digital Minimalism Practices:

  • Leave your phone at home
  • Take long walks (without headphones, use this time to think intentionally)
  • Write letters to yourself (process of writing more important than outcome)
  • Spent time alone (provides solitude)
  • Don’t click “Like” (prioritize high-value conversation vs. low-value communication, more below)
  • Consolidate texting
  • Fix or build something every week
  • Schedule your low-quality leisure
  • Join something
  • Follow leisure plans
  • Delete social media from your phone (just use on desktop/laptop)
  • Turn your devices into single-purpose computers (limit options available for general-purpose device at certain times)
  • Use social media like a professional (remember that social media companies spend millions to keep you invested as long as possible, get just the basic needs you need from it)
  • Embrace slow media
  • Dumb down your smartphone

Conversation vs. Communication

In her book Reclaiming Conversation, Turkle makes a distinction between:

  • High-value conversation, committed face to face conversation with others
  • Low-value communcation, asynchronous communication with others usually via digital means

This ties into the idea of staying away from something like “Likes” on social media – focus on dedicated conversations with others, which makes for a more fulfilling social life as a whole over trying to spread communication thin.

Personal thought: Interesting the idea that something like using social media makes you think you could miss out on what people are doing- but you can always reach out individually to the people you care about to check in!

Book Notes – The Shallows (What the Internet is Doing to Our Brains)

The premise of the book is that as we move into integrating the Internet into our lives more and more, we are shifting from thinking deeply and creatively on topics, to learning quickly on a surface level.

Brain Plasticity

The brain is capable of being rewired and redeveloped through-out the entirety of a human life – even if that ability slows down in age. This applies in many cases such as the loss of capabilities (blindness, loss of limb, etc.) – the gray matter will be rerouted in the brain to other functions.

Plasticity, however, means that as changes occur in a person’s thinking and interaction, they can have lasting effects on how the brain processes in the future. In a sense, we become how we think and practice.

Connection to Medium

In writing and creation, there is a sort of tie-in that correlates to the medium being used to express. For instance, the way a book is written will change if the book is written online (where hyper-linking is available) or written in a paper-back book.

Prime example in this when using a Kindle (which I usually use to read), you have the ability to go to different websites and look up words right on the device – therefore diverting from the general process of reading the book from start to finish (took a look while writing this – no way to turn that off on the Kindle unfortunately).

In the comparison to digital vs. print, there’s also the connection between mutable (digital) vs. immutable (print). This makes for a push of more speed vs. quality, as publishing has become more of an ongoing process. This could remove the pressure of perfection seen in writing an immutable novel.

Personal note: I don’t see the above as an issue, although I’m sure I’m biased being in software. In this case, I see it as more of a “perfect is the enemy of good”.

Internet as a Medium of Distraction

The Internet serves as a medium that promotes distraction, which comes from sources such as:

  • Social media (engineered to provide stimulus rewards for checking regularly, much like a rat pulling a lever)
  • Page layout (advertisements)
  • Pop-ups

This does potentially come with some benefit – because browsing the internet promotes a shallow and quick level of thinking, it can keep minds sharp. However, this can mean we become good to identifying information and losing the ability to think creatively (especially thinking our own thoughts) on particular topics. Neuropyschologist Jordan Grafman says “The more you multitask, the less deliberative you become; the less able to think and reason out a problem.”

The major issue comes into the difficulty of learning and processing when our cognitive load is increased by use of the Internet (cognitive load – information flowing into our working memory at any given moment). Essentially, we can only handle so much information (2-4 things max) at a time before our ability to absorb information is diminished, and the information just rolls off.

Memory Collection, Digital vs. Biological Memory

When making memories, we have two types:

  • Short-term – like RAM, in working thoughts
  • Long-term – like HDD, stored away in brain

Short-term memories become long term memories after a period of time and reinforcement, where they gain new context on each subsequent retrieval and storage.

This changes with technology – memories are stored with no context, and as they are, which can limit their usefulness.

Personal note: This is another I don’t necessarily see a negative. It’s been proven that human memory is flawed, and our long-term memory is tarnished over time, moving away from reality over time and becoming what we want to believe. Using technology to store memories is a way to ensure those memories can be viewed intact. Something like writing a journal can show the thoughts of a particular experience at the time, and seeing how they compare to the long-term memory stored.

Tool Usage and Dependence

When using tools to amplify output (using a calculator to perform simple math, or using physical tools to perform labor), this has a numbing effect on our ability to perform the task ourselves.

This can especially apply in the software we use when interacting with a computer. A study of different users for software using both helpful and unhelpful software showed “The subjects using the bare-bones software consistently demonstrated “more focus, more direct and economical solutions, better strategies, and better imprinting of knowledge.” The more that people depended on explicit guidance from software programs, the less engaged they were in the task and the less they ended up learning.”

This reflects in the way we search for information – we use tools that provide easy results without contemplation on our end, limiting the amount of creativity we can apply to our work.

Set up nopCommerce 4.2 on a Linux Azure VM

Infrastructure Setup

First, create a Ubuntu-based VM, opening ports 80, 443, and 22.

Afterwards, create an Azure SQL Database.

VM Configuration

Once all of the infrastructure is created, set up a DNS record for the public IP created for the VM to make access easier.

Next, SSH into the VM using the domain name created above. Run the following commands to install the .NET Core runtime and SDK:

wget -q https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

sudo add-apt-repository universe
sudo apt-get update
sudo apt-get install apt-transport-https
sudo apt-get update
sudo apt-get install aspnetcore-runtime-2.2 dotnet-sdk-2.2

Next, install and enable nginx:

sudo apt-get install nginx
sudo systemctl enable nginx
sudo systemctl start nginx

Edit /etc/nginx/sites-available/default:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name   YOUR_DOMAIN.com;

    location / {
        proxy_pass         http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

Finally, restart NGINX:

sudo systemctl restart nginx

Set up NopCommerce

This step will lay out the process of downloading the NoSource version of nopCommerce and getting it running.

If you have a custom copy of nopCommerce from source, you would publish it and use the output here instead.

If starting from scratch, run the following:

sudo wget https://github.com/nopSolutions/nopCommerce/releases/download/release-4.20/nopCommerce_4.20_Source.rar

sudo apt-get install unrar -y
mkdir nopSource
unrar x nopCommerce_4.20_Source.rar nopSource

cd nopSource/src
dotnet clean -c Release
dotnet build -c Release

cd Presentation/Nop.Web
sudo mkdir /var/www/nop
sudo dotnet publish -c Release -o /var/www/nop

cd /var/www/nop
sudo mkdir bin
sudo mkdir logs

cd ..

sudo chown -R www-data:www-data nop/

Now create the nopCommerce service by creating file /etc/systemd/system/nop.service:

[Unit]
Description=nopCommerce

[Service]
WorkingDirectory=/var/www/nop
ExecStart=/usr/bin/dotnet /var/www/nop/Nop.Web.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=nop
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false

[Install]
WantedBy=multi-user.target

Enable the above service:

sudo systemctl enable nop.service
sudo systemctl start nop.service

Once this is all set, you should be able to install the store, using the Azure SQL Database created above. When installing, you may want to use the connection string provided by Azure:

While installing, you’ll likely see a 504 timeout from NGINX – this is okay, just give some time for the installation to finish, and you should be able to eventually see the store front.

Set up SSL using Let’s Encrypt

To set up Let’s Encrypt, follow the Certbot directions, making sure to enable auto-redirect.

Afterwards, make the following change to the appsettings.json file:

"Hosting": {
    //Set to "true" the settings below if your hosting uses a load balancer$
    "UseHttpClusterHttps": false,
    "UseHttpXForwardedProto": true,

Restart the NopCommerce service and ensure you can view the front page without an SSL warning.

Set up Auto-Renewing Let’s Encrypt Certificates on App Service Linux

Set up the ability to assign auto-renewing Let’s Encrypt certs to an Azure App Service Linux instance with shibayan’s appservice-acmebot. This will create a Function App that automatically updates the App Service as needed.

Before getting started, you’ll need to have a few things:

  • An Azure App Service (Linux-based).
  • DNS records being served using Azure DNS.

Procedure

First, deploy the solution to your Azure subscription. Use the following for configation:

  • Resource group – certbot-rg
  • App Name Prefix – certbot-fa
  • Mail Address – your email address.

Next, set up the ability for the Certbot function app to access your Linux App Service

  • Select ‘App Service Authentication’ to on.
  • Set ‘Log in with Azure Active Directory’
  • Set up the ‘Azure Active Directory’ Auth Provider
    • Set Management mode to ‘Express’
    • Create a new AD app
  • Save changes.

Now, assign the Website Contributor and Web Plan Contributor roles to the Certbot function app:

Finally, restart the function app and access the Function App URL (https://your-function-app.azurewebsites.net/add-certificate). You should be able to see the UI showing the available RGs and App Names available (access can take 30-60 minutes to reflect in Azure, so if you’re seeing a 401, wait a while for things to resolve):

Once the certificate is added, you’re all set! Renewals will automatically occur, as the app will scan regularly to check when to renew the certs.

Quickly Work With Graylog Streams Using the API

When using Graylog, you may run into a case where you’re making a large number of streams to organize data. A quick way to do this is to use the API to programmatically add the streams to the system quickly.

Authorization

For authorization, you can use Basic Auth with your username and password.

You can also create an access token to allow access for individual systems.

Interact with API

Use the GET endpoint to get the streams payload:

https://YOUR_GRAYLOG_ENDPOINT/api/streams

Grab one of the streams and format the payload to use for the POST endpoint, and then insert the streams using the API.

You can check the API browser for more endpoints at https://GRAYLOG_ENDPOINT/api/api-browser.

Setting up my Android Device

Initial Setup

First, go through the default setup, connecting to Wi-Fi and Google.

Turn off backup to Google Drive.

Set up all of the methods of accessing phone (face recognition, etc.)

Configuration

  • Turn on night mode.
  • Set resolution to max.
  • Set navigation bar to full screen gestures
  • Show battery percentage
  • Set sound mode to vibrate

Turn off Bixby home.

Install the following apps from the Play Store:

  • Outlook (login, turn off notifs, swipe right delete, turn off focused inbox, week start Monday, set calendar widget)
  • Firefox (sign in)
  • Messenger (sign in, turn on dark mode, turn off chat bubbles)
  • Dropbox (sign in)
  • Instagram (sign in)
  • Netflix (sign in)
  • YNAB (sign in)
  • Slack (sign in)
  • Fly Delta (sign in)
  • Ecobee (sign in)
  • Fi (sign in)
  • Fitbit (sign in)
  • WhatsApp (sign in, turn off notifs)

Configure the following:

  • Youtube (turn on dark mode)

Uninstall the following:

  • Duo
  • Drive
  • Galaxy Wearable
  • Google Play Movies & TV
  • Kids Home
  • Photos
  • Samsung Global Goals
  • Samsung Health
  • Samsung Pay
  • Smart Switch
  • SmartThings
  • Spotify

Moving Resources to a Different Azure Tenant

Let’s say you have some resources in your Azure tenant that you want to move to a different tenant (such as if you’re going to transfer ownership of a particular set of resources to another company). You can do that with the following steps:

Move Existing Resources to A New Subscription

  1. Create a new subscription in your current tenant as the current account admin (use your own information, which you will change over later so you can be an Account Admin).
  2. Rename the subscription to something more meaningful to avoid confusion.
  3. Sign into your tenant and move the desired resources over to the new subscription (you may need to recreate certain resources as some resources cannot be moved).
    1. If running any VM backups, you’ll need to delete all images before you can move a VM over. After moving over, make sure to turn backups back on.

Transfer Subscription

Next, create a new Microsoft account, and create an Azure account to transfer the subscription to – using the phone and credit card of the responsible party. When going through this process, you’ll either need the person by you when setting up the account, or have them set it up on their own.

Once the account is created, go back to the newly created subscription from above and transfer billing ownership using the email account of the Azure account from above:

Setting up the transfer request will send an email to the above – and give them the directions to accept the transfer.

Additional Steps

Once the transfer is done, they will own the resources. Here’s a few more steps you may want to take:

Set up Custom Domain for Azure AD

To set up the ability to use a domain for login to the tenant, you’ll need DNS access to a preferred domain.

Create an Administrative User

If you want to keep the ability to administer the resources, create a user for yourself and give them the following:

  • Global Admin rights in Azure AD
  • Owner rights to the subscription

Upgrading nopCommerce

Upgrading nopCommerce is a manual process that requires a decent amonut to work to get in place. When upgrading, you’ll need to upgrade sequentially (3.80 -> 3.90 -> 4.00 -> etc.).

NOTE: When performing this process on a live site, make sure to close the store during the upgrade process so no changes occur on the site during upgrade.

Upgrade Database

First, you’ll need to upgrade the database using a script provided by nopCommerce. Download the script here based on the version and apply the changes in the SQL script to a copied version of the database.

Upgrade Site Files

The script above with have a README.txt file that describes the next steps, which is essentially:

  • Download the source code for the upgrade version
  • Porting over the specific configuration files (Settings.txt, InstalledPlugins.txt, etc.) and making sure to point to the newly created database above.

If storing images on the filesystem, make sure to copy images over in /Content/images as well.

At this point, you should be able to see the front page of the site.

Restore Theme

If you were using a theme in the previous version, you’ll need to get the correct version of it and restore it.

First, if there are any SQL scripts for the theme, run those on the upgraded database.

Upload the theme to the nopCommerce installation, alongside any plugins required by the theme.

After this is done, check the site again and confirm the new theme is being used.

Restore Plugins

Finally, go through the plugins from the original site and add the appropriate version. If you’re using the source code version of nopCommerce, you’ll want to make sure the plugin is set up to use the latest version of nopCommerce, and that it compiles.

Some plugins will require database upgrades as well.