Example #1
0
 /**
  * Associate a manifest 
  *
  * @param \XLite\Module\XC\CanadaPost\Model\Order\Parcel\Manifest $manifest Manifest object
  *
  * @return void
  */
 public function addManifest(\XLite\Module\XC\CanadaPost\Model\Order\Parcel\Manifest $manifest)
 {
     $manifest->addShipment($this);
     $this->manifests[] = $manifest;
 }
Example #2
0
 /**
  * Call "Get Manifest" request
  *
  * Reason to Call:
  * To retrieve the set of information links for a particular manifest that was previously created as part of Transmit Shipments.
  *
  * More info at:
  * https://www.canadapost.ca/cpo/mc/business/productsservices/developers/services/shippingmanifest/manifest.jsf
  *
  * @param \XLite\Module\XC\CanadaPost\Model\Order\Parcel\Manifest $manifest Manifest object
  *
  * @return \XLite\Core\CommonCell
  */
 public function callGetManifestRequest(\XLite\Module\XC\CanadaPost\Model\Order\Parcel\Manifest $manifest)
 {
     $apiHost = $manifest->getHref();
     $result = new \XLite\Core\CommonCell();
     try {
         $request = new \XLite\Core\HTTP\Request($apiHost);
         $request->requestTimeout = $this->requestTimeout;
         $request->verb = 'GET';
         $request->setHeader('Authorization', 'Basic ' . base64_encode(static::getCanadaPostConfig()->user . ':' . static::getCanadaPostConfig()->password));
         $request->setHeader('Accept', 'application/vnd.cpc.manifest-v5+xml');
         $request->setHeader('Accept-language', static::ACCEPT_LANGUAGE_EN);
         if (static::isOnBehalfOfAMerchant()) {
             $request->setHeader('Platform-id', $this->getPlatformId());
         }
         $response = $request->sendRequest();
         if (isset($response->body) && !empty($response->body)) {
             // Parse response to object
             $result = $this->parseResponse($response->body);
         } else {
             $result->errors = array('INTERNAL' => sprintf('Error while connecting to the Canada Post host (%s) during Get Manifest request', $apiHost));
         }
         if (static::getCanadaPostConfig()->debug_enabled) {
             // Save debug log
             static::logApiCall($apiHost, 'Get Manifest', '', $response->body);
         }
     } catch (\Exception $e) {
         if (!isset($result->errors)) {
             $result->errors = array();
         }
         $result->errors += array($e->getCode(), $e->getMessage());
     }
     return $result;
 }
 /**
  * {@inheritDoc}
  */
 public function prepareEntityBeforeCommit($type)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'prepareEntityBeforeCommit', array($type));
     return parent::prepareEntityBeforeCommit($type);
 }