Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
carrier_config.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
11 $upsCarrierConfig = $block->getCarrierConfig();
12 $orShipArr = $upsCarrierConfig->getCode('originShipment');
13 $defShipArr = $upsCarrierConfig->getCode('method');
14 
15 $sectionCode = $block->getRequest()->getParam('section');
16 $websiteCode = $block->getRequest()->getParam('website');
17 $storeCode = $block->getRequest()->getParam('store');
18 
19 if (!$storeCode && $websiteCode) {
21  $web = $block->getWebsiteModel()->load($websiteCode);
22  $storedAllowedMethods = explode(',', $web->getConfig('carriers/ups/allowed_methods'));
23  $storedOriginShipment = $block->escapeHtml($web->getConfig('carriers/ups/origin_shipment'));
24  $storedFreeShipment = $block->escapeHtml($web->getConfig('carriers/ups/free_method'));
25  $storedUpsType = $block->escapeHtml($web->getConfig('carriers/ups/type'));
26 } elseif ($storeCode) {
27  $storedAllowedMethods = explode(',', $block->getConfig('carriers/ups/allowed_methods', $storeCode));
28  $storedOriginShipment = $block->escapeHtml($block->getConfig('carriers/ups/origin_shipment', $storeCode));
29  $storedFreeShipment = $block->escapeHtml($block->getConfig('carriers/ups/free_method', $storeCode));
30  $storedUpsType = $block->escapeHtml($block->getConfig('carriers/ups/type', $storeCode));
31 } else {
32  $storedAllowedMethods = explode(',', $block->getConfig('carriers/ups/allowed_methods'));
33  $storedOriginShipment = $block->escapeHtml($block->getConfig('carriers/ups/origin_shipment'));
34  $storedFreeShipment = $block->escapeHtml($block->getConfig('carriers/ups/free_method'));
35  $storedUpsType = $block->escapeHtml($block->getConfig('carriers/ups/type'));
36 }
37 ?>
38 <script>
39 require(["prototype"], function(){
40 
41 //<![CDATA[
42  function hideRowArrayElements(arr)
43  {
44  for (var a = 0; a < arr.length; a++) {
45  $(arr[a]).up(1).hide();
46  }
47  }
48 
49  function showRowArrayElements(arr)
50  {
51  for (var a = 0; a < arr.length; a++) {
52  $(arr[a]).up(1).show();
53  }
54  }
55 
56  function inArray(arr, value)
57  {
58  for (var i = 0; i < arr.length; i++) {
59  if (arr[i] === value) {
60  return true;
61  }
62  }
63  return false;
64  }
65 
66  var upsXml = Class.create();
67  upsXml.prototype = {
68  initialize: function()
69  {
70  this.carriersUpsTypeId = 'carriers_ups_type';
71  if (!$(this.carriersUpsTypeId)) {
72  return;
73  }
74 
75  this.checkingUpsXmlId = ['carriers_ups_gateway_xml_url','carriers_ups_username',
76  'carriers_ups_password','carriers_ups_access_license_number'];
77  this.checkingUpsId = ['carriers_ups_gateway_url'];
78  this.originShipmentTitle = '';
79  this.allowedMethodsId = 'carriers_ups_allowed_methods';
80  this.freeShipmentId = 'carriers_ups_free_method';
81  this.onlyUpsXmlElements = ['carriers_ups_gateway_xml_url','carriers_ups_tracking_xml_url',
82  'carriers_ups_username','carriers_ups_password','carriers_ups_access_license_number',
83  'carriers_ups_origin_shipment','carriers_ups_negotiated_active','carriers_ups_shipper_number',
84  'carriers_ups_mode_xml','carriers_ups_include_taxes'];
85  this.onlyUpsElements = ['carriers_ups_gateway_url'];
86 
87  this.storedOriginShipment = '<?= /* @noEscape */ $storedOriginShipment ?>';
88  this.storedFreeShipment = '<?= /* @noEscape */ $storedFreeShipment ?>';
89  this.storedUpsType = '<?= /* @noEscape */ $storedUpsType ?>';
90  <?php $jsonHelper = $this->helper('Magento\Framework\Json\Helper\Data'); ?>
91  this.storedAllowedMethods = <?= /* @noEscape */ $jsonHelper->jsonEncode($storedAllowedMethods) ?>;
92  this.originShipmentObj = <?= /* @noEscape */ $jsonHelper->jsonEncode($orShipArr) ?>;
93  this.originShipmentObj['default'] = <?= /* @noEscape */ $jsonHelper->jsonEncode($defShipArr) ?>;
94 
95  this.setFormValues();
96  Event.observe($(this.carriersUpsTypeId), 'change', this.setFormValues.bind(this));
97  },
98  updateAllowedMethods: function(originShipmentTitle)
99  {
100  var allowedMethods = $(this.allowedMethodsId), // multiselect
101  freeMethod = $(this.freeShipmentId), // single-choice select
102  originShipment = this.originShipmentObj[originShipmentTitle];
103 
104  while (allowedMethods.length > 0) {
105  allowedMethods.remove(0);
106  }
107 
108  while (freeMethod.length > 0) {
109  freeMethod.remove(0);
110  }
111  freeMethod.insert(new Element('option', {value:''}).update('<?= $block->escapeHtml(__('None')) ?>'));
112 
113  var code, option;
114  for (code in originShipment) {
115  option = new Element('option', {value:code}).update(originShipment[code]);
116  if ((originShipmentTitle == this.storedOriginShipment || originShipmentTitle == 'default')
117  && this.storedFreeShipment == code
118  ) {
119  option.selected = true;
120  }
121  freeMethod.insert(option);
122 
123  option = new Element('option', {value:code}).update(originShipment[code]);
124  if (this.storedUpsType == 'UPS') {
125  if (originShipmentTitle != 'default' || inArray(this.storedAllowedMethods, code)) {
126  option.selected = true;
127  }
128  } else if (originShipmentTitle != this.storedOriginShipment
129  || inArray(this.storedAllowedMethods, code)
130  ) {
131  option.selected = true;
132  }
133 
134  if ((originShipmentTitle == 'default' || originShipmentTitle == this.storedOriginShipment)
135  && inArray(this.storedAllowedMethods, code)
136  ) {
137  option.selected = true;
138  }
139 
140  allowedMethods.insert(option);
141  }
142  },
143  setFormValues: function()
144  {
145  var a;
146  if ($F(this.carriersUpsTypeId) == 'UPS') {
147  for (a = 0; a < this.checkingUpsXmlId.length; a++) {
148  $(this.checkingUpsXmlId[a]).removeClassName('required-entry');
149  }
150  for (a = 0; a < this.checkingUpsId.length; a++) {
151  $(this.checkingUpsXmlId[a]).addClassName('required-entry');
152  }
153  Event.stopObserving($('carriers_ups_origin_shipment'), 'change', this.changeOriginShipment.bind(this));
154  showRowArrayElements(this.onlyUpsElements);
155  hideRowArrayElements(this.onlyUpsXmlElements);
156  this.changeOriginShipment(null, 'default');
157  } else {
158  for (a = 0; a < this.checkingUpsXmlId.length; a++) {
159  $(this.checkingUpsXmlId[a]).addClassName('required-entry');
160  }
161  for (a = 0; a < this.checkingUpsId.length; a++) {
162  $(this.checkingUpsXmlId[a]).removeClassName('required-entry');
163  }
164  Event.observe($('carriers_ups_origin_shipment'), 'change', this.changeOriginShipment.bind(this));
165  showRowArrayElements(this.onlyUpsXmlElements);
166  hideRowArrayElements(this.onlyUpsElements);
167  this.changeOriginShipment(null, null);
168  }
169  },
170  changeOriginShipment: function(Event, key)
171  {
172  this.originShipmentTitle = key ? key : $F('carriers_ups_origin_shipment');
173  this.updateAllowedMethods(this.originShipmentTitle);
174  }
175  };
176  xml = new upsXml();
177  //]]>
178 
179 });
180 </script>
$storedFreeShipment
$upsCarrierConfig
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$websiteCode
$block
Definition: block.php:8
$defShipArr
$orShipArr
$storedOriginShipment
$storedUpsType
$jsonHelper
$sectionCode
$storeCode