예제 #1
0
 /**
  * Create a cart with fake item
  *
  * @param \XLite\Model\Profile $profile Customer's profile for whom the cart is created for
  * @param \XLite\Model\Payment\Method $paymentMethod Payment methood
  * @param \XLite\Model\Currency $currency Currency
  * @param $total Cart total
  * @param $itemName Name of the fake item
  * @param $itemSku SKU of the fake item
  *
  * @return \XLite\Model\Cart
  */
 public function createFakeCart(\XLite\Model\Profile $profile, \XLite\Model\Payment\Method $paymentMethod, \XLite\Model\Currency $currency, $total, $itemName, $itemSku)
 {
     $cart = new \XLite\Model\Cart();
     $cart->setTotal($total);
     $cart->setDate(time());
     $cart->setOrderNumber(\XLite\Core\Database::getRepo('XLite\\Model\\Order')->findNextOrderNumber());
     $cart->setProfile($profile);
     $cart->setCurrency($currency);
     $cart->setPaymentMethod($paymentMethod, $total);
     \XLite\Core\Database::getEM()->persist($cart);
     \XLite\Core\Database::getEM()->flush();
     $item = new \XLite\Model\OrderItem();
     $item->setName($itemName);
     $item->setSku($itemSku);
     $item->setPrice($total);
     $item->setAmount(1);
     $item->setTotal($total);
     $item->setXpcFakeItem(true);
     \XLite\Core\Database::getEM()->persist($item);
     \XLite\Core\Database::getEM()->flush();
     $cart->addItem($item);
     if (count($cart->getPaymentTransactions()) == 0) {
         // We cannot use first open transaction later, so we need to create it
         $transaction = new \XLite\Model\Payment\Transaction();
         $transaction->setPaymentMethod($paymentMethod);
         $transaction->setValue($total);
         $cart->addPaymentTransactions($transaction);
         $transaction->setOrder($cart);
     }
     return $cart;
 }
예제 #2
0
파일: Order.php 프로젝트: kingsj/core
 public function testGetEventFingerprint()
 {
     $order = $this->getTestOrder();
     $product = $this->getProduct();
     $product->getInventory()->setEnabled(false);
     $etalon = array('items' => array(array('item_id' => $order->getItems()->get(0)->getItemId(), 'key' => 'product.' . $product->getProductId(), 'object_type' => 'product', 'object_id' => $product->getProductId(), 'options' => array(), 'quantity' => 1)));
     $this->assertEquals($etalon, $order->getEventFingerprint(), 'check fingerprint');
     $item = new \XLite\Model\OrderItem();
     $item->setProduct($product);
     $item->setAmount(2);
     $item->setPrice($product->getPrice());
     $this->assertTrue($order->addItem($item), 'check add item');
     $etalon['items'][0]['quantity'] = 3;
     $this->assertEquals($etalon, $order->getEventFingerprint(), 'check fingerprint #2');
     $order->getItems()->clear();
     $etalon['items'] = array();
     $this->assertEquals($etalon, $order->getEventFingerprint(), 'check fingerprint (empty)');
 }