Beispiel #1
0
 public function testCreate()
 {
     $order = $this->getTestOrder();
     $this->assertEquals(1, $order->getItems()->count(), 'check items count');
     $item = $order->getItems()->get(0);
     $this->assertTrue(0 < $item->getItemId(), 'check items id');
     $this->assertEquals($this->getProduct()->getProductId(), $item->getObject()->getId(), 'check product id');
     $this->assertEquals($this->getProduct()->getName(), $item->getName(), 'check name');
     $this->assertEquals($this->getProduct()->getSKU(), $item->getSKU(), 'check sku');
     $this->assertEquals($this->getProduct()->getPrice(), $item->getPrice(), 'check price');
     $this->assertEquals(1, $item->getAmount(), 'check amount');
     // Saved modifiers
     $surcharge = new \XLite\Model\OrderItem\Surcharge();
     $surcharge->setType('shipping');
     $surcharge->setCode('ttt');
     $surcharge->setValue(10.0);
     $surcharge->setInclude(false);
     $surcharge->setAvailable(true);
     $surcharge->setClass(get_called_class());
     $surcharge->setName('test');
     $item->getSurcharges()->add($surcharge);
     $surcharge->setOwner($item);
     $count = count($item->getSurcharges());
     $this->assertEquals($surcharge, $item->getSurcharges()->get($count - 1), 'check surcharge');
 }
Beispiel #2
0
 /**
  * Add order item surcharge
  *
  * @param \XLite\Model\OrderItem $item      Order item
  * @param string                 $code      Surcharge code
  * @param float                  $value     Value
  * @param boolean                $include   Include flag OPTIONAL
  * @param boolean                $available Availability flag OPTIONAL
  *
  * @return \XLite\Model\OrderItem\Surcharge
  */
 protected function addOrderItemSurcharge(\XLite\Model\OrderItem $item, $code, $value, $include = false, $available = true)
 {
     $surcharge = new \XLite\Model\OrderItem\Surcharge();
     $surcharge->setType($this->type);
     $surcharge->setCode($code);
     $surcharge->setValue($value);
     $surcharge->setInclude($include);
     $surcharge->setAvailable($available);
     $surcharge->setClass(get_called_class());
     $info = $this->getSurchargeInfo($surcharge);
     $surcharge->setName($info->name);
     $item->addSurcharges($surcharge);
     $surcharge->setOwner($item);
     return $surcharge;
 }