protected function getTestOrder($new_order = false) { xdebug_stop_code_coverage(false); if ($this->order && !$new_order) { return $this->order; } \XLite\Core\Auth::getInstance()->logoff(); $this->testOrder['date'] = time(); $order = \XLite\Core\Database::getRepo('XLite\\Model\\Order')->insert($this->testOrder); $order->setCurrency(\XLite\Core\Database::getRepo('XLite\\Model\\Currency')->find(840)); if ($this->orderProducts) { foreach ($this->orderProducts as $sku) { $product = $this->getProductBySku($sku); $this->assertNotNull($product, 'Product with SKU ' . $sku . ' not found!'); $item = new \XLite\Model\OrderItem(); $item->setProduct($product); $item->setAmount(1); $order->addItem($item); } } else { $item = new \XLite\Model\OrderItem(); $item->setProduct($this->getProduct()); $item->setAmount(1); $order->addItem($item); } $list = \XLite\Core\Database::getRepo('XLite\\Model\\Profile')->findAll(); $found = false; foreach ($list as $p) { if (!$p->getOrder() && $p->getLogin() == '*****@*****.**') { $order->setProfileCopy($p); $found = true; break; } } $this->assertTrue($found, 'test order\'s profile is not found'); $order->calculate(); \XLite\Core\Database::getRepo('XLite\\Model\\Order')->update($order); if (!$this->order || $new_order) { $this->orders[] = $order; } $this->order = $order; xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); return $order; }
/** * Define specific data structure which will be sent in the triggering event (model.selected) * * @param mixed $item Model item * * @return string */ protected function defineDataItem($item) { $data = parent::defineDataItem($item); $orderItem = new \XLite\Model\OrderItem(); $orderItem->setProduct($item); if ($item->hasEditableAttributes()) { $orderItem->setAttributeValues($item->prepareAttributeValues()); } $orderItem = $this->postprocessOrderItem($orderItem); $orderItem->setItemNetPrice(null); $orderItem->setPrice(null); $orderItem->calculate(); $orderItem->renew(); $data['clear_price'] = $orderItem->getClearPrice(); $data['selected_price'] = $orderItem->getDisplayPrice(); $data['max_qty'] = $orderItem->getProductAvailableAmount(); $data['server_price_control'] = $orderItem->isPriceControlledServer(); if ($item->hasEditableAttributes()) { // SKU may differ after attributes selection $data['selected_sku'] = $orderItem->getSku(); $data['presentation'] = $this->formatItem($orderItem); $data['clear_price'] = $orderItem->getClearPrice(); $data['server_price_control'] = $orderItem->isPriceControlledServer(); if ($data['server_price_control']) { $data['selected_price'] = $orderItem->getDisplayPrice(); } $widget = new \XLite\View\OrderItemAttributes(array('orderItem' => $orderItem, 'idx' => \XLite\Core\Request::getInstance()->idx ?: $orderItem->getItemId())); $widget->init(); $data['selected_attributes'] = $widget->getContent(); $widget = new \XLite\View\InvoiceAttributeValues(array('item' => $orderItem, 'displayVariative' => 1)); $widget->init(); $data['attributes_widget'] = $widget->getContent(); } $this->orderItem = $orderItem; return $data; }
/** * Prepare order item class for adding to cart. * This method takes \XLite\Model\Product class and amount and creates \XLite\Model\OrderItem. * This order item container will be added to cart in $this->addItem() method. * * @param \XLite\Model\Product $product Product class to add to cart * @param integer $amount Amount of product to add to cart * * @return \XLite\Model\OrderItem */ protected function prepareOrderItem(\XLite\Model\Product $product, $amount) { $item = null; if ($product) { $item = new \XLite\Model\OrderItem(); $item->setOrder($this->getCart()); $item->setProduct($product); // We make amount correction if there is no such product with additional specifications // which are provided in order item container $newAmount = $this->correctAmountToAdd($item, $amount); if ($newAmount > 0) { $item->setAmount($newAmount); } else { $item->setOrder(null); $item = null; } } return $item; }
public function testGetProduct() { $order = $this->getTestOrder(); $item = $order->getItems()->get(0); $id = $item->getItemId(); $this->assertEquals($this->getProduct(), $item->getProduct(), 'check object'); $item = new \XLite\Model\OrderItem(); $this->assertTrue(is_null($item->getProduct()), 'check empty object #2'); \XLite\Core\Database::getEM()->clear(); $item = \XLite\Core\Database::getRepo('XLite\\Model\\OrderItem')->find($id); $this->assertEquals($this->getProduct(), $item->getProduct(), 'check object #2'); $item = \XLite\Core\Database::getRepo('XLite\\Model\\OrderItem')->find($id); \XLite\Core\Database::getEM()->remove($this->getProduct()); \XLite\Core\Database::getEM()->flush(); \XLite\Core\Database::getEM()->clear(); $item = \XLite\Core\Database::getRepo('XLite\\Model\\OrderItem')->find($id); $this->assertFalse(is_null($item), 'check item from DB'); $this->assertFalse(is_null($item->getProduct()), 'check dump object #2'); }
/** * Prepare order item class for adding to cart. * This method takes \XLite\Model\Product class and amount and creates \XLite\Model\OrderItem. * This order item container will be added to cart in $this->addItem() method. * * @param \XLite\Model\Product $product Product class to add to cart OPTIOANL * @param integer $amount Amount of product to add to cart OPTIONAL * * @return \XLite\Model\OrderItem */ protected function prepareOrderItem(\XLite\Model\Product $product = null, $amount = null) { $item = null; if ($product) { $item = new \XLite\Model\OrderItem(); $item->setOrder($this->getCart()); $item->setAttributeValues($product->prepareAttributeValues(\XLite\Core\Request::getInstance()->attribute_values)); $item->setProduct($product); // We make amount correction if there is no such product with additional specifications // which are provided in order item container $newAmount = $this->correctAmountToAdd($item, $amount); if (0 < $newAmount) { $item->setAmount($newAmount); } else { $item->setOrder(null); $item = null; } } return $item; }
/** * 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; }
/** * Get prepared order item by product ID * * @return array */ protected function getPreparedItemByProductId() { $order = $this->getOrder(); $request = \XLite\Core\Request::getInstance(); $item = new \XLite\Model\OrderItem(); $item->setOrder($order); $item->setProduct(\XLite\Core\Database::getRepo('XLite\\Model\\Product')->find($request->product_id)); $attributes = $request->new; $attributes = reset($attributes); $attributeValues = array(); if (!empty($attributes['attribute_values'])) { $attributeValues = $attributes['attribute_values']; } return array($item, $attributeValues); }
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)'); }
/** * prepareCart * * @return void * @access protected * @see ____func_see____ * @since 1.0.0 */ protected function prepareCart() { $cart = \XLite\Model\Cart::getInstance(); $cart->setItems(new \Doctrine\Common\Collections\ArrayCollection()); $item = new \XLite\Model\OrderItem(); $item->setProduct($this->getProductWithInventory()); $item->setAmount(self::CART_AMOUNT_WITH_INVENTORY); $cart->addItem($item); $item = new \XLite\Model\OrderItem(); $item->setProduct($this->getProductWithoutInventory()); $item->setAmount(self::CART_AMOUNT_WITHOUT_INVENTORY); $cart->addItem($item); }