protected function setCurrentCustomer(OnlineShop_OfferTool_AbstractOffer $offer) { $env = OnlineShop_Framework_Factory::getInstance()->getEnvironment(); if (@class_exists("Object_Customer")) { $customer = \Pimcore\Model\Object\Customer::getById($env->getCurrentUserId()); $offer->setCustomer($customer); } return $offer; }
/** * @param OnlineShop_Framework_ICart $cart * * @return OnlineShop_Framework_AbstractOrder * @throws Exception * @throws OnlineShop_Framework_Exception_UnsupportedException */ public function getOrCreateOrder(OnlineShop_Framework_ICart $cart) { $orderListClass = $this->orderClass . "_List"; if (!\Pimcore\Tool::classExists($orderListClass)) { throw new Exception("Class {$orderListClass} does not exist."); } $cartId = get_class($cart) . "_" . $cart->getId(); $orderList = new $orderListClass(); $orderList->setCondition("cartId = ?", array($cartId)); $orders = $orderList->load(); if (count($orders) > 1) { throw new Exception("No unique order found for {$cartId}."); } if (count($orders) == 1) { $order = $orders[0]; } else { //No Order found, create new one $tempOrdernumber = $this->createOrderNumber(); $order = $this->getNewOrderObject(); $order->setParent(\Pimcore\Model\Object\Folder::getById($this->parentFolderId)); $order->setCreationDate(Zend_Date::now()->get()); $order->setKey($tempOrdernumber); $order->setPublished(true); $order->setOrdernumber($tempOrdernumber); $order->setOrderdate(Zend_Date::now()); $order->setCartId($cartId); } //check if pending payment. if one, do not update order from cart $orderAgent = OnlineShop_Framework_Factory::getInstance()->getOrderManager()->createOrderAgent($order); $paymentInfo = $orderAgent->startPayment(false); if ($paymentInfo) { return $order; } //update order from cart $order->setTotalPrice($cart->getPriceCalculator()->getGrandTotal()->getAmount()); $modificationItems = new \Pimcore\Model\Object\Fieldcollection(); foreach ($cart->getPriceCalculator()->getPriceModifications() as $name => $modification) { $modificationItem = new \Pimcore\Model\Object\Fieldcollection\Data\OrderPriceModifications(); $modificationItem->setName($modification->getDescription() ? $modification->getDescription() : $name); $modificationItem->setAmount($modification->getAmount()); $modificationItems->add($modificationItem); } $order->setPriceModifications($modificationItems); $env = OnlineShop_Framework_Factory::getInstance()->getEnvironment(); //sets customer to order - if available // TODO refactor if (@\Pimcore\Tool::classExists("\\Pimcore\\Model\\Object\\Customer")) { $customer = \Pimcore\Model\Object\Customer::getById($env->getCurrentUserId()); $order->setCustomer($customer); } // set order currency $currency = $cart->getPriceCalculator()->getGrandTotal()->getCurrency(); $order->setCurrency($currency->getShortName()); $order->save(); //for each cart item and cart sub item create corresponding order items $orderItems = array(); $i = 0; foreach ($cart->getItems() as $item) { $i++; $orderItem = $this->createOrderItem($item, $order); $orderItem->save(); $subItems = $item->getSubItems(); if (!empty($subItems)) { $orderSubItems = array(); foreach ($subItems as $subItem) { $orderSubItem = $this->createOrderItem($subItem, $orderItem); $orderSubItem->save(); $orderSubItems[] = $orderSubItem; } $orderItem->setSubItems($orderSubItems); $orderItem->save(); } $orderItems[] = $orderItem; } $order->setItems($orderItems); return $order; }