| 1 |
<?php |
| 2 |
|
| 3 |
namespace MakeCommerce\Shipping\Method\ParcelMachine; |
| 4 |
|
| 5 |
/** |
| 6 |
* LP Express parcelmachine shipping method. |
| 7 |
* Defines all LP Express specific options. |
| 8 |
* |
| 9 |
* @since 3.2.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
class LPExpress extends \MakeCommerce\Shipping\Method\ParcelMachine { |
| 13 |
|
| 14 |
use \MakeCommerce\Shipping\Method\Common\LPExpress; |
| 15 |
|
| 16 |
public $default_price = "5.00"; |
| 17 |
public $default_max_weight = "30"; |
| 18 |
|
| 19 |
/** |
| 20 |
* Loads all form fields specific to this shipping method |
| 21 |
* |
| 22 |
* @since 3.2.0 |
| 23 |
*/ |
| 24 |
public function initialize_method_form_fields() { |
| 25 |
|
| 26 |
//This is needed for our API. It changes behaviour depending on the country your contract has been signed in |
| 27 |
$this->form_fields['service_carrier'] = array( |
| 28 |
'type' => 'select', |
| 29 |
'title' => __( 'Integration country', 'wc_makecommerce_domain' ), |
| 30 |
'options' => array( |
| 31 |
"LP_EXPRESS_LT" => __( 'Lithuania', 'wc_makecommerce_domain' ), |
| 32 |
), |
| 33 |
'default' => "lt", |
| 34 |
'description' => __( "Which country's carrier gave you the credentials", 'wc_makecommerce_domain' ), |
| 35 |
); |
| 36 |
|
| 37 |
$presetsArray = $this->get_lp_express_presets(); |
| 38 |
|
| 39 |
$this->form_fields['mk_lpexpress_template'] = array( |
| 40 |
'type' => 'select', |
| 41 |
'title' => __( 'Default LP Express template', 'wc_makecommerce_domain' ), |
| 42 |
'options' => $presetsArray, |
| 43 |
'default' => 63, |
| 44 |
'description' => __( |
| 45 |
"All new orders will have this template as a default but can be individually changed in the order view. <br>" . |
| 46 |
"When changing the template size in the order view, the packing slip will also change.", |
| 47 |
'wc_makecommerce_domain' |
| 48 |
), |
| 49 |
); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Adds more address fields to LP Express |
| 54 |
* |
| 55 |
* @since 3.2.0 |
| 56 |
*/ |
| 57 |
public function initialize_return_address_form_fields() { |
| 58 |
|
| 59 |
parent::initialize_return_address_form_fields(); |
| 60 |
|
| 61 |
// Override shop_address_country to only contain LT |
| 62 |
$this->form_fields['shop_address_country'] = array( |
| 63 |
'type' => 'select', |
| 64 |
'title' => __( 'Shop address country', 'wc_makecommerce_domain' ), |
| 65 |
'options' => array( |
| 66 |
'LT' => 'LT', |
| 67 |
), |
| 68 |
'default' => 'LT', |
| 69 |
); |
| 70 |
|
| 71 |
$this->form_fields['shop_building'] = array( |
| 72 |
'type' => 'text', |
| 73 |
'title' => __( 'Shop building', 'wc_makecommerce_domain' ), |
| 74 |
'class' => 'input-text regular-input', |
| 75 |
); |
| 76 |
|
| 77 |
$this->form_fields['shop_apartment'] = array( |
| 78 |
'type' => 'text', |
| 79 |
'title' => __( 'Shop apartment', 'wc_makecommerce_domain' ), |
| 80 |
'class' => 'input-text regular-input', |
| 81 |
); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Gets template presets from API for LP Express |
| 86 |
* |
| 87 |
* @since 3.2.0 |
| 88 |
*/ |
| 89 |
public static function get_lp_express_presets() { |
| 90 |
|
| 91 |
$MK = \MakeCommerce::get_api(); |
| 92 |
|
| 93 |
if ( !$MK ) { |
| 94 |
// Fallback for default |
| 95 |
return array( "63" => __( 'Parcel to Parcel size XL', 'wc_makecommerce_domain' ) ); |
| 96 |
} |
| 97 |
|
| 98 |
$presetsArray = array(); |
| 99 |
|
| 100 |
try { |
| 101 |
|
| 102 |
$presets = $MK->getLPExpressPresets(); |
| 103 |
|
| 104 |
foreach ( $presets as $preset ) { |
| 105 |
$presetsArray[$preset->value] = $preset->label; |
| 106 |
} |
| 107 |
} catch ( \Exception $e ) { |
| 108 |
//do nothing, something is wrong with the credentials or the shop is disabled |
| 109 |
} |
| 110 |
return $presetsArray; |
| 111 |
} |
| 112 |
} |