Magento 2 Create a Configurable product using SOAP API

Uploading a Simple product in Magento is pretty easy and straightforward. Creating a configurable product is a little bit more difficult.

In this post you’ll see C# code on how to create a configurable product in Magento 2 using the SOAP API. There’s not a lot of sources on the internet for this and it took me a while to figure this out.

This is how it works:

  • Create and upload the simple products (and don’t forget their SKU’s)
  • Create and upload the configurable product (specify the attribute that’s changing and don’t forget it’s SKU)
  • Link the simple products to the configurable product

Now let’s get started.

Create and upload the simple products

Create and upload the configurable product

You’ll see I make a call to my own method GetProductAttributesByAttributeSetAsync. Basically it’s used to know the attributes of the attributeSet the product is in. I have made my own attributes like color_config or size_config. If an attributeSet has an attribute with _config in the name it registers this as productOption. These are the options that will have a dropdown in your product page.

You need to configure product options in your configurable product

Link the simple products to the conifgurable product

 

Removing the H1 title from a category in Magento 2

The huge H1 title personally annoyed me in the Magento 2 categories so I decided to remove it. Turns out it’s pretty easy.

Go to your category and click Design. Insert this code:

Clear the cache and refresh.

Solving Bannerslider Class Magestore\BannerSlider\Ui\Component\Listing\Column\Image does not exist

So we wanted to have a Banner Slider on our Magento 2 frontpage and Magestore provides one for free. After installing using their tutorial on GitHub I wanted to configure the banners.

It soon became clear that this was not going to be an in install and go type of application.

If you click Content -> Manage Banners you’ll get this exception: Class Magestore\BannerSlider\Ui\Component\Listing\Column\Image does not exist

This is triggered by some sloppy coding that has uppercase BannerSlider mixed up with lowercase Bannerslider. So to solve it you would need to replace all occurrences of BannerSlider to Bannerslider.

This is pretty easy on linux. All you need to do is this:

  • Login to your system using SSH
  • Navigate to this folder:

  • Issue this command:

  • Check if everything has been replaced:

  • Clear the cache and everything should be working.

Disable the H1 title in Magento 2 on the Homepage

Disabling the H1 title in Magento 2 is a fairly simple process. You first need to override the Magento blank or luma theme and navigate to this folder:

Of course you’ll need to replace <vendor> and <theme> with your own values. Inside the folder you need to create or edit the file cms_index_index.xml.

The content of the file should be:

Flush the cache, reload the page and voila.

Magento 2 disable product compare

If you’re going to override the Magento theme then I really would advise against modifying  the Magento core files. A better practice is to create your own theme and override all the files you need. This way you can update Magento with much less worries. How you create your own theme is for another episode.

Supposing you have created your own theme you should have a directory structure that looks something like this:

In my case, the theme is called desktop.

In the desktop folder, create a directory called Magento_Catalog.

And in the Magento_Catalog folder, create another directory called layout.

Now, with nano, create a file called default.xml

In the default.xml file, insert:

Clear the cache and you’re done.

Magento 2 Disable advanced search link in topmenu

If you’re going to override the Magento theme then I really would advise against modifying  the Magento core files. A better practice is to create your own theme and override all the files you need. This way you can update Magento with much less worries. How you create your own theme is for another episode.

Supposing you have created your own theme you should have a directory structure that looks something like this:

In my case, the theme is called desktop.

In the desktop folder, create a directory called Magento_Search.

And in the Magento_Search folder, create another directory called layout

Now, with nano, create a file called default.xml

So if you were paying attention you now have:

In the default.xml file, insert:

Clear the cache and you’re good to go.

Creating a new Magento 2 Integration to consume with c-sharp and the SOAP API

So you want to use c-sharp to access your Magento 2 instance? Join the club. Unfortunately, there’s not a lot of documentation so I’m writing stuff on my blog as I go along, hoping it will be useful for someone.

If you want to access your Magento 2 instance with c-sharp then for starters, you’ll need to create an Integration.

