File tree Expand file tree Collapse file tree 5 files changed +57
-8
lines changed Expand file tree Collapse file tree 5 files changed +57
-8
lines changed Original file line number Diff line number Diff line change @@ -269,15 +269,24 @@ public function createConcepts(): self
269
269
$ newConsignments = $ this ->where ('consignment_id ' , '!= ' , null )->toArray ();
270
270
$ this ->addMissingReferenceId ();
271
271
272
+ $ grouped = $ this ->where ('consignment_id ' , null )->groupBy (function (AbstractConsignment $ item ) {
273
+ return $ item ->getApiKey () . ($ item ->hasSender () ? '-sender ' : '' );
274
+ });
275
+
272
276
/* @var MyParcelCollection $consignments */
273
- foreach ($ this ->where ('consignment_id ' , null )->groupBy ('api_key ' ) as $ consignments ) {
277
+ foreach ($ grouped as $ consignments ) {
278
+ $ headers = MyParcelRequest::HEADER_CONTENT_TYPE_SHIPMENT ;
279
+ if ($ consignments ->first ()->hasSender ()) {
280
+ $ headers += MyParcelRequest::HEADER_SET_CUSTOM_SENDER ;
281
+ }
282
+
274
283
$ data = (new CollectionEncode ($ consignments ))->encode ();
275
284
$ request = (new MyParcelRequest ())
276
285
->setUserAgents ($ this ->getUserAgent ())
277
286
->setRequestParameters (
278
287
$ consignments ->first ()->apiKey ,
279
288
$ data ,
280
- MyParcelRequest:: HEADER_CONTENT_TYPE_SHIPMENT
289
+ $ headers
281
290
)
282
291
->sendRequest ();
283
292
Original file line number Diff line number Diff line change 18
18
use MyParcelNL \Sdk \src \Model \Carrier \AbstractCarrier ;
19
19
use MyParcelNL \Sdk \src \Model \Carrier \CarrierFactory ;
20
20
use MyParcelNL \Sdk \src \Model \MyParcelCustomsItem ;
21
+ use MyParcelNL \Sdk \src \Model \Recipient ;
21
22
use MyParcelNL \Sdk \src \Services \CountryCodes ;
22
23
use MyParcelNL \Sdk \src \Services \CountryService ;
23
24
use MyParcelNL \Sdk \src \Support \Str ;
@@ -522,6 +523,11 @@ abstract class AbstractConsignment
522
523
*/
523
524
private $ state ;
524
525
526
+ /**
527
+ * @var null|\MyParcelNL\Sdk\src\Model\Recipient
528
+ */
529
+ private $ sender ;
530
+
525
531
/**
526
532
* @throws \Exception
527
533
*/
@@ -532,6 +538,34 @@ public function __construct()
532
538
: null ;
533
539
}
534
540
541
+ /**
542
+ * If you set a sender, a feature header will be added to the request.
543
+ * Exporting the consignment to MyParcel will throw an error if your shop (by apikey) does not have this permission.
544
+ *
545
+ * @param Recipient $sender
546
+ * @return $this
547
+ */
548
+ public function setSender (Recipient $ sender ): AbstractConsignment
549
+ {
550
+ $ this ->sender = $ sender ;
551
+
552
+ return $ this ;
553
+ }
554
+
555
+ public function hasSender (): bool
556
+ {
557
+ return isset ($ this ->sender );
558
+ }
559
+
560
+ public function getSender (): ?Recipient
561
+ {
562
+ if (!$ this ->hasSender ()) {
563
+ return null ;
564
+ }
565
+
566
+ return $ this ->sender ;
567
+ }
568
+
535
569
/**
536
570
* @return null|\MyParcelNL\Sdk\src\Model\Carrier\AbstractCarrier
537
571
*/
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ class MyParcelRequest
40
40
];
41
41
public const HEADER_ACCEPT_APPLICATION_PDF = ['Accept ' => 'application/pdf ' ];
42
42
public const HEADER_CONTENT_TYPE_RETURN_SHIPMENT = ['Content-Type ' => 'application/vnd.return_shipment+json; charset=utf-8 ' ];
43
+ public const HEADER_SET_CUSTOM_SENDER = ['x-dmp-set-custom-sender ' => 'true ' ];
43
44
44
45
/* @deprecated use HEADER_CONTENT_TYPE_SHIPMENT, HEADER_ACCEPT_APPLICATION_PDF or HEADER_CONTENT_TYPE_RETURN_SHIPMENT */
45
46
public const REQUEST_HEADER_SHIPMENT = 'Content-Type: application/vnd.shipment+json;charset=utf-8;version=1.1 ' ;
Original file line number Diff line number Diff line change @@ -55,10 +55,10 @@ private function groupMultiColloConsignments()
55
55
{
56
56
return $ this ->consignments ->groupBy (function (AbstractConsignment $ consignment ) {
57
57
if ($ consignment ->isPartOfMultiCollo ()) {
58
- return $ consignment ->getReferenceId ();
58
+ return $ consignment ->getReferenceIdentifier ();
59
59
}
60
60
61
- return 'random_to_prevent_multi_collo_ ' . uniqid ();
61
+ return 'random_to_prevent_multi_collo_ ' . uniqid ('' , true );
62
62
})->toArray ();
63
63
}
64
64
}
Original file line number Diff line number Diff line change @@ -205,12 +205,17 @@ private function encodeBase(): self
205
205
'carrier ' => $ consignment ->getCarrierId (),
206
206
];
207
207
208
- if ($ consignment ->getReferenceId ()) {
209
- $ this ->consignmentEncoded ['reference_identifier ' ] = $ consignment ->getReferenceId ();
208
+
209
+ if (($ sender = $ consignment ->getSender ())) {
210
+ $ this ->consignmentEncoded ['sender ' ] = $ sender ->toArrayWithoutNull ();
211
+ }
212
+
213
+ if (($ id = $ consignment ->getReferenceIdentifier ())) {
214
+ $ this ->consignmentEncoded ['reference_identifier ' ] = $ id ;
210
215
}
211
216
212
- if ($ consignment ->getCompany ()) {
213
- $ this ->consignmentEncoded ['recipient ' ]['company ' ] = $ consignment -> getCompany () ;
217
+ if (( $ company = $ consignment ->getCompany () )) {
218
+ $ this ->consignmentEncoded ['recipient ' ]['company ' ] = $ company ;
214
219
}
215
220
216
221
return $ this ;
You can’t perform that action at this time.
0 commit comments