issues in Implementing Delivery Provider

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Re: issues in Implementing Delivery Provider

Post by khizar » 08 Apr 2021, 05:04

Hey guys waiting for reply

khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Re: issues in Implementing Delivery Provider

Post by khizar » 08 Apr 2021, 09:17

hey guys please have a look at this problem

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: issues in Implementing Delivery Provider

Post by aimeos » 09 Apr 2021, 07:08

khizar wrote: 07 Apr 2021, 11:39

Code: Select all

        if($t->data[0]->success){
        // here is the code for saving attributes
            $status = \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS;
            $order->setDeliveryStatus( $status );
            // $this->saveOrder( $order );

            $attributes = ['reference_number' => $t->data[0]->reference_number];
            $serviceType = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY;
            $orderServiceItem = $order->getService( $serviceType );
    
            $this->setAttributes( $orderServiceItem, $attributes, 'myprovider' );
            $this->saveOrderBase( $basket );
        }

        return $order;
    }
}
Your code looks correct.
khizar wrote: 07 Apr 2021, 11:39 Now if above code is right can you please tell me how can i access that reference no in orders list

Code: Select all

	<?php foreach( $this->get( 'items', [] ) as $id => $item ) : ?>
	
	<?php endforeach; ?>
please note that the above foreach loop is from the orders list and it contains code but for the sake of simplicity i picked up only start and end of the loop can you please tell me here how can i access that reference number
In the order list view it's more difficult because the order details are not loaded there:
https://github.com/aimeos/ai-client-htm ... d.php#L218

You would have to overwrite that method with your own version in your own extension and use:

Code: Select all

$view->listsOrderItems = $cntl->uses( ['order/base', 'order/base/service'] )->sort( '-order.id' )->search();
Then, you can get the reference in the loop using:

Code: Select all

if( $service = current( $item->getBaseItem()->getService( 'delivery' ) ) ) {
	$ref = $service->getAttribute( 'reference_number', 'myprovider' );
}
https://github.com/aimeos/aimeos-core/b ... e.php#L151

Note: We answer questions in the forum in our spare time.
If you need immediate response, please ask the Aimeos company for paid support:

https://aimeos.com/support
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

khizar
Posts: 99
Joined: 19 Jan 2021, 09:51

Re: issues in Implementing Delivery Provider

Post by khizar » 09 Apr 2021, 07:18

aimeos wrote: 09 Apr 2021, 07:08
khizar wrote: 07 Apr 2021, 11:39

Code: Select all

        if($t->data[0]->success){
        // here is the code for saving attributes
            $status = \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS;
            $order->setDeliveryStatus( $status );
            // $this->saveOrder( $order );

            $attributes = ['reference_number' => $t->data[0]->reference_number];
            $serviceType = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY;
            $orderServiceItem = $order->getService( $serviceType );
    
            $this->setAttributes( $orderServiceItem, $attributes, 'myprovider' );
            $this->saveOrderBase( $basket );
        }

        return $order;
    }
}
Your code looks correct.
khizar wrote: 07 Apr 2021, 11:39 Now if above code is right can you please tell me how can i access that reference no in orders list

Code: Select all

	<?php foreach( $this->get( 'items', [] ) as $id => $item ) : ?>
	
	<?php endforeach; ?>
please note that the above foreach loop is from the orders list and it contains code but for the sake of simplicity i picked up only start and end of the loop can you please tell me here how can i access that reference number
In the order list view it's more difficult because the order details are not loaded there:
https://github.com/aimeos/ai-client-htm ... d.php#L218

You would have to overwrite that method with your own version in your own extension and use:

Code: Select all

$view->listsOrderItems = $cntl->uses( ['order/base', 'order/base/service'] )->sort( '-order.id' )->search();
Then, you can get the reference in the loop using:

Code: Select all

if( $service = current( $item->getBaseItem()->getService( 'delivery' ) ) ) {
	$ref = $service->getAttribute( 'reference_number', 'myprovider' );
}
https://github.com/aimeos/aimeos-core/b ... e.php#L151

Note: We answer questions in the forum in our spare time.
If you need immediate response, please ask the Aimeos company for paid support:

https://aimeos.com/support
I have completed my task .I want to you to have a look at my code and guide me is it correct or not so that i can move on to next task .i am getting my desired result but not sure my approach is right or not so please guide me.i am posting my code below

Code: Select all

<?php

namespace Aimeos\MShop\Service\Provider\Delivery;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

class Myprovider
extends \Aimeos\MShop\Service\Provider\Delivery\Base
implements \Aimeos\MShop\Service\Provider\Delivery\Iface
{
    /**
     * Sends the order details to the ERP system for further processing.
     *
     * @param \Aimeos\MShop\Order\Item\Iface $order Order invoice object to process
     */
    public function process(\Aimeos\MShop\Order\Item\Iface $order): \Aimeos\MShop\Order\Item\Iface
    {
        $parts = \Aimeos\MShop\Order\Item\Base\Base::PARTS_ALL;
        $basket = $this->getOrderBase($order->getBaseId(), $parts);

       

       

	$data = []; // note that it contains data but i have skipped that part
        $apiurl = 'http://demodashboardapi.shipsy.in/api/customer/integration/consignment/softdata';
        $response =  Http::withHeaders([
            "api-key" => "XXXXXXXXXXXXXX",
            "Content-Type" => "application/json"
        ])->post($apiurl,$data);

       
        
        
        
        $t = json_decode($response);

        if($t->data[0]->success){
           
            info('entered into success method');
            $attributes = ['reference_number' => $t->data[0]->reference_number,'message'=>''];
            $serviceType = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY;
            $orderServiceItem = $basket->getService( $serviceType );
            if(($serviceItem = reset($orderServiceItem)) !== false){
                $status = \Aimeos\MShop\Order\Item\Base::STAT_PROGRESS;
                $order->setDeliveryStatus( $status );
                // $this->saveOrder( $order );
                $this->setAttributes( $serviceItem, $attributes, 'myprovider' );
                $this->saveOrderBase( $basket );
            }
            
        }else{
            $attributes = ['reference_number' => '', 'message' => $t->data[0]->message];
            $serviceType = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY;
            $orderServiceItem = $basket->getService( $serviceType );
            if(($serviceItem = reset($orderServiceItem)) !== false){
               
                
                $this->setAttributes( $serviceItem, $attributes, 'myprovider' );
                $this->saveOrderBase( $basket );
            }
        }

        return $order;
    }
}

Now in my list orders i picked up service attribute by using

Code: Select all


<?php 

$baseItems = $this->get( 'baseItems', [] );
foreach( $this->get( 'items', [] ) as $id => $item ) :
                $baseItem = ( isset( $baseItems[$item->getBaseId()] ) ? $baseItems[$item->getBaseId()] : null ); 
			
					$reference_no = '';
					$message  = ''; 
					$serviceType = \Aimeos\MShop\Order\Item\Base\Service\Base::TYPE_DELIVERY;
					$orderServiceItem = $baseItem->getService( $serviceType );
					if(($serviceItem = reset($orderServiceItem)) !== false){
						$reference_no = $serviceItem->getAttribute( 'reference_number', 'myprovider' );
						// $attrItem = $serviceItem->getAttributeItem( 'reference_number', 'myprovider' );
						$message = $serviceItem->getAttribute( 'message', 'myprovider' );
					}
					
					
					
			endforeach:	
?>
	
That code is working perfectly but i want you to have a look if it need any modification .please guide me

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: issues in Implementing Delivery Provider

Post by aimeos » 11 Apr 2021, 12:01

In principle, it should be correct.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply