コード例 #1
0
ファイル: ConfigTest.php プロジェクト: Atlis/docker-magento2
 public function testLoadString()
 {
     $xml = '<?xml version="1.0"?><config><node>1</node></config>';
     $config = new \Magento\Framework\Simplexml\Config();
     $this->assertFalse($config->loadString(''));
     $this->assertTrue($config->loadString($xml));
     $this->assertXmlStringEqualsXmlString($xml, $config->getXmlString());
 }
コード例 #2
0
ファイル: Carrier.php プロジェクト: pradeep-wagento/magento2
 /**
  * Parse xml tracking response
  *
  * @param string $trackingValue
  * @param string $xmlResponse
  * @return null
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _parseXmlTrackingResponse($trackingValue, $xmlResponse)
 {
     $errorTitle = 'For some reason we can\'t retrieve tracking info right now.';
     $resultArr = [];
     $packageProgress = [];
     if ($xmlResponse) {
         $xml = new \Magento\Framework\Simplexml\Config();
         $xml->loadString($xmlResponse);
         $arr = $xml->getXpath("//TrackResponse/Response/ResponseStatusCode/text()");
         $success = (int) $arr[0][0];
         if ($success === 1) {
             $arr = $xml->getXpath("//TrackResponse/Shipment/Service/Description/text()");
             $resultArr['service'] = (string) $arr[0];
             $arr = $xml->getXpath("//TrackResponse/Shipment/PickupDate/text()");
             $resultArr['shippeddate'] = (string) $arr[0];
             $arr = $xml->getXpath("//TrackResponse/Shipment/Package/PackageWeight/Weight/text()");
             $weight = (string) $arr[0];
             $arr = $xml->getXpath("//TrackResponse/Shipment/Package/PackageWeight/UnitOfMeasurement/Code/text()");
             $unit = (string) $arr[0];
             $resultArr['weight'] = "{$weight} {$unit}";
             $activityTags = $xml->getXpath("//TrackResponse/Shipment/Package/Activity");
             if ($activityTags) {
                 $index = 1;
                 foreach ($activityTags as $activityTag) {
                     $addArr = [];
                     if (isset($activityTag->ActivityLocation->Address->City)) {
                         $addArr[] = (string) $activityTag->ActivityLocation->Address->City;
                     }
                     if (isset($activityTag->ActivityLocation->Address->StateProvinceCode)) {
                         $addArr[] = (string) $activityTag->ActivityLocation->Address->StateProvinceCode;
                     }
                     if (isset($activityTag->ActivityLocation->Address->CountryCode)) {
                         $addArr[] = (string) $activityTag->ActivityLocation->Address->CountryCode;
                     }
                     $dateArr = [];
                     $date = (string) $activityTag->Date;
                     //YYYYMMDD
                     $dateArr[] = substr($date, 0, 4);
                     $dateArr[] = substr($date, 4, 2);
                     $dateArr[] = substr($date, -2, 2);
                     $timeArr = [];
                     $time = (string) $activityTag->Time;
                     //HHMMSS
                     $timeArr[] = substr($time, 0, 2);
                     $timeArr[] = substr($time, 2, 2);
                     $timeArr[] = substr($time, -2, 2);
                     if ($index === 1) {
                         $resultArr['status'] = (string) $activityTag->Status->StatusType->Description;
                         $resultArr['deliverydate'] = implode('-', $dateArr);
                         //YYYY-MM-DD
                         $resultArr['deliverytime'] = implode(':', $timeArr);
                         //HH:MM:SS
                         $resultArr['deliverylocation'] = (string) $activityTag->ActivityLocation->Description;
                         $resultArr['signedby'] = (string) $activityTag->ActivityLocation->SignedForByName;
                         if ($addArr) {
                             $resultArr['deliveryto'] = implode(', ', $addArr);
                         }
                     } else {
                         $tempArr = [];
                         $tempArr['activity'] = (string) $activityTag->Status->StatusType->Description;
                         $tempArr['deliverydate'] = implode('-', $dateArr);
                         //YYYY-MM-DD
                         $tempArr['deliverytime'] = implode(':', $timeArr);
                         //HH:MM:SS
                         if ($addArr) {
                             $tempArr['deliverylocation'] = implode(', ', $addArr);
                         }
                         $packageProgress[] = $tempArr;
                     }
                     $index++;
                 }
                 $resultArr['progressdetail'] = $packageProgress;
             }
         } else {
             $arr = $xml->getXpath("//TrackResponse/Response/Error/ErrorDescription/text()");
             $errorTitle = (string) $arr[0][0];
         }
     }
     if (!$this->_result) {
         $this->_result = $this->_trackFactory->create();
     }
     if ($resultArr) {
         $tracking = $this->_trackStatusFactory->create();
         $tracking->setCarrier('ups');
         $tracking->setCarrierTitle($this->getConfigData('title'));
         $tracking->setTracking($trackingValue);
         $tracking->addData($resultArr);
         $this->_result->append($tracking);
     } else {
         $error = $this->_trackErrorFactory->create();
         $error->setCarrier('ups');
         $error->setCarrierTitle($this->getConfigData('title'));
         $error->setTracking($trackingValue);
         $error->setErrorMessage($errorTitle);
         $this->_result->append($error);
     }
     return $this->_result;
 }
コード例 #3
0
 public function getReleaseVersion($module)
 {
     $modulePath = $this->moduleRegistry->getPath(self::XML_PATH_INSTALLATED_MODULES, $module);
     $filePath = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, "{$modulePath}/etc/module.xml");
     $source = new \Magento\Framework\Simplexml\Config($filePath);
     if ($source->getNode(self::XML_PATH_INSTALLATED_MODULES)->attributes()->release_version) {
         return $source->getNode(self::XML_PATH_INSTALLATED_MODULES)->attributes()->release_version->__toString();
     }
     return false;
 }