description | edition |
---|---|
Use PHP API to manage shipping methods in Commerce. Create and update shipping methods, delete shipping methods and their translations. |
commerce |
To get shipping methods and manage them, use the Ibexa\Contracts\Shipping\ShippingMethodServiceInterface
interface.
Shipping methods are referenced with identifiers defined manually at method creation stage in user interface.
To access a shipping method by using its identifier, use the ShippingMethodServiceInterface::getShippingMethod
method.
The method takes a string as $identifier
parameter and uses a prioritized language from SiteAccess settings unless you pass another language as forcedLanguage
.
[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 61, 71) =]]
To access a shipping method by using its ID, use the ShippingMethodServiceInterface::getShippingMethod
method.
The method takes a string as $id
parameter and uses a prioritized language from SiteAccess settings unless you pass another language as forcedLanguage
.
[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 49, 59) =]]
To fetch multiple shipping methods, use the ShippingMethodServiceInterface::getShippingMethod
method.
It follows the same search query pattern as other APIs:
[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 73, 91) =]]
To create a shipping method, use the ShippingMethodServiceInterface::createShippingMethod
method and provide it with the Ibexa\Contracts\Shipping\Value\ShippingMethodCreateStruct
object that you created by using the newShippingMethodCreateStruct
method.
[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 92, 116) =]]
To update a shipping method, use the ShippingMethodServiceInterface::updateShippingMethod
method and provide it with the Ibexa\Contracts\Shipping\Value\ShippingMethodUpdateStruct
object that you created by using the newShippingMethodUpdateStruct
method.
[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 118, 133) =]]
To update a shipping method, use the ShippingMethodServiceInterface::deleteShippingMethod
method.
[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 134, 140) =]]
To delete shipping method translation, use the ShippingMethodServiceInterface::deleteShippingMethodTranslation
method.
[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 142, 151) =]]