Beispiel #1
0
 /**
  * @static
  * @param array $types
  * @return void
  */
 public static function objects($types = null, $classes = null)
 {
     if (empty($types)) {
         $types = array("object", "folder", "variant");
     }
     $classesCondition = "";
     if (!empty($classes)) {
         $classesCondition .= " AND o_className IN ('" . implode("','", $classes) . "')";
     }
     $list = new Object_List();
     $list->setCondition("o_type IN ('" . implode("','", $types) . "')" . $classesCondition);
     self::loadToCache($list);
 }
Beispiel #2
0
 public function testLazyLoading()
 {
     //reset registry
     Test_Tool::resetRegistry();
     //find an object with data
     $objectList = new Object_List();
     $objectList->setCondition("o_key like '%_data' and o_type = 'object'");
     $objects = $objectList->load();
     $this->assertTrue($objects[0] instanceof Object_Abstract);
     //check for lazy loading elements
     $this->assertTrue($objects[0]->lazyObjects === null);
     $this->assertTrue(is_array($objects[0]->getLazyObjects()));
     $this->assertTrue($objects[0]->lazyMultihref === null);
     $this->assertTrue(is_array($objects[0]->getLazyMultihref()));
     $this->assertTrue($objects[0]->lazyHref === null);
     $this->assertTrue(is_object($objects[0]->getLazyHref()));
 }
 public function copyInfoAction()
 {
     $transactionId = time();
     $pasteJobs = array();
     $session = new Zend_Session_Namespace("pimcore_copy");
     $session->{$transactionId} = array();
     if ($this->_getParam("type") == "recursive") {
         $object = Object_Abstract::getById($this->_getParam("sourceId"));
         // first of all the new parent
         $pasteJobs[] = array(array("url" => "/admin/object/copy", "params" => array("sourceId" => $this->_getParam("sourceId"), "targetId" => $this->_getParam("targetId"), "type" => "child", "transactionId" => $transactionId, "saveParentId" => true)));
         if ($object->hasChilds(array(Object_Abstract::OBJECT_TYPE_OBJECT, Object_Abstract::OBJECT_TYPE_FOLDER, Object_Abstract::OBJECT_TYPE_VARIANT))) {
             // get amount of childs
             $list = new Object_List();
             $list->setCondition("o_path LIKE '" . $object->getFullPath() . "/%'");
             $list->setOrderKey("LENGTH(o_path)", false);
             $list->setOrder("ASC");
             $list->setObjectTypes(array(Object_Abstract::OBJECT_TYPE_OBJECT, Object_Abstract::OBJECT_TYPE_FOLDER, Object_Abstract::OBJECT_TYPE_VARIANT));
             $childIds = $list->loadIdList();
             if (count($childIds) > 0) {
                 foreach ($childIds as $id) {
                     $pasteJobs[] = array(array("url" => "/admin/object/copy", "params" => array("sourceId" => $id, "targetParentId" => $this->_getParam("targetId"), "sourceParentId" => $this->_getParam("sourceId"), "type" => "child", "transactionId" => $transactionId)));
                 }
             }
         }
     } else {
         if ($this->_getParam("type") == "child" || $this->_getParam("type") == "replace") {
             // the object itself is the last one
             $pasteJobs[] = array(array("url" => "/admin/object/copy", "params" => array("sourceId" => $this->_getParam("sourceId"), "targetId" => $this->_getParam("targetId"), "type" => $this->_getParam("type"), "transactionId" => $transactionId)));
         }
     }
     $this->_helper->json(array("pastejobs" => $pasteJobs));
 }
Beispiel #4
0
 /**
  * @return void
  */
 public function delete()
 {
     // delete all objects using this class
     $list = new Object_List();
     $list->setCondition("o_classId = ?", $this->getId());
     $list->load();
     foreach ($list->getObjects() as $o) {
         $o->delete();
     }
     $this->deletePhpClasses();
     // empty object cache
     try {
         Pimcore_Model_Cache::clearTag("class_" . $this->getId());
     } catch (Exception $e) {
     }
     // empty output cache
     try {
         Pimcore_Model_Cache::clearTag("output");
     } catch (Exception $e) {
     }
     $this->getResource()->delete();
 }