In Magento 2 goto

  • System, Extensions -> Integrations

Configure as follows:

 

  • In the API tab you can configure the access of the user:

Magento 2 SOAP API with C Sharp adding Service References

If you’re just starting out with Magento 2 and you’re coming from Magento 1, you’ll immediately see the difference in terms of the SOAP API.

It seems the developers have opted to split the functionality into several smaller units. It increases security but adds a little bit of complexity. Nothing that can’t be overcome.

You can combine the service request using commas so you don’t need to have 50 or so different services. You can read all about it on the Magento SOAP reference page.

I’ve grouped them into the Magento categories on their website. You can see the Service Reference URL for Visual Studio below together with the ServiceReference name. Don’t forget to change www.domain.com to your domain.

Warning: i’ve had mixed results with this approach. Sometimes you’ll get messages like “catalogProductRepositoryV1SaveRequest not present”. Use it at your own risk but I would not recommend it. Splitting the services up solves the issue…

ServiceReferenceMagentoBackend

ServiceReferenceMagentoBundle

ServiceReferenceMagentoCatalog

* For some reason, the service catalogProductGroupPriceManagementV1 cannot be added so I have omitted it.

ServiceReferenceMagentoCheckout

ServiceReferenceMagentoConfigurable

ServiceReferenceMagentoCustomer

ServiceReferenceMagentoDownloadable

ServiceReferenceMagentoEav

ServiceReferenceMagentoGiftMessage

ServiceReferenceMagentoIntegration

ServiceReferenceMagentoQuote

ServiceReferenceMagentoSales

ServiceReferenceMagentoTax

  • So now we import the individual service’s into Visual Studio like this:

  • And then we rinse and repeat for every service reference:

Magento 2 CatalogProductRepositoryV1SaveRequest not available in API

When you’re starting out with the Magento 2 API in c# (c sharp) you’ll notice it’s quite different from the previous version.

The API has been split up into different pieces to, among other things, address security concerns. This means you’ll probably need to add several Service References to get the job done.

My goal was to insert products trough the Web API. To my surprise it seemed the CatalogProductRepositoryV1SaveRequest method was missing from the http://www.xxx.yyy/soap/default?wsdl=1&services=catalogProductRepositoryV1 service…

I have not found any other solution than to override security in the file /vendor/magento/module-webapi/Model/AbstractSchemaGenerator.php.

Allowing anonymous web access does not help…

Now before you start making changes, it’s best to backup the file. Also note that this should be a temporary solution and it creates a security issue. Anyone can now see (but not use) this method when requesting the wsdl from the service.  Also, when updating Magento there is a probability it will be overwritten. You have been warned.

The two changes are highlighted in yellow.

 

Magento 2 sending e-mail trough Outlook 365 Smtp

Like many others out there, we’re running our own VPS (Virtual Private Server) for our Magento 2 instance. This allows us full control over the code, security and it’s also pretty fast.

When using a VPS, you’ll need to setup e-mail yourself. You can save yourself the trouble if you have an Office 365 subscription. The only thing you have to do then is to make Magento send e-mails using the Outlook 365 Smtp server.

  • Navigate to your Magento 2 app/code directory

  • Make a directory structure like this:

 

The text in red is what’s probably different in your instance or what you’ll have to change.

  • In the folder Smtp, make a file called registration.php and insert the content from below. Make sure you change Organization_Smtp to what is appropriate for you. Don’t forget to chmod +x it :-).

  • In the folder etc, you’ll need to make two files: di.xml and module.xml

Insert the content below for di.xml and don’t forget to change Organization to what is appropriate for you.

Insert the content below for module.xml and don’t forget to change Organization to what is appropriate for you.

  • In the folder Module, you’ll need to make a file called Transport.php and insert the content below. Change Organization and username / password to what’s appropriate for you. Don’t forget to chmod +x it.

  • Now if you would order something, the confirmation e-mail will be sent trough the Outlook 365 Smtp service (if the sender is a valid Office 365 client).