Esempio n. 1
0
 /**
  * testCreate
  *
  * @return void
  * @access public
  * @see    ____func_see____
  * @since  1.0.0
  */
 public function testCreate()
 {
     $order = $this->getTestOrder();
     $this->assertTrue(0 < $order->getOrderId(), 'check order id');
     foreach ($order as $k => $v) {
         $m = 'get' . \XLite\Core\Converter::convertToCamelCase($k);
         $this->assertEquals($v, $order->{$m}(), 'Check test order: ' . $k);
     }
     $this->assertEquals($this->getProduct()->getProductId(), $order->getItems()->get(0)->getObject()->getProductId(), 'check product id');
     $this->assertEquals('Purchase Order', $order->getPaymentMethod()->getName(), 'check payment method');
     $this->assertFalse(is_null($order->getProfile()), 'check profile');
     $this->assertFalse(is_null($order->getProfile()->getOrder()), 'check profile\'s order');
     $this->assertEquals($order->getOrderId(), $order->getProfile()->getOrder()->getOrderId(), 'check profile\'s order id');
     $this->assertTrue(0 < $order->getDate(), 'check date');
     $shippingCost = $order->getSurchargeSumByType('shipping');
     $this->assertEquals(1, $order->getItems()->get(0)->getAmount(), 'check quantity');
     $this->assertEquals($this->getProduct()->getPrice(), $order->getItems()->get(0)->getPrice(), 'check price');
     $this->assertEquals($this->getProduct()->getPrice(), $order->getItems()->get(0)->getSubtotal(), 'check item subtotal');
     $this->assertEquals($this->getProduct()->getPrice(), $order->getSubtotal(), 'check order subtotal');
     $this->assertEquals(round($shippingCost + $this->getProduct()->getPrice(), 2), $order->getTotal(), 'check total');
     // Payment method
     $pm = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findOneBy(array('service_name' => 'PurchaseOrder'));
     $order->setPaymentMethod($pm);
     $this->assertEquals($pm, $order->getPaymentMethod(), 'check payment method');
     // Saved modifiers
     $surcharge = new \XLite\Model\Order\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');
     $order->getSurcharges()->add($surcharge);
     $surcharge->setOwner($order);
     $count = count($order->getSurcharges());
     $this->assertEquals($surcharge, $order->getSurcharges()->get($count - 1), 'check surcharge');
 }
Esempio n. 2
0
 /**
  * Add order surcharge
  *
  * @param string  $code      Surcharge code
  * @param float   $value     Value
  * @param boolean $include   Include flag OPTIONAL
  * @param boolean $available Availability flag OPTIONAL
  *
  * @return \XLite\Model\Order\Surcharge
  */
 public function addOrderSurcharge($code, $value, $include = false, $available = true)
 {
     $surcharge = new \XLite\Model\Order\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);
     $surcharge->setWeight(count($this->order->getSurcharges()));
     $this->order->addSurcharges($surcharge);
     $surcharge->setOwner($this->order);
     return $surcharge;
 }
Esempio n. 3
0
 /**
  * Assemble default dump surcharge
  *
  * @param string $type  Type
  * @param string $code  Code
  * @param string $class Class
  * @param string $name  Name
  *
  * @return array
  */
 protected function assembleDefaultDumpSurcharge($type, $code, $class, $name)
 {
     $surcharge = new \XLite\Model\Order\Surcharge();
     $surcharge->setType($type);
     $surcharge->setCode($code);
     $surcharge->setClass($class);
     $surcharge->setValue(0);
     $surcharge->setName($name);
     $surcharge->setOwner(static::getTemporaryOrder($this->getOrder()->getOrderId(), false) ?: $this->getOrder());
     return array('name' => $surcharge->getTypeName(), 'cost' => $surcharge->getValue(), 'available' => $surcharge->getAvailable(), 'count' => 1, 'lastName' => $surcharge->getName(), 'code' => $surcharge->getCode(), 'widget' => \Includes\Utils\Operator::checkIfClassExists($class) ? $class::getWidgetClass() : \XLite\Logic\Order\Modifier\AModifier::getWidgetClass(), 'object' => $surcharge);
 }