コード例 #1
0
 public function testCreate()
 {
     $rate = $this->dummyData->getMoney(907);
     $deliveryDate = new DateTime();
     $shipmentRate = new ShipmentRate($rate);
     $shipmentRate->setExternalId('rate_xxxxxx');
     $shipmentRate->setShipmentExternalId('shp_xxxxxx');
     $shipmentRate->setCarrier('UPS');
     $shipmentRate->setService('Ground');
     $shipmentRate->setListRate($this->dummyData->getMoney(986));
     $shipmentRate->setRetailRate($this->dummyData->getMoney(1196));
     $shipmentRate->setDeliveryDate($deliveryDate);
     $shipmentRate->setIsDeliveryDateGuaranteed(true);
     $shipmentRate->setDeliveryDays(5);
     $shipmentRate->setEstDeliveryDays(5);
     $this->assertEntityValid($shipmentRate);
     $this->assertSame('rate_xxxxxx', $shipmentRate->getExternalId());
     $this->assertSame('shp_xxxxxx', $shipmentRate->getShipmentExternalId());
     $this->assertSame('UPS', $shipmentRate->getCarrier());
     $this->assertSame('Ground', $shipmentRate->getService());
     $this->assertSame($rate, $shipmentRate->getRate());
     $this->assertSame(907, $shipmentRate->getRate()->getAmount());
     $this->assertSame(986, $shipmentRate->getListRate()->getAmount());
     $this->assertSame(1196, $shipmentRate->getRetailRate()->getAmount());
     $this->assertEquals($deliveryDate, $shipmentRate->getDeliveryDate());
     $this->assertSame(5, $shipmentRate->getDeliveryDays());
     $this->assertSame(true, $shipmentRate->isDeliveryDateGuaranteed());
     $this->assertSame(5, $shipmentRate->getEstDeliveryDays());
     $this->assertTrue($shipmentRate->getDeliveryMethod()->isStandard());
 }
コード例 #2
0
ファイル: DummyData.php プロジェクト: inklabs/kommerce-core
 /**
  * @param int $amount
  * @param string $currency
  * @return ShipmentRate
  */
 public function getShipmentRate($amount = 500, $currency = 'USD')
 {
     $shipmentRate = new ShipmentRate(new Money($amount, $currency));
     $shipmentRate->setExternalId('rate_' . $this->getRandomToken());
     $shipmentRate->setCarrier('UPS');
     $shipmentRate->setService('Ground');
     $shipmentRate->setListRate(new Money($amount * 1.05, $currency));
     $shipmentRate->setRetailRate(new Money($amount * 1.15, $currency));
     $shipmentRate->setDeliveryDate(new DateTime());
     return $shipmentRate;
 }
コード例 #3
0
 private function getShipmentRateFromEasyPostRate($rate)
 {
     $shipmentRate = new ShipmentRate(new Money($rate->rate * 100, $rate->currency));
     $shipmentRate->setExternalId($rate->id);
     $shipmentRate->setShipmentExternalId($rate->shipment_id);
     $shipmentRate->setCarrier($rate->carrier);
     $shipmentRate->setService($rate->service);
     $shipmentRate->setIsDeliveryDateGuaranteed($rate->delivery_date_guaranteed);
     if ($rate->list_rate !== null) {
         $shipmentRate->setListRate(new Money($rate->list_rate * 100, $rate->list_currency));
     }
     if ($rate->retail_rate !== null) {
         $shipmentRate->setRetailRate(new Money($rate->retail_rate * 100, $rate->retail_currency));
     }
     if (!empty($rate->delivery_date)) {
         $shipmentRate->setDeliveryDate(new DateTime($rate->delivery_date));
     }
     if (!empty($rate->delivery_days)) {
         $shipmentRate->setDeliveryDays($rate->delivery_days);
     }
     return $shipmentRate;
 }