1. Go to this page and download the library: Download marshmallow/keen-delivery library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marshmallow / keen-delivery example snippets
use Marshmallow\KeenDelivery\Traits\KeenDelivery;
class Order
{
use KeenDelivery;
// ...
use Marshmallow\KeenDelivery\Traits\KeenDelivery;
class Order
{
use KeenDelivery;
// ...
/**
* Keen Delivery
*/
public function getDeliveryReference(): string
{
return __('Shipment for order: #:order_id', [
'order_id' => $this->id,
]);
}
public function getDeliveryCompanyName(): ?string
{
return $this->shippingAddress()->company_name;
}
public function getDeliveryContactPerson(): ?string
{
return $this->shippingAddress()->name;
}
public function getDeliveryStreet(): string
{
return $this->shippingAddress()->address;
}
public function getDeliveryNumber(): string
{
return $this->shippingAddress()->house_number;
}
public function getDeliveryAddition(): ?string
{
return $this->shippingAddress()->house_number_addon;
}
public function getDeliveryZipCode(): string
{
return $this->shippingAddress()->postal_code;
}
public function getDeliveryCity(): string
{
return $this->shippingAddress()->city;
}
public function getDeliveryCountry(): string
{
return $this->shippingAddress()->country?->id ?? 'NL';
}
public function getDeliveryPhone(): ?string
{
return $this->customer->phone_number;
}
public function getDeliveryEmail(): ?string
{
return $this->customer->email;
}
public function getDeliveryComment(): ?string
{
return null;
}
public function getDeliveryPredict(): ?string
{
return '';
}
/**
* Return the weight in kilo's
*/
public function getDeliveryWeight(): ?int
{
return 1;
}
public function getCustomDeliveryData(): array
{
return [
/**
* Use email notifications for DPD
*/
'predict' => 2,
];
}
$order->createShipment()
public function fields(Request $request)
{
// ...
MorphMany::make(__('Deliveries'), 'deliverable', Delivery::class),
}
use Marshmallow\KeenDelivery\Facades\KeenDelivery;
public function fields(Request $request)
{
// ...
KeenDelivery::shipmentInfoField(),
}
public function filters(Request $request)
{
return [
new ShipmentNotifiedFilter,
];
}
public function actions(Request $request)
{
return [
//
new SubmitForShipment,
];
}
public function actions(Request $request)
{
return [
//
new DownloadLabels,
];
}
use Marshmallow\KeenDelivery\Facades\KeenDeliveryApi;
KeenDeliveryApi::verifyApiToken();
KeenDeliveryApi::listShippingMethods();