PHP code example of ray-nl / sendcloud-for-simple-commerce

1. Go to this page and download the library: Download ray-nl/sendcloud-for-simple-commerce 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/ */

    

ray-nl / sendcloud-for-simple-commerce example snippets

bash
php artisan sendcloud:generate-shipping-methods
bash


namespace App\Actions;

use DoubleThreeDigital\SimpleCommerce\Facades\Order;
use Illuminate\Support\Facades\Storage;
use RayNl\SendcloudForSimpleCommerce\Services\SendcloudService;
use Statamic\Actions\Action;
use Statamic\Contracts\Entries\Entry;

class DownloadLabel extends Action
{
    public function visibleTo($item)
    {
        if ($item instanceof Entry) {
            return $item->collection->handle === 'orders';
        }

        return false;
    }

    public function visibleToBulk($items)
    {
        return false;
    }

    public function download($items, $values)
    {
        foreach ($items as $item) {
            $shippingMethod = new ($item->shipping_method->first())();
            if ($shippingMethod->getSendCloudId() !== null) {
                if (!Storage::exists("labels/{$item->order_number}/label-{$item->order_number}.pdf")) {
                    if ($item->sendcloud_id !== null) {

                        $sendcloud = new SendcloudService();
                        $sendcloud->getParcelFromId($item->sendcloud_id);
                        $sendcloud->createLabel($shippingMethod->getSendCloudId());

                        Storage::put('labels/' . $item->order_number . '/label-' . $item->order_number . '.pdf', $sendcloud->createLabelPdf());
                    }
                }

                Order::find($item->id)->markAsShipped();

                return storage_path("app/labels/{$item->order_number}/label-{$item->order_number}.pdf");
            }
        }
    }
}