コード例 #1
0
 public function process(array $data)
 {
     //todo log the data to get the order increment id
     $shipment = Mage::getModel('sales/order_shipment')->load($data['order_id'], 'order_id');
     $customerId = null;
     $customer = Mage::getModel('customer/customer')->setWebsiteId(Mage::app()->getStore($data['store_id'])->getWebsiteId())->loadByEmail($data['partner_email']);
     if ($customer->getId()) {
         $customerId = ' (' . $customer->getId() . ')';
     }
     $helperTools = Mage::helper('swisspost_yellowcube/tools');
     $partner = new Partner();
     $partner->setPartnerType($data['partner_type'])->setPartnerNo($this->cutString($data['partner_number']), 10)->setPartnerReference($this->cutString($this->getHelper()->getPartnerReference($data['partner_name'], $data['partner_zip_code'])), 50)->setName1($this->cutString($data['partner_name']))->setName2($this->cutString($data['partner_name2']))->setStreet($this->cutString($data['partner_street']))->setName3($this->cutString($data['partner_name3']))->setCountryCode($data['partner_country_code'])->setZIPCode($this->cutString($data['partner_zip_code']), 10)->setCity($this->cutString($data['partner_city']))->setEmail($this->cutString($data['partner_email']), 241)->setPhoneNo($this->cutString($data['partner_phone']), 16)->setLanguageCode($this->cutString($data['partner_language']), 2);
     $ycOrder = new Order();
     $ycOrder->setOrderHeader(new OrderHeader($this->cutString($data['deposit_number'], 10), $this->cutString($shipment->getIncrementId()), $data['order_date']))->setPartnerAddress($partner)->addValueAddedService(new BasicShippingServices($this->cutString($data['service_basic_shipping']), 40))->addValueAddedService(new AdditionalShippingServices($this->cutString($data['service_additional_shipping']), 40))->setOrderDocumentsFlag(false);
     // Mime-Type: X(3) pdf oder pcl (kleine Buchstaben)
     // DocTyp: X(2) IV=Invoice/Rechnung, LS=Lieferschein, ZS=ZahlSchein
     $doc = null;
     $pdfa = $this->getPdfA($shipment);
     if ($pdfa) {
         $doc = Doc::fromFile(Doc::DOC_TYPE_LS, Doc::MIME_TYPE_PDF, $pdfa);
         $ycOrder->addOrderDocument($doc)->setOrderDocumentsFlag(true);
     }
     foreach ($data['items'] as $key => $item) {
         $position = new Position();
         $position->setPosNo($key + 1)->setArticleNo($this->cutString($item['article_number']))->setEAN($this->cutString($item['article_ean']))->setPlant($this->cutString($data['plant_id']), 4)->setQuantity($item['article_qty'])->setQuantityISO(\YellowCube\ART\UnitsOfMeasure\ISO::PCE)->setShortDescription($this->cutString($item['article_title']), 40);
         $ycOrder->addOrderPosition($position);
     }
     $response = $this->getYellowCubeService()->createYCCustomerOrder($ycOrder);
     try {
         if (!is_object($response) || !$response->isSuccess()) {
             $message = $this->getHelper()->__('Shipment #%s for Order #%s could not be transmitted to YellowCube: "%s".', $shipment->getIncrementId(), $data['order_increment_id'], $response->getStatusText());
             $shipment->addComment($message, false, false)->save();
             Mage::log($message . "\n" . print_r($response, true), Zend_Log::ERR, Swisspost_YellowCube_Helper_Data::YC_LOG_FILE, true);
             $helperTools->sendAdminNotification($message);
             // @todo allow the user to send again to yellow cube the request from backend
         } else {
             if ($this->getHelper()->getDebug()) {
                 Mage::log(print_r($ycOrder, true), Zend_Log::DEBUG, Swisspost_YellowCube_Helper_Data::YC_LOG_FILE);
                 Mage::log(print_r($response, true), Zend_Log::DEBUG, Swisspost_YellowCube_Helper_Data::YC_LOG_FILE);
             }
             /**
              * Define yc_shipped to 0 to be used later in BAR process that the shipping has not been done
              */
             reset($data['items']);
             foreach ($shipment->getItemsCollection() as $item) {
                 /* @var $item Mage_Sales_Model_Order_Shipment_Item */
                 $item->setAdditionalData(Zend_Json::encode(array('yc_shipped' => 0)))->save();
             }
             $shipment->addComment($this->getHelper()->__('Shipment #%s for Order #%s was successfully transmitted to YellowCube. Received reference number %s and status message "%s".', $shipment->getIncrementId(), $data['order_increment_id'], $response->getReference(), $response->getStatusText()), false, false)->save();
             // WAR Message
             $this->getQueue()->send(Zend_Json::encode(array('action' => Swisspost_YellowCube_Model_Synchronizer::SYNC_ORDER_UPDATE, 'order_id' => $data['order_id'], 'shipment_increment_id' => $shipment->getIncrementId(), 'yc_reference' => $response->getReference())));
         }
     } catch (Exception $e) {
         // Let's keep going further processes
         Mage::logException($e);
     }
     return $this;
 }
コード例 #2
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use YellowCube\WAB\AdditionalService\AdditionalShippingServices;
use YellowCube\WAB\AdditionalService\BasicShippingServices;
use YellowCube\WAB\AdditionalService\DeliveryInstructions;
use YellowCube\WAB\Doc;
use YellowCube\WAB\Order;
use YellowCube\WAB\OrderHeader;
use YellowCube\WAB\Partner;
use YellowCube\Config;
use YellowCube\WAB\Position;
$service = new YellowCube\Service(Config::testConfig());
$partner = new Partner();
$partner->setPartnerType('WE')->setPartnerNo('0000300020')->setPartnerReference('LiiP AG')->setTitle('Madame')->setName1('We Name')->setName2('c/o Cailler')->setStreet('Strasse')->setCountryCode('CH')->setZIPCode('8057')->setCity('Zurich')->setPOBox('po box')->setPhoneNo('0041793020467')->setSMSAvisMobNo('0041793020467')->setFaxNo('0041793020467')->setEmail('*****@*****.**')->setLanguageCode('en');
$position = new Position();
$position->setPosNo(10)->setArticleNo('200522004')->setEAN('714718003580')->setPlant('Y010')->setQuantity(1.0)->setQuantityISO('PCE')->setShortDescription('loral Pasty Daisie');
$order = new Order();
$order->setOrderHeader(new OrderHeader('0000040730', \uniqid('yc'), date('Ymd')))->setPartnerAddress($partner)->addValueAddedService(new AdditionalShippingServices())->addValueAddedService(new BasicShippingServices(BasicShippingServices::PRI))->addValueAddedService(new DeliveryInstructions(''))->addOrderPosition($position)->addOrderDocument(Doc::fromFile('LS', 'pdf', 'docs/order/example-file.pdf'));
$response = $service->createYCCustomerOrder($order);
assert($response->isSuccess(), 'Getting status for order failed.');
var_dump($response);
echo "Successfully added order with reference " . $response->getReference();