@@ -29,7 +29,7 @@ function __construct (& $subject, $config) {
29
29
/**
30
30
* Create the table for this plugin if it does not yet exist.
31
31
*
32
- * @author Valérie Isaksen
32
+ * @author Valérie Isaksen
33
33
*/
34
34
public function getVmPluginCreateTableSQL () {
35
35
@@ -67,7 +67,7 @@ function getTableSQLFields () {
67
67
* @param integer $virtuemart_shipmentmethod_id The selected shipment method id
68
68
* @param string $shipment_name Shipment Name
69
69
* @return mixed Null for shipments that aren't active, text (HTML) otherwise
70
- * @author Valérie Isaksen
70
+ * @author Valérie Isaksen
71
71
* @author Max Milbers
72
72
*/
73
73
public function plgVmOnShowOrderFEShipment ($ virtuemart_order_id , $ virtuemart_shipmentmethod_id , &$ shipment_name ) {
@@ -145,28 +145,28 @@ function plgVmConfirmedOrder (VirtueMartCart $cart, $order) {
145
145
'AccountNumber ' => $ method ->account_number ,
146
146
147
147
'PartyAddress ' => array (
148
- 'Line1 ' => $ method ->account_address ,
149
- 'City ' => $ method ->account_city ,
150
- //'StateOrProvinceCode' => $method->addcount_state,
151
- 'PostCode ' => $ method ->account_zipcode ,
148
+ 'Line1 ' => $ method ->account_address ,
149
+ 'City ' => $ method ->account_city ,
150
+ //'StateOrProvinceCode' => $method->addcount_state,
151
+ 'PostCode ' => $ method ->account_zipcode ,
152
152
'CountryCode ' => $ method ->account_country_code
153
153
),
154
154
155
- 'Contact ' => array (
156
- 'Department ' => $ method ->shipper_department ,
157
- 'PersonName ' => $ method ->shipper_personname ,
158
- 'Title ' => $ method ->shipper_title ,
159
- 'CompanyName ' => $ method ->shipper_companyname ,
160
- 'PhoneNumber1 ' => $ method ->shipper_phonenumber1 ,
161
- 'PhoneNumber1Ext ' => $ method ->shipper_phonenumber1ext ,
162
- 'PhoneNumber2 ' => $ method ->shipper_phonenumber2 ,
163
- 'PhoneNumber2Ext ' => $ method ->shipper_phonenumber2ext ,
164
- 'FaxNumber ' => $ method ->shipper_faxnumber ,
165
- 'CellPhone ' => $ method ->shipper_cellphone ,
166
- 'EmailAddress ' => $ method ->shipper_emailaddress ,
167
- 'Type ' => ''
168
- )
169
- );
155
+ 'Contact ' => array (
156
+ 'Department ' => $ method ->shipper_department ,
157
+ 'PersonName ' => $ method ->shipper_personname ,
158
+ 'Title ' => $ method ->shipper_title ,
159
+ 'CompanyName ' => $ method ->shipper_companyname ,
160
+ 'PhoneNumber1 ' => $ method ->shipper_phonenumber1 ,
161
+ 'PhoneNumber1Ext ' => $ method ->shipper_phonenumber1ext ,
162
+ 'PhoneNumber2 ' => $ method ->shipper_phonenumber2 ,
163
+ 'PhoneNumber2Ext ' => $ method ->shipper_phonenumber2ext ,
164
+ 'FaxNumber ' => $ method ->shipper_faxnumber ,
165
+ 'CellPhone ' => $ method ->shipper_cellphone ,
166
+ 'EmailAddress ' => $ method ->shipper_emailaddress ,
167
+ 'Type ' => ''
168
+ )
169
+ );
170
170
171
171
$ params ['Consignee ' ] = array (
172
172
'Reference1 ' => $ cart ->order_number ,
@@ -214,39 +214,41 @@ function plgVmConfirmedOrder (VirtueMartCart $cart, $order) {
214
214
215
215
$ params ['Details ' ]= array (
216
216
'Dimensions ' => array (
217
- 'Length ' => 10 ,
218
- 'Width ' => 10 ,
219
- 'Height ' => 10 ,
220
- 'Unit ' => 'CM ' ,
217
+ 'Length ' => 10 ,
218
+ 'Width ' => 10 ,
219
+ 'Height ' => 10 ,
220
+ 'Unit ' => 'CM ' ,
221
221
222
222
),
223
223
224
224
225
225
'ActualWeight ' => array (
226
- 'Value ' => number_format ($ this ->getOrderWeight ($ cart ,'KG ' ),3 ),
227
- 'Unit ' => 'KG '
226
+ 'Value ' => number_format ($ this ->getOrderWeight ($ cart ,'KG ' ),3 ),
227
+ 'Unit ' => 'KG '
228
228
),
229
229
230
230
'ProductGroup ' => $ method ->product_group ,
231
231
'ProductType ' => $ method ->product_type ,
232
232
'PaymentType ' => $ method ->payment_type ,
233
233
'PaymentOptions ' => $ method ->payment_options ,
234
- 'Services ' => $ method ->services ,
234
+ 'Services ' => $ method ->services ,
235
235
'NumberOfPieces ' => 1 ,
236
- 'DescriptionOfGoods ' => $ method ->description_of_goods ,
237
- 'GoodsOriginCountry ' => $ method ->goods_country ,
238
- 'CurrencyCode ' => $ currency ->_vendorCurrency_code_3 ,
239
- 'Items ' => $ aramex_items
236
+ 'DescriptionOfGoods ' => $ method ->description_of_goods ,
237
+ 'GoodsOriginCountry ' => $ method ->goods_country ,
238
+ 'CurrencyCode ' => $ currency ->_vendorCurrency_code_3 ,
239
+ 'Items ' => $ aramex_items
240
240
);
241
241
242
-
243
- $ params ['Details ' ]['CashOnDeliveryAmount ' ] = array (
244
- 'Value ' => $ cart ->pricesUnformatted ['billTotal ' ],
245
- 'CurrencyCode ' => $ currency ->_vendorCurrency_code_3
246
- );
242
+ if ($ method ->services == 'COD ' )
243
+ {
244
+ $ params ['Details ' ]['CashOnDeliveryAmount ' ] = array (
245
+ 'Value ' => $ cart ->pricesUnformatted ['billTotal ' ],
246
+ 'CurrencyCode ' => $ currency ->_vendorCurrency_code_3
247
+ );
248
+ }
247
249
248
250
$ params ['Details ' ]['CustomsValueAmount ' ] = array (
249
- 'Value ' => $ cart ->pricesUnformatted ['billTotal ' ],
251
+ 'Value ' => $ cart ->pricesUnformatted ['billTotal ' ],
250
252
'CurrencyCode ' => $ currency ->_vendorCurrency_code_3
251
253
);
252
254
@@ -283,53 +285,58 @@ function plgVmConfirmedOrder (VirtueMartCart $cart, $order) {
283
285
284
286
$ major_par ['ClientInfo ' ] = array (
285
287
'AccountCountryCode ' => $ method ->account_country_code ,
286
- 'AccountEntity ' => $ method ->account_entity ,
287
- 'AccountNumber ' => $ method ->account_number ,
288
- 'AccountPin ' => $ method ->account_pin ,
289
- 'UserName ' => $ method ->username ,
290
- 'Password ' => $ method ->password ,
291
- 'Version ' => $ method ->version
288
+ 'AccountEntity ' => $ method ->account_entity ,
289
+ 'AccountNumber ' => $ method ->account_number ,
290
+ 'AccountPin ' => $ method ->account_pin ,
291
+ 'UserName ' => $ method ->username ,
292
+ 'Password ' => $ method ->password ,
293
+ 'Version ' => $ method ->version
292
294
);
293
295
294
296
$ major_par ['LabelInfo ' ] = array (
295
- 'ReportID ' => 9201 ,
296
- 'ReportType ' => 'URL ' ,
297
+ 'ReportID ' => 9201 ,
298
+ 'ReportType ' => 'URL ' ,
297
299
);
298
300
301
+ vmdebug ('Shippment params ' , $ major_par );
302
+
299
303
if ($ method ->ship_mode ) //live mode
300
304
$ soapClient = new SoapClient (WSDL_PATH .'shipping-services-api.wsdl ' );
301
- else //test mode
305
+ else //test mode
302
306
$ soapClient = new SoapClient (WSDL_PATH .'shipping-services-api-test.wsdl ' );
303
-
304
- $ auth_call = $ soapClient ->CreateShipments ($ major_par );
305
307
306
308
try
307
309
{
308
310
$ auth_call = $ soapClient ->CreateShipments ($ major_par );
311
+ vmdebug ('Shipment response ' , $ auth_call );
312
+
309
313
if ($ auth_call ->HasErrors ) //error
310
314
{
311
315
if (count ($ auth_call ->Notifications ->Notification ) > 1 )
312
316
{
313
317
foreach ($ auth_call ->Notifications ->Notification as $ notify_error )
314
318
{
315
- JError::raiseWarning (500 ,'Aramex: ' . $ notify_error ->Code .' - ' . $ notify_error ->Message );
319
+ JError::raiseWarning (500 , 'Aramex: ' . $ notify_error ->Code .' - ' . $ notify_error ->Message );
316
320
}
317
- }
318
- else
321
+ }
322
+ else
319
323
{
320
- JError::raiseWarning (500 ,'Aramex: ' . $ auth_call ->Shipments ->ProcessedShipment ->Notifications ->Notification ->Code . ' - ' . $ auth_call ->Shipments ->ProcessedShipment ->Notifications ->Notification ->Message );
324
+ foreach ($ auth_call ->Shipments ->ProcessedShipment ->Notifications ->Notification as $ notify_error )
325
+ {
326
+ JError::raiseWarning (500 , 'Aramex: ' . $ notify_error ->Code . ' - ' . $ notify_error ->Message );
327
+ }
321
328
}
322
329
323
-
324
- $ app -> redirect (JRoute:: _ ( ' index.php?option=com_virtuemart&view=cart ' )); exit ;
330
+ $ app -> redirect (JRoute:: _ ( ' index.php?option=com_virtuemart&view=cart ' ));
331
+ return FALSE ;
325
332
}
326
-
327
333
else
328
334
{
329
-
330
335
//save file
336
+ $ filepath = JPATH_ROOT .DS .'media ' .DS .'com_virtuemart ' .DS .'labels ' .DS ;
337
+ mkdir ($ filepath , 0755 , true );
331
338
$ filename = basename ($ auth_call ->Shipments ->ProcessedShipment ->ShipmentLabel ->LabelURL );
332
- file_put_contents (JPATH_ROOT . DS . ' media ' . DS .$ filename , file_get_contents ($ auth_call ->Shipments ->ProcessedShipment ->ShipmentLabel ->LabelURL ));
339
+ file_put_contents ($ filepath .$ filename , file_get_contents ($ auth_call ->Shipments ->ProcessedShipment ->ShipmentLabel ->LabelURL ));
333
340
334
341
$ values ['virtuemart_order_id ' ] = $ order ['details ' ]['BT ' ]->virtuemart_order_id ;
335
342
$ values ['order_number ' ] = $ order ['details ' ]['BT ' ]->order_number ;
@@ -349,36 +356,38 @@ function plgVmConfirmedOrder (VirtueMartCart $cart, $order) {
349
356
$ fromname = $ app ->getCfg ('fromname ' );
350
357
$ sitename = $ app ->getCfg ('sitename ' );
351
358
352
- $ admin_body = $ method ->admin_body ;
353
- $ admin_body = str_replace ("{shopper_name} " ,$ shipto ['first_name ' ]. ' ' . $ shipto ['last_name ' ],$ admin_body );
354
- $ admin_body = str_replace ("{order_number} " ,$ order ['details ' ]['BT ' ]->order_number ,$ admin_body );
355
- $ admin_body = str_replace ("{reference_id} " ,$ auth_call ->Shipments ->ProcessedShipment ->ID ,$ admin_body );
356
-
357
- $ mail = JFactory::getMailer ();
358
- $ mail ->addRecipient ($ method ->admin_email );
359
- $ mail ->setSender (array ($ mailfrom , $ fromname ));
360
- $ mail ->setSubject ($ method ->admin_subject );
361
- $ mail ->setBody ($ admin_body );
362
- $ mail ->addAttachment (JPATH_ROOT .DS .'media ' .DS .$ filename );
363
- $ sent = $ mail ->Send ();
359
+ if ($ method ->admin_email )
360
+ {
361
+ $ admin_body = $ method ->admin_body ;
362
+ $ admin_body = str_replace ("{shopper_name} " ,$ shipto ['first_name ' ]. ' ' . $ shipto ['last_name ' ],$ admin_body );
363
+ $ admin_body = str_replace ("{order_number} " ,$ order ['details ' ]['BT ' ]->order_number ,$ admin_body );
364
+ $ admin_body = str_replace ("{reference_id} " ,$ auth_call ->Shipments ->ProcessedShipment ->ID ,$ admin_body );
365
+
366
+ $ mail = JFactory::getMailer ();
367
+ $ mail ->addRecipient ($ method ->admin_email );
368
+ $ mail ->setSender (array ($ mailfrom , $ fromname ));
369
+ $ mail ->setSubject ($ method ->admin_subject );
370
+ $ mail ->setBody ($ admin_body );
371
+ $ mail ->addAttachment ($ filepath .$ filename );
372
+ $ sent = $ mail ->Send ();
373
+ }
364
374
//shopper
365
- $ shopper_body = $ method ->shopper_body ;
366
- $ shopper_body = str_replace ("{shopper_name} " ,$ shipto ['first_name ' ]. ' ' . $ shipto ['last_name ' ],$ shopper_body );
367
- $ shopper_body = str_replace ("{order_number} " ,$ order ['details ' ]['BT ' ]->order_number ,$ shopper_body );
368
- $ shopper_body = str_replace ("{reference_id} " ,$ auth_call ->Shipments ->ProcessedShipment ->ID ,$ shopper_body );
369
-
370
- $ mail = JFactory::getMailer ();
371
- $ mail ->addRecipient ($ shipto ['email ' ]);
372
- $ mail ->setSender (array ($ mailfrom , $ fromname ));
373
- $ mail ->setSubject ($ method ->shopper_subject );
374
- $ mail ->setBody ($ shopper_body );
375
- $ mail ->addAttachment (JPATH_ROOT .DS .'media ' .DS .$ filename );
376
- $ sent = $ mail ->Send ();
377
-
378
-
375
+ if ($ shipto ['email ' ])
376
+ {
377
+ $ shopper_body = $ method ->shopper_body ;
378
+ $ shopper_body = str_replace ("{shopper_name} " ,$ shipto ['first_name ' ]. ' ' . $ shipto ['last_name ' ],$ shopper_body );
379
+ $ shopper_body = str_replace ("{order_number} " ,$ order ['details ' ]['BT ' ]->order_number ,$ shopper_body );
380
+ $ shopper_body = str_replace ("{reference_id} " ,$ auth_call ->Shipments ->ProcessedShipment ->ID ,$ shopper_body );
381
+
382
+ $ mail = JFactory::getMailer ();
383
+ $ mail ->addRecipient ($ shipto ['email ' ]);
384
+ $ mail ->setSender (array ($ mailfrom , $ fromname ));
385
+ $ mail ->setSubject ($ method ->shopper_subject );
386
+ $ mail ->setBody ($ shopper_body );
387
+ $ mail ->addAttachment ($ filepath .$ filename );
388
+ $ sent = $ mail ->Send ();
389
+ }
379
390
}
380
-
381
-
382
391
}
383
392
catch (SoapFault $ fault )
384
393
{
@@ -541,6 +550,7 @@ function getCosts (VirtueMartCart $cart, $method, $cart_prices)
541
550
),
542
551
);
543
552
553
+ vmdebug ('Rates params ' , $ params );
544
554
545
555
if ($ method ->ship_mode ) //live mode
546
556
{
@@ -552,6 +562,7 @@ function getCosts (VirtueMartCart $cart, $method, $cart_prices)
552
562
}
553
563
554
564
$ results = $ soapClient ->CalculateRate ($ params );
565
+ vmdebug ('Rates response ' , $ results );
555
566
556
567
if ($ results ->HasErrors )
557
568
{
@@ -579,15 +590,40 @@ function getCosts (VirtueMartCart $cart, $method, $cart_prices)
579
590
//return 100;
580
591
}
581
592
582
- /**
583
- * @param \VirtueMartCart $cart
584
- * @param int $method
585
- * @param array $cart_prices
586
- * @return bool
593
+ /**
594
+ * Check if the shipping conditions are fulfilled for this shipment method.
595
+ *
596
+ * @author Valerie Isaksen
597
+ * @author Max Milbers
598
+ * @param VirtueMartCart $cart
599
+ * @param int $method
600
+ * @param array $cart_prices
587
601
*/
588
602
protected function checkConditions ($ cart , $ method , $ cart_prices ) {
603
+ $ countries = array ();
604
+ if (!empty ($ method ->countries )) {
605
+ if (!is_array ($ method ->countries )) {
606
+ $ countries [0 ] = $ method ->countries ;
607
+ } else {
608
+ $ countries = $ method ->countries ;
609
+ }
610
+ }
611
+
612
+ $ address = (($ cart ->ST == 0 ) ? $ cart ->BT : $ cart ->ST );
613
+ // probably did not gave his BT:ST address
614
+ if (!is_array ($ address )) {
615
+ $ address = array ();
616
+ $ address ['virtuemart_country_id ' ] = 0 ;
617
+ }
618
+ if (!isset ($ address ['virtuemart_country_id ' ])) {
619
+ $ address ['virtuemart_country_id ' ] = 0 ;
620
+ }
621
+
622
+ if (in_array ($ address ['virtuemart_country_id ' ], $ countries ) || count ($ countries ) == 0 ) {
623
+ return TRUE ;
624
+ }
589
625
590
- return true ;
626
+ return FALSE ;
591
627
}
592
628
593
629
/**
@@ -613,7 +649,7 @@ function convert (&$method) {
613
649
* This functions checks if the called plugin is active one.
614
650
* When yes it is calling the standard method to create the tables
615
651
*
616
- * @author Valérie Isaksen
652
+ * @author Valérie Isaksen
617
653
*
618
654
*/
619
655
function plgVmOnStoreInstallShipmentPluginTable ($ jplugin_id ) {
0 commit comments