Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 0 additions & 121 deletions acl.md

This file was deleted.

55 changes: 34 additions & 21 deletions add-custom-shipping-carrier.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,20 @@ carrier configurations, and frontend integration.
The first step in adding a custom shipping carrier is creating the necessary directory structure
for the Mage-OS module:

```bash
app/code/MageOS/ShippingCarrier/
```text
app/code/Vendor/ShippingCarrier/
├── registration.php
├── composer.json
├── etc
│ ├── module.xml
│ ├── config.xml
│ ├── adminhtml
└── system.xml
├── Model
│ └── Carrier
│ └── CustomCarrier.php
│ └── adminhtml
│ └── system.xml
└── Model
└── Carrier
└── CustomCarrier.php
```

Create register module file `app/code/MageOS/ShippingCarrier/registration.php`
Create register module file `app/code/Vendor/ShippingCarrier/registration.php`

```php
<?php
Expand All @@ -44,23 +43,23 @@ ComponentRegistrar::register(
);
```

Next, you need to declare your module in `app/code/MageOS/ShippingCarrier/etc/module.xml`:
Next, you need to declare your module in `app/code/Vendor/ShippingCarrier/etc/module.xml`:

```xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MageOS_ShippingCarrier"/>
<module name="Vendor_ShippingCarrier"/>
</config>
```

## Shipping Carrier Configuration

In the `config.xml` file, define the shipping carrier's core settings, such as its active state,
title, and allowed countries. Create `app/code/MageOS/ShippingCarrier/etc/config.xml`:
title, and allowed countries. Create `app/code/Vendor/ShippingCarrier/etc/config.xml`:

```xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Shipping/etc/config.xsd">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<carriers>
<customcarrier>
Expand All @@ -70,7 +69,7 @@ title, and allowed countries. Create `app/code/MageOS/ShippingCarrier/etc/config
<shipping_cost>10</shipping_cost>
<sallowspecific>0</sallowspecific>
<sort_order>15</sort_order>
<model>MageOS\ShippingCarrier\Model\Carrier\CustomCarrier</model>
<model>Vendor\ShippingCarrier\Model\Carrier\CustomCarrier</model>
</customcarrier>
</carriers>
</default>
Expand All @@ -81,14 +80,14 @@ Explanation:

- active: Enables or disables the custom carrier.
- title: The name displayed in the checkout.
- name: Internal name of the carrier.
- name: The method name displayed in the checkout next to the title.
- model: The path to the custom shipping carrier model.
- shipping_cost: The amount of the handling fee.
- shipping_cost: The fixed shipping price charged for this method.

## Admin Configuration for Carrier

To allow store administrators to configure the shipping method, we define settings in
`app/code/MageOS/ShippingCarrier/etc/adminhtml/system.xml`:
`app/code/Vendor/ShippingCarrier/etc/adminhtml/system.xml`:

```xml
<?xml version="1.0"?>
Expand Down Expand Up @@ -136,8 +135,9 @@ To allow store administrators to configure the shipping method, we define settin
</config>
```

This configuration allows administrators to enable the carrier, set a title, and configure a handling
fee through the Mage-OS admin panel.
This configuration allows administrators to enable the carrier, set a title, and configure the shipping
cost through the Mage-OS admin panel, under **Stores > Configuration > Sales > Delivery Methods > Custom Shipping
Module**.

## Shipping Carrier Model

Expand All @@ -148,7 +148,7 @@ This class extends Mage-OS's abstract shipping carrier class and implements the
<?php
declare(strict_types=1);

namespace MageOS\ShippingCarrier\Model\Carrier;
namespace Vendor\ShippingCarrier\Model\Carrier;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Quote\Model\Quote\Address\RateRequest;
Expand Down Expand Up @@ -228,13 +228,26 @@ class CustomCarrier extends AbstractCarrier implements CarrierInterface
Explanation:

- collectRates(): Calculates shipping rates based on the quote request and returns them.
Here, a fixed rate of 10.00 is used.
Here, the rate is the configured Shipping Cost (`shipping_cost`, 10 by default).
- getAllowedMethods(): Returns the allowed shipping methods for this carrier.

## Enable the Module

Enable the module and apply the changes:

```bash
bin/magento module:enable Vendor_ShippingCarrier
bin/magento setup:upgrade
bin/magento cache:flush
```

## Frontend Integration

Once the backend logic is in place, the custom shipping carrier will automatically appear in the Mage-OS checkout
if it's enabled and configured properly. The title and price will be displayed as defined in the carrier configuration.
For a destination outside **Ship to Specific Countries**, the carrier is hidden. With **Show Method if not applicable**
set to Yes, it's listed as unavailable with the message "Sorry, but we can't deliver to the destination country with
this shipping module."

## Conclusion
This guide walks through the basic setup of a custom shipping carrier in Mage-OS. The carrier integrates with Mage-OS’s shipping framework, allowing you to customize the shipping calculation and display it during the checkout process. You can extend this basic structure to integrate with third-party APIs, offer dynamic shipping rates, or introduce more complex shipping logic based on cart contents or customer information.
Loading
Loading