Пример #1
0
 /**
  * @param EventgalleryLibraryCart $cart
  * @return EventgalleryLibraryOrder
  */
 public function createOrder($cart)
 {
     $db = JFactory::getDBO();
     $data = $cart->_getInternalDataObject();
     $uuid = uniqid("", true);
     $uuid = base_convert($uuid, 16, 10);
     $query = $db->getQuery(true);
     $query->insert("#__eventgallery_order");
     $query->columns('id');
     $query->values($db->quote($uuid));
     $db->setQuery($query);
     $db->execute();
     $user = JFactory::getUser();
     $data['id'] = $uuid;
     if (!$user->guest) {
         $data['userid'] = $user->id;
     }
     /**
      * @var TableOrder $orderTable
      */
     $orderTable = $this->store($data, 'Order');
     /**
      * @var EventgalleryLibraryImagelineitem $lineitem
      * @var EventgalleryLibraryFactoryImagelineitem $imageLineItemFactory
      */
     $imageLineItemFactory = EventgalleryLibraryFactoryImagelineitem::getInstance();
     foreach ($cart->getLineItems() as $lineitem) {
         $imageLineItemFactory->copyLineItem($orderTable->id, $lineitem);
     }
     /**
      * @var EventgalleryLibraryServicelineitem $lineitem
      * @var EventgalleryLibraryFactoryServicelineitem $serviceLineItemFactory
      */
     $serviceLineItemFactory = EventgalleryLibraryFactoryServicelineitem::getInstance();
     foreach ($cart->getServiceLineItems() as $lineitem) {
         $serviceLineItemFactory->copyLineItem($orderTable->id, $lineitem);
     }
     /**
      * @var EventgalleryLibraryManagerOrderstatus $orderstatusMgr
      */
     $orderstatusMgr = EventgalleryLibraryManagerOrderstatus::getInstance();
     /**
      * @var EventgalleryLibraryOrder $order
      */
     $order = new EventgalleryLibraryOrder($orderTable->id);
     $order->setOrderStatus($orderstatusMgr->getDefaultOrderStatus(EventgalleryLibraryOrderstatus::TYPE_ORDER));
     $order->setPaymentStatus($orderstatusMgr->getDefaultOrderStatus(EventgalleryLibraryOrderstatus::TYPE_PAYMENT));
     $order->setShippingStatus($orderstatusMgr->getDefaultOrderStatus(EventgalleryLibraryOrderstatus::TYPE_SHIPPING));
     $order->setDocumentNumber(EventgalleryLibraryDatabaseSequence::generateNewId());
     return $order;
 }
Пример #2
0
 /**
  * adds an image to the cart and checks if this action is actually allowed
  */
 function addItem($foldername, $filename, $count = 1, $typeid = NULL)
 {
     if ($filename == NULL || $foldername == NULL) {
         throw new Exception("can't add item with invalid file or folder name");
     }
     /**
      * @var EventgalleryLibraryManagerFile $fileMgr
      */
     $fileMgr = EventgalleryLibraryManagerFile::getInstance();
     $file = $fileMgr->getFile($foldername, $filename);
     /* security check BEGIN */
     if (!$file->isPublished()) {
         throw new Exception("the item you try to add is not published.");
     }
     if (!$file->getFolder()->isCartable()) {
         throw new Exception("the item you try to add is not cartable.");
     }
     if (!$file->getFolder()->isVisible()) {
         throw new Exception("the item you try to add is not visible for you. You might want to login first.");
     }
     if (!$file->getFolder()->isAccessible()) {
         throw new Exception("the item you try to add is not accessible. You might need to enter a password to unlock the folder first.");
     }
     /* check of the folder allows the type id. take the first type if not specific type was given. */
     /*@var EventgalleryLibraryImagetype */
     $imageType = NULL;
     if ($typeid == NULL) {
         $imageType = $file->getFolder()->getImageTypeSet()->getDefaultImageType();
     } else {
         $imageType = $file->getFolder()->getImageTypeSet()->getImageType($typeid);
     }
     if ($imageType == NULL) {
         throw new Exception("the image type you specified for the new item is invalid. Reason for this can be that there is not image type set, no image type set image type assignments or the image type set does not contain the image type");
     }
     /* security check END */
     /**
      * @var EventgalleryLibraryFactoryImagelineitem $imageLineItemFactory
      */
     $imageLineItemFactory = EventgalleryLibraryFactoryImagelineitem::getInstance();
     $lineitem = $this->getLineItemByFileAndType($foldername, $filename, $typeid);
     if ($lineitem == null) {
         $lineitem = $imageLineItemFactory->createLineitem($this->getId(), $foldername, $filename, $typeid, $count);
     } else {
         $lineitem->setQuantity($lineitem->getQuantity() + $count);
     }
     $this->_updateLineItemContainer();
     return $lineitem;
 }