Beispiel #5
0
 /**
  * @return array
  */
 public function getO_childs($objectTypes = array(self::OBJECT_TYPE_OBJECT, self::OBJECT_TYPE_FOLDER))
 {
     if ($this->o_childs === null || $this->lastGetChildsObjectTypes != $objectTypes) {
         $this->lastGetChildsObjectTypes = $objectTypes;
         $list = new Object_List(true);
         $list->setCondition("o_parentId = ?", $this->getO_id());
         $list->setOrderKey("o_key");
         $list->setOrder("asc");
         $list->setObjectTypes($objectTypes);
         $this->o_childs = $list->load();
     }
     return $this->o_childs;
 }
 public function checkoutAction()
 {
     $id_customer = $_POST['id_customer'];
     $return_array = array();
     try {
         // get cart open
         $carts = new Object\Carts\Listing();
         $carts->setCondition("Customer__id = " . $id_customer . " and Status = 'open'");
         $carts->setLimit(1);
         $cart = array();
         if ($carts->Count() > 0) {
             foreach ($carts as $c) {
                 $cart = $c;
             }
             // count detail on cart
             $carts_detail = new Object\CartsDetail\Listing();
             $carts_detail->setCondition("Carts__id = " . $cart->o_id);
             $n_detail = $carts_detail->count();
             if ($n_detail > 0) {
                 // get object customer
                 $customer = Object::getById($id_customer);
                 $now = date("Y-m-d,H-i");
                 $get_time_now = new Pimcore_Date($now);
                 $newOrder = Object\Orders::create();
                 $newOrder->setKey(\Pimcore\File::getValidFilename('order_' . $id_customer . '_' . $now));
                 //to get and set ID PARENT FOLDER
                 $id_folder = new Object_List();
                 $id_folder->setCondition("o_key='orders-management'");
                 $o_Pid = 0;
                 foreach ($id_folder as $parent) {
                     $oidParent = $parent->getO_id();
                 }
                 $newOrder->setParentId($oidParent);
                 $newOrder->setCarts($cart);
                 $newOrder->setCustomer($customer);
                 $newOrder->setOrderDate($get_time_now);
                 $newOrder->setPublished(1);
                 $newOrder->save();
                 //Set log checkout cart
                 $base_url = Website_P1GlobalFunction::getBaseUrl();
                 $url_api = $base_url . '/core/log/set';
                 $id_activity = Website_P1GlobalFunction::getActivities("customer_checkout_cart");
                 $array_object = json_encode(array("id_order" => $newOrder->o_id));
                 $data = array("user" => $id_customer, "activities" => $id_activity, "object" => $array_object);
                 $setLogCheckout = json_decode(Website_P1GlobalFunction::CallAPI("post", $url_api, $data));
                 $cart->setstatus("close");
                 $cart->save();
                 //Set log close cart
                 $id_activity = Website_P1GlobalFunction::getActivities("customer_close_cart");
                 $array_object = json_encode(array("id_cart" => $cart->o_id));
                 $data = array("user" => $id_customer, "activities" => $id_activity, "object" => $array_object);
                 $setLogClose = json_decode(Website_P1GlobalFunction::CallAPI("post", $url_api, $data));
                 if ($setLogClose->status == "Success" && $setLogCheckout->status == "Success") {
                     $return_data = json_encode(array("id_cart" => $cart->o_id, "id_order" => $newOrder->o_id));
                     $return_array['status'] = 'success';
                     $return_array['message'] = 'success';
                     $return_array['data'] = $return_data;
                 } else {
                     $return_array['status'] = 'Failed';
                     $return_array['message'] = 'Failed checkout cart';
                     $return_array['data'] = '';
                 }
             } else {
                 $return_array['status'] = 'failed';
                 $return_array['message'] = 'Cart is empty';
                 $return_array['data'] = '';
             }
         } else {
             $return_array['status'] = 'failed';
             $return_array['message'] = 'Customer not have cart open';
             $return_array['data'] = '';
         }
     } catch (Exception $ex) {
         $return_array['status'] = 'failed';
         $return_array['message'] = 'Internal service error';
         $return_array['data'] = '';
     }
     $return_json = $this->_helper->json($return_array);
     $this->sendResponse($return_json);
 }
Beispiel #7
0
 public function testCopyAndDeleteObject()
 {
     $objectList = new Object_List();
     $objectList->setCondition("o_key like '%_data%' and o_type = 'object'");
     $objects = $objectList->load();
     $parent = $objects[0];
     $this->assertTrue($parent instanceof Object_Unittest);
     //remove childs if there are some
     if ($parent->hasChilds()) {
         foreach ($parent->getChilds() as $child) {
             $child->delete();
         }
     }
     $this->assertFalse($parent->hasChilds());
     $service = new Object_Service(User::getById(1));
     //copy as child
     $service->copyAsChild($parent, $parent);
     $this->assertTrue($parent->hasChilds());
     $this->assertTrue(count($parent->getChilds()) == 1);
     //copy as child no. 2
     $service->copyAsChild($parent, $parent);
     $this->assertTrue($parent->hasChilds());
     $this->assertTrue(count($parent->getChilds()) == 2);
     $childs = $parent->getChilds();
     //load all in case of lazy loading fields
     Object_Service::loadAllObjectFields($parent);
     Object_Service::loadAllObjectFields($childs[0]);
     Object_Service::loadAllObjectFields($childs[1]);
     $this->assertTrue(Test_Tool::objectsAreEqual($parent, $childs[0], true));
     $this->assertTrue(Test_Tool::objectsAreEqual($parent, $childs[1], true));
     //copy recursivley
     $rootNode = Object_Abstract::getById(1);
     $copy = $service->copyRecursive($rootNode, $parent);
     $this->assertTrue($copy->hasChilds());
     Object_Service::loadAllObjectFields($copy);
     $this->assertTrue(count($copy->getChilds()) == 2);
     $this->assertTrue(Test_Tool::objectsAreEqual($parent, $copy, true));
     //create empty object
     $emptyObject = new Object_Unittest();
     $emptyObject->setOmitMandatoryCheck(true);
     $emptyObject->setParentId(1);
     $emptyObject->setUserOwner(1);
     $emptyObject->setUserModification(1);
     $emptyObject->setCreationDate(time());
     $emptyObject->setKey(uniqid() . rand(10, 99));
     $emptyObject->save();
     $emptyObject->setOmitMandatoryCheck(false);
     $this->assertFalse(Test_Tool::objectsAreEqual($emptyObject, $copy, true));
     //copy contents
     $emptyObject = $service->copyContents($emptyObject, $copy);
     $this->assertTrue(Test_Tool::objectsAreEqual($emptyObject, $copy, true));
     //todo copy contents must fail if types differ
     //delete recusively
     $shouldBeDeleted[] = $copy->getId();
     $childs = $copy->getChilds();
     foreach ($childs as $child) {
         $shouldBeDeleted[] = $child->getId();
     }
     $copy->delete();
     foreach ($shouldBeDeleted as $id) {
         $o = Object_Abstract::getById($id);
         $this->assertFalse($o instanceof Object_Abstract);
     }
 }