php Pimcore-Model-Object-Service类(方法)实例源码

下面列出了php Pimcore-Model-Object-Service 类(方法)源码代码实例,从而了解它的用法。

作者:ascertai    项目:NGsho   
public function __construct($offerClass, $offerItemClass, $parentFolderPath)
 {
     $this->offerClass = $offerClass;
     $this->offerItemClass = $offerItemClass;
     $this->parentFolderPath = strftime($parentFolderPath, time());
     \Pimcore\Model\Object\Service::createFolderByPath($this->parentFolderPath);
 }

作者:dominikschniepe    项目:pimcor   
public function copyAction()
 {
     $success = false;
     $message = "";
     $sourceId = intval($this->getParam("sourceId"));
     $source = Object::getById($sourceId);
     $session = Tool\Session::get("pimcore_copy");
     $targetId = intval($this->getParam("targetId"));
     if ($this->getParam("targetParentId")) {
         $sourceParent = Object::getById($this->getParam("sourceParentId"));
         // this is because the key can get the prefix "_copy" if the target does already exists
         if ($session->{$this->getParam("transactionId")}["parentId"]) {
             $targetParent = Object::getById($session->{$this->getParam("transactionId")}["parentId"]);
         } else {
             $targetParent = Object::getById($this->getParam("targetParentId"));
         }
         $targetPath = preg_replace("@^" . $sourceParent->getFullPath() . "@", $targetParent . "/", $source->getPath());
         $target = Object::getByPath($targetPath);
     } else {
         $target = Object::getById($targetId);
     }
     if ($target->isAllowed("create")) {
         $source = Object::getById($sourceId);
         if ($source != null) {
             try {
                 if ($this->getParam("type") == "child") {
                     $newObject = $this->_objectService->copyAsChild($target, $source);
                     $session->{$this->getParam("transactionId")}["idMapping"][(int) $source->getId()] = (int) $newObject->getId();
                     // this is because the key can get the prefix "_copy" if the target does already exists
                     if ($this->getParam("saveParentId")) {
                         $session->{$this->getParam("transactionId")}["parentId"] = $newObject->getId();
                         Tool\Session::writeClose();
                     }
                 } else {
                     if ($this->getParam("type") == "replace") {
                         $this->_objectService->copyContents($target, $source);
                     }
                 }
                 $success = true;
             } catch (\Exception $e) {
                 \Logger::err($e);
                 $success = false;
                 $message = $e->getMessage() . " in object " . $source->getFullPath() . " [id: " . $source->getId() . "]";
             }
         } else {
             \Logger::error("could not execute copy/paste, source object with id [ {$sourceId} ] not found");
             $this->_helper->json(array("success" => false, "message" => "source object not found"));
         }
     } else {
         \Logger::error("could not execute copy/paste because of missing permissions on target [ " . $targetId . " ]");
         $this->_helper->json(array("error" => false, "message" => "missing_permission"));
     }
     $this->_helper->json(array("success" => $success, "message" => $message));
 }

作者:Cube-Solution    项目:pimcore-coresho   
/**
  * Prepare a Cart
  *
  * @return CoreShopCart
  * @throws \Exception
  */
 public static function prepare()
 {
     $cartsFolder = Service::createFolderByPath("/coreshop/carts/" . date("Y/m/d"));
     $cart = CoreShopCart::create();
     $cart->setKey(uniqid());
     $cart->setParent($cartsFolder);
     $cart->setPublished(true);
     if (Tool::getUser() instanceof CoreShopUser) {
         $cart->setUser(Tool::getUser());
     }
     $cart->save();
     return $cart;
 }

作者:Cube-Solution    项目:pimcore-coresho   
/**
  * Create a new Payment
  *
  * @param Payment $provider
  * @param $amount
  * @return Object\CoreShopPayment
  * @throws \Exception
  */
 public function createPayment(Payment $provider, $amount)
 {
     $payment = new Object\CoreShopPayment();
     $payment->setKey(uniqid());
     $payment->setPublished(true);
     $payment->setParent(Object\Service::createFolderByPath($this->getFullPath() . "/payments/"));
     $payment->setAmount($amount);
     $payment->setTransactionIdentifier(uniqid());
     $payment->setProvider($provider->getIdentifier());
     $payment->save();
     $this->addPayment($payment);
     return $payment;
 }

作者:emanuel-londo    项目:pimcor   
/**
  * @param $id
  * @return mixed|null|CustomLayout
  * @throws \Exception
  */
 public static function getById($id)
 {
     if ($id === null) {
         throw new \Exception("CustomLayout id is null");
     }
     $cacheKey = "customlayout_" . $id;
     try {
         $customLayout = \Zend_Registry::get($cacheKey);
         if (!$customLayout) {
             throw new \Exception("Custom Layout in registry is null");
         }
     } catch (\Exception $e) {
         try {
             $customLayout = new self();
             $customLayout->getDao()->getById($id);
             Object\Service::synchronizeCustomLayout($customLayout);
             \Zend_Registry::set($cacheKey, $customLayout);
         } catch (\Exception $e) {
             \Logger::error($e);
             return null;
         }
     }
     return $customLayout;
 }

作者:pimcor    项目:pimcor   
/**
  * @param string $key
  * @return mixed
  */
 public function getValueForFieldName($key)
 {
     if (isset($this->{$key})) {
         return $this->{$key};
     } elseif ($this->getClass()->getFieldDefinition($key) instanceof Model\Object\ClassDefinition\Data\CalculatedValue) {
         $value = new Model\Object\Data\CalculatedValue($key);
         $value = Service::getCalculatedFieldValue($this, $value);
         return $value;
     }
     return false;
 }

作者:ChristophWurs    项目:pimcor   
/**
  * @return void
  */
 public function findAction()
 {
     $user = $this->getUser();
     $query = $this->getParam("query");
     if ($query == "*") {
         $query = "";
     }
     $query = str_replace("%", "*", $query);
     $types = explode(",", $this->getParam("type"));
     $subtypes = explode(",", $this->getParam("subtype"));
     $classnames = explode(",", $this->getParam("class"));
     if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) {
         $subtypes = array("object", "variant", "folder");
     }
     $offset = intval($this->getParam("start"));
     $limit = intval($this->getParam("limit"));
     $offset = $offset ? $offset : 0;
     $limit = $limit ? $limit : 50;
     $searcherList = new Data\Listing();
     $conditionParts = array();
     $db = \Pimcore\Db::get();
     //exclude forbidden assets
     if (in_array("asset", $types)) {
         if (!$user->isAllowed("assets")) {
             $forbiddenConditions[] = " `type` != 'asset' ";
         } else {
             $forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user);
             if (count($forbiddenAssetPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
                     $forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
             }
         }
     }
     //exclude forbidden documents
     if (in_array("document", $types)) {
         if (!$user->isAllowed("documents")) {
             $forbiddenConditions[] = " `type` != 'document' ";
         } else {
             $forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user);
             if (count($forbiddenDocumentPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
                     $forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
             }
         }
     }
     //exclude forbidden objects
     if (in_array("object", $types)) {
         if (!$user->isAllowed("objects")) {
             $forbiddenConditions[] = " `type` != 'object' ";
         } else {
             $forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user);
             if (count($forbiddenObjectPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
                     $forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
             }
         }
     }
     if ($forbiddenConditions) {
         $conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
     }
     if (!empty($query)) {
         $queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
         // the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
         // if the query is numeric the user might want to search by id
         //if(is_numeric($query)) {
         //$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
         //}
         $conditionParts[] = $queryCondition;
     }
     //For objects - handling of bricks
     $fields = array();
     $bricks = array();
     if ($this->getParam("fields")) {
         $fields = $this->getParam("fields");
         foreach ($fields as $f) {
             $parts = explode("~", $f);
             if (substr($f, 0, 1) == "~") {
                 //                    $type = $parts[1];
                 //                    $field = $parts[2];
                 //                    $keyid = $parts[3];
                 // key value, ignore for now
             } else {
                 if (count($parts) > 1) {
                     $bricks[$parts[0]] = $parts[0];
                 }
             }
         }
     }
     // filtering for objects
     if ($this->getParam("filter") && $this->getParam("class")) {
         $class = Object\ClassDefinition::getByName($this->getParam("class"));
//.........这里部分代码省略.........

作者:pimcor    项目:pimcor   
/**
  * @return void
  */
 public function findAction()
 {
     $user = $this->getUser();
     $query = $this->getParam("query");
     if ($query == "*") {
         $query = "";
     }
     $query = str_replace("%", "*", $query);
     $query = preg_replace("@([^ ])\\-@", "\$1 ", $query);
     $types = explode(",", $this->getParam("type"));
     $subtypes = explode(",", $this->getParam("subtype"));
     $classnames = explode(",", $this->getParam("class"));
     if ($this->getParam("type") == "object" && is_array($classnames) && empty($classnames[0])) {
         $subtypes = ["object", "variant", "folder"];
     }
     $offset = intval($this->getParam("start"));
     $limit = intval($this->getParam("limit"));
     $offset = $offset ? $offset : 0;
     $limit = $limit ? $limit : 50;
     $searcherList = new Data\Listing();
     $conditionParts = [];
     $db = \Pimcore\Db::get();
     //exclude forbidden assets
     if (in_array("asset", $types)) {
         if (!$user->isAllowed("assets")) {
             $forbiddenConditions[] = " `type` != 'asset' ";
         } else {
             $forbiddenAssetPaths = Element\Service::findForbiddenPaths("asset", $user);
             if (count($forbiddenAssetPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenAssetPaths); $i++) {
                     $forbiddenAssetPaths[$i] = " (maintype = 'asset' AND fullpath not like " . $db->quote($forbiddenAssetPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenAssetPaths);
             }
         }
     }
     //exclude forbidden documents
     if (in_array("document", $types)) {
         if (!$user->isAllowed("documents")) {
             $forbiddenConditions[] = " `type` != 'document' ";
         } else {
             $forbiddenDocumentPaths = Element\Service::findForbiddenPaths("document", $user);
             if (count($forbiddenDocumentPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenDocumentPaths); $i++) {
                     $forbiddenDocumentPaths[$i] = " (maintype = 'document' AND fullpath not like " . $db->quote($forbiddenDocumentPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenDocumentPaths);
             }
         }
     }
     //exclude forbidden objects
     if (in_array("object", $types)) {
         if (!$user->isAllowed("objects")) {
             $forbiddenConditions[] = " `type` != 'object' ";
         } else {
             $forbiddenObjectPaths = Element\Service::findForbiddenPaths("object", $user);
             if (count($forbiddenObjectPaths) > 0) {
                 for ($i = 0; $i < count($forbiddenObjectPaths); $i++) {
                     $forbiddenObjectPaths[$i] = " (maintype = 'object' AND fullpath not like " . $db->quote($forbiddenObjectPaths[$i] . "%") . ")";
                 }
                 $forbiddenConditions[] = implode(" AND ", $forbiddenObjectPaths);
             }
         }
     }
     if ($forbiddenConditions) {
         $conditionParts[] = "(" . implode(" AND ", $forbiddenConditions) . ")";
     }
     if (!empty($query)) {
         $queryCondition = "( MATCH (`data`,`properties`) AGAINST (" . $db->quote($query) . " IN BOOLEAN MODE) )";
         // the following should be done with an exact-search now "ID", because the Element-ID is now in the fulltext index
         // if the query is numeric the user might want to search by id
         //if(is_numeric($query)) {
         //$queryCondition = "(" . $queryCondition . " OR id = " . $db->quote($query) ." )";
         //}
         $conditionParts[] = $queryCondition;
     }
     //For objects - handling of bricks
     $fields = [];
     $bricks = [];
     if ($this->getParam("fields")) {
         $fields = $this->getParam("fields");
         foreach ($fields as $f) {
             $parts = explode("~", $f);
             if (substr($f, 0, 1) == "~") {
                 //                    $type = $parts[1];
                 //                    $field = $parts[2];
                 //                    $keyid = $parts[3];
                 // key value, ignore for now
             } elseif (count($parts) > 1) {
                 $bricks[$parts[0]] = $parts[0];
             }
         }
     }
     // filtering for objects
     if ($this->getParam("filter") && $this->getParam("class")) {
         $class = Object\ClassDefinition::getByName($this->getParam("class"));
         // add Localized Fields filtering
//.........这里部分代码省略.........

作者:pawansgi9    项目:pimcore   
/**
  * @param $id
  * @throws \Exception
  */
 public function getObjectConcreteById($id)
 {
     try {
         $object = Object::getById($id);
         if ($object instanceof Object\Concrete) {
             // load all data (eg. lazy loaded fields like multihref, object, ...)
             Object\Service::loadAllObjectFields($object);
             $apiObject = Webservice\Data\Mapper::map($object, "\\Pimcore\\Model\\Webservice\\Data\\Object\\Concrete\\Out", "out");
             return $apiObject;
         }
         throw new \Exception("Object with given ID (" . $id . ") does not exist.");
     } catch (\Exception $e) {
         \Logger::error($e);
         throw $e;
     }
 }

作者:yonetic    项目:pimcore-coreshop-dem   
/**
  * @see Object\ClassDefinition\Data::getDataForEditmode
  * @param array $data
  * @param null|Model\Object\AbstractObject $object
  * @return array
  */
 public function getDataForEditmode($data, $object = null)
 {
     $return = array();
     $visibleFieldsArray = explode(",", $this->getVisibleFields());
     $gridFields = (array) $visibleFieldsArray;
     // add data
     if (is_array($data) && count($data) > 0) {
         foreach ($data as $metaObject) {
             $object = $metaObject->getObject();
             if ($object instanceof Object\Concrete) {
                 $columnData = Object\Service::gridObjectData($object, $gridFields);
                 foreach ($this->getColumns() as $c) {
                     $getter = "get" . ucfirst($c['key']);
                     $columnData[$c['key']] = $metaObject->{$getter}();
                 }
                 $return[] = $columnData;
             }
         }
     }
     return $return;
 }

作者:yonetic    项目:pimcore-coreshop-dem   
/**
  * @return mixed
  */
 public function getValueFromParent($key)
 {
     $parent = Object\Service::hasInheritableParentObject($this->getObject());
     if (!empty($parent)) {
         $containerGetter = "get" . ucfirst($this->fieldname);
         $brickGetter = "get" . ucfirst($this->getType());
         $getter = "get" . ucfirst($key);
         if ($parent->{$containerGetter}()->{$brickGetter}()) {
             return $parent->{$containerGetter}()->{$brickGetter}()->{$getter}();
         }
     }
     return null;
 }

作者:pimcor    项目:pimcor   
public function objectbrickListAction()
 {
     $list = new Object\Objectbrick\Definition\Listing();
     $list = $list->load();
     if ($this->hasParam("class_id") && $this->hasParam("field_name")) {
         $filteredList = [];
         $classId = $this->getParam("class_id");
         $fieldname = $this->getParam("field_name");
         foreach ($list as $type) {
             /** @var  $type Object\Objectbrick\Definition */
             $clsDefs = $type->getClassDefinitions();
             if (!empty($clsDefs)) {
                 foreach ($clsDefs as $cd) {
                     if ($cd["classname"] == $classId && $cd["fieldname"] == $fieldname) {
                         $filteredList[] = $type;
                         continue;
                     }
                 }
             }
             $layout = $type->getLayoutDefinitions();
             Object\Service::enrichLayoutDefinition($layout);
             $type->setLayoutDefinitions($layout);
         }
         $list = $filteredList;
     }
     $returnValueContainer = new Model\Tool\Admin\EventDataContainer($list);
     \Pimcore::getEventManager()->trigger("admin.class.objectbrickList.preSendData", $this, ["returnValueContainer" => $returnValueContainer, "objectId" => $this->getParam('object_id')]);
     $this->_helper->json(["objectbricks" => $list]);
 }

作者:jjpeters6    项目:pimcor   
/**
  * @see Object_Class_Data::getDataForEditmode
  * @param float $data
  * @return float
  */
 public function getDataForEditmode($data, $object = null)
 {
     if ($data instanceof Model\Object\Data\CalculatedValue) {
         $data = Model\Object\Service::getCalculatedFieldValueForEditMode($object, $data);
     }
     return $data;
 }

作者:solvera    项目:pimcor   
/**
  * Fired before information is sent back to the admin UI about an element
  * @param \Zend_EventManager_Event $e
  * @throws \Exception
  */
 public static function adminElementGetPreSendData($e)
 {
     $element = self::extractElementFromEvent($e);
     $returnValueContainer = $e->getParam('returnValueContainer');
     $data = $returnValueContainer->getData();
     //create a new namespace for WorkflowManagement
     //set some defaults
     $data['workflowManagement'] = ['hasWorkflowManagement' => false];
     if (Workflow\Manager::elementCanAction($element)) {
         $data['workflowManagement']['hasWorkflowManagement'] = true;
         //see if we can change the layout
         $currentUser = Admin::getCurrentUser();
         $manager = Workflow\Manager\Factory::getManager($element, $currentUser);
         $data['workflowManagement']['workflowName'] = $manager->getWorkflow()->getName();
         //get the state and status
         $state = $manager->getElementState();
         $data['workflowManagement']['state'] = $manager->getWorkflow()->getStateConfig($state);
         $status = $manager->getElementStatus();
         $data['workflowManagement']['status'] = $manager->getWorkflow()->getStatusConfig($status);
         if ($element instanceof ConcreteObject) {
             $workflowLayoutId = $manager->getObjectLayout();
             //check for !is_null here as we might want to specify 0 in the workflow config
             if (!is_null($workflowLayoutId)) {
                 //load the new layout into the object container
                 $validLayouts = Object\Service::getValidLayouts($element);
                 //check that the layout id is valid before trying to load
                 if (!empty($validLayouts)) {
                     //todo check user permissions again
                     if ($validLayouts && $validLayouts[$workflowLayoutId]) {
                         $customLayout = ClassDefinition\CustomLayout::getById($workflowLayoutId);
                         $customLayoutDefinition = $customLayout->getLayoutDefinitions();
                         Object\Service::enrichLayoutDefinition($customLayoutDefinition, $e->getParam('object'));
                         $data["layout"] = $customLayoutDefinition;
                     }
                 }
             }
         }
     }
     $returnValueContainer->setData($data);
 }

作者:ascertai    项目:NGsho   
/**
  * @param $shopConfigurations Object\OnlineShopConfiguration
  */
 public function import($shopConfigurations)
 {
     if ($shopConfigurations && !is_array($shopConfigurations)) {
         $shopConfigurations = array($shopConfigurations);
     }
     $pageSize = 20;
     $page = 0;
     /** @var  $shopConfiguration Object\OnlineShopConfiguration */
     foreach ($shopConfigurations as $shopConfiguration) {
         $importDirectory = $shopConfiguration->getTrustedShopReviewsimportDirectory();
         $startTime = time();
         if ($this->logToConsole) {
             echo "Importing reviews for " . $shopConfiguration->getFullPath() . " ...\n";
         }
         /** @var  $startDate Pimcore\Date */
         $startDate = $shopConfiguration->getLastSync();
         while (true) {
             if ($this->logToConsole) {
                 echo "Page=" . $page . "\n";
             }
             $uri = "https://%s:%s@api.trustedshops.com/rest/restricted/v2/shops/%s/reviews.json?page=" . $page . "&size=" . $pageSize;
             if ($startDate) {
                 $uri .= "&startDate=" . date('Y-m-d', $startDate->getTimestamp() - 3600 * 24 * 30);
                 //get ratins from last 30 days - for some reasons trusted shop sometimes dont show all ratings imediately
             }
             $uri = sprintf($uri, $shopConfiguration->getTrustedShopUser(), $shopConfiguration->getTrustedShopPassword(), $shopConfiguration->getTrustedShopKey());
             if ($this->logToConsole) {
                 echo $uri . "\n";
             }
             $this->client->setUri($uri);
             $result = $this->client->request();
             if ($result->getStatus() != 200) {
                 $this->logger->error("Status code " . $result->getStatus(), null, null, self::COMPONENT);
                 throw new \Exception("Status Code: " . $result->getStatus());
             }
             $body = $result->getBody();
             $data = json_decode($body);
             if (!$data) {
                 $this->logger->error("Could not decode data " . $body, null, null, self::COMPONENT);
                 throw new \Exception("Could not decode data");
             }
             $response = $data->response;
             $data = $response->data;
             $shop = $data->shop;
             if ($shop->tsId != $shopConfiguration->getTrustedShopKey()) {
                 $this->logger->error("Tsid mismatch", null, null, self::COMPONENT);
                 throw new \Exception("Tsid mismatch");
             }
             $reviews = $shop->reviews;
             foreach ((array) $reviews as $review) {
                 $uid = $review->UID;
                 $comment = $review->comment;
                 $criterias = $review->criteria;
                 $consumerEmail = $review->consumerEmail;
                 $mark = $review->mark;
                 $markDescription = $review->markDescription;
                 $orderReference = $review->orderReference;
                 $changeDate = $review->changeDate;
                 $creationDate = $review->creationDate;
                 $confirmationDate = $review->confirmationDate;
                 $changeDate = $changeDate ? strtotime($changeDate) : 0;
                 $creationDate = $creationDate ? strtotime($creationDate) : 0;
                 $confirmationDate = $confirmationDate ? strtotime($confirmationDate) : 0;
                 $fc = new Object\Fieldcollection();
                 foreach ($criterias as $criteria) {
                     $mark = $criteria->mark;
                     $criteriaMarkDescription = $criteria->markDescription;
                     $type = $criteria->type;
                     $item = new Object\Fieldcollection\Data\TrustedShopCriteria();
                     $item->setMark($mark);
                     $item->setMarkDescription($criteriaMarkDescription);
                     $item->setCriteriaType($type);
                     $fc->add($item);
                 }
                 $reviewObject = $this->getReview($shopConfiguration, $uid, $consumerEmail, $creationDate);
                 $reviewObject->setShopConfig($shopConfiguration);
                 $reviewObject->setUid($uid);
                 $reviewObject->setComment($comment);
                 $reviewObject->setConsumerEmail($consumerEmail);
                 $reviewObject->setReviewConfirmationDate(new Pimcore\Date($confirmationDate));
                 $reviewObject->setReviewCreationDate(new Pimcore\Date($creationDate));
                 $reviewObject->setReviewChangeDate(new Pimcore\Date($changeDate));
                 $reviewObject->setMark($mark);
                 $reviewObject->setMarkDescription($markDescription);
                 $reviewObject->setCritera($fc);
                 $reviewObject->setOrderReference($orderReference);
                 if (!$creationDate) {
                     $path = '/unknown';
                 } else {
                     $path = '/' . date('Y/m/d', $creationDate);
                 }
                 $path = $importDirectory . $path;
                 $reviewObject->setParent(Object\Service::createFolderByPath($path));
                 $reviewObject->save();
                 if ($this->logToConsole) {
                     echo "Saved review " . $reviewObject->getId() . " " . $reviewObject->getFullPath() . "\n";
                 }
//.........这里部分代码省略.........

作者:Cube-Solution    项目:pimcore-coresho   
public function paymentAction()
 {
     $this->checkIsAllowed();
     $this->view->provider = Plugin::getPaymentProviders($this->cart);
     if ($this->getRequest()->isPost()) {
         $paymentProvider = reset($this->getParam("payment_provider", array()));
         foreach ($this->view->provider as $provider) {
             if ($provider->getIdentifier() == ${$paymentProvider}) {
                 $paymentProvider = $provider;
                 break;
             }
         }
         if (!$provider instanceof Payment) {
             $this->view->error = "oh shit, not found";
         } else {
             $this->session->order['paymentProvider'] = $provider;
             $order = new CoreShopOrder();
             $order->setKey(uniqid());
             $order->setParent(Service::createFolderByPath('/coreshop/orders/' . date('Y/m/d')));
             $order->setPublished(true);
             $order->setLang($this->view->language);
             $order->setCustomer($this->session->user);
             $order->setShippingAddress($this->session->order['address']['delivery']);
             $order->setBillingAddress($this->session->order['address']['billing']);
             $order->setPaymentProvider($provider->getIdentifier());
             $order->setOrderDate(new \Zend_Date());
             if ($this->session->order['shippingProvider'] instanceof Shipping) {
                 $order->setShippingProvider($this->session->order['shippingProvider']->getIdentifier());
                 $order->setShipping($this->session->order['shippingProvider']->getShipping($this->cart));
             } else {
                 $order->setShipping(0);
             }
             $order->save();
             $order->importCart($this->cart);
             $this->session->orderId = $order->getId();
             $this->_helper->viewRenderer($provider->processPayment($order, $this->view->url(array("action" => "paymentreturn"), "coreshop_checkout")), null, true);
         }
     }
     $this->view->headTitle($this->view->translate("Payment"));
 }

作者:sfi    项目:pimcor   
/**
  * @param $keyId
  * @param $groupId
  * @param string $language
  * @param bool|false $ignoreFallbackLanguage
  * @return null
  */
 public function getLocalizedKeyValue($groupId, $keyId, $language = "default", $ignoreFallbackLanguage = false, $ignoreDefaultLanguage = false)
 {
     $oid = $this->object->getId();
     $keyConfig = Model\Object\Classificationstore\DefinitionCache::get($keyId);
     if ($keyConfig->getType() == "calculatedValue") {
         $data = new Model\Object\Data\CalculatedValue($this->getFieldname());
         $childDef = Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
         $data->setContextualData("classificationstore", $this->getFieldname(), null, $language, $groupId, $keyId, $childDef);
         $data = Model\Object\Service::getCalculatedFieldValueForEditMode($this->getObject(), $data);
         return $data;
     }
     $fieldDefinition = Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
     $language = $this->getLanguage($language);
     $data = null;
     if (array_key_exists($groupId, $this->items) && array_key_exists($keyId, $this->items[$groupId]) && array_key_exists($language, $this->items[$groupId][$keyId])) {
         $data = $this->items[$groupId][$keyId][$language];
     }
     // check for fallback value
     if ($fieldDefinition->isEmpty($data) && !$ignoreFallbackLanguage && self::doGetFallbackValues()) {
         $data = $this->getFallbackValue($groupId, $keyId, $language, $fieldDefinition);
     }
     if ($fieldDefinition->isEmpty($data) && !$ignoreDefaultLanguage && $language != "default") {
         $data = $this->items[$groupId][$keyId]["default"];
     }
     // check for inherited value
     $doGetInheritedValues = AbstractObject::doGetInheritedValues();
     if ($fieldDefinition->isEmpty($data) && $doGetInheritedValues) {
         $object = $this->getObject();
         $class = $object->getClass();
         $allowInherit = $class->getAllowInherit();
         if ($allowInherit) {
             if ($object->getParent() instanceof AbstractObject) {
                 $parent = $object->getParent();
                 while ($parent && $parent->getType() == "folder") {
                     $parent = $parent->getParent();
                 }
                 if ($parent && ($parent->getType() == "object" || $parent->getType() == "variant")) {
                     if ($parent->getClassId() == $object->getClassId()) {
                         $method = "getLocalizedfields";
                         if (method_exists($parent, $method)) {
                             $getter = "get" . ucfirst($this->fieldname);
                             $classificationStore = $parent->{$getter}();
                             if ($classificationStore instanceof Classificationstore) {
                                 if ($classificationStore->object->getId() != $this->object->getId()) {
                                     $data = $classificationStore->getLocalizedKeyValue($groupId, $keyId, $language, false);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($fieldDefinition && method_exists($fieldDefinition, "preGetData")) {
         $data = $fieldDefinition->preGetData($this, array("data" => $data, "language" => $language, "name" => $groupId . "-" . $keyId));
     }
     return $data;
 }

作者:pimcor    项目:pimcor   
public function replaceAssignmentsAction()
 {
     $success = false;
     $message = "";
     $element = Element\Service::getElementById($this->getParam("type"), $this->getParam("id"));
     $sourceEl = Element\Service::getElementById($this->getParam("sourceType"), $this->getParam("sourceId"));
     $targetEl = Element\Service::getElementById($this->getParam("targetType"), $this->getParam("targetId"));
     if ($element && $sourceEl && $targetEl && $this->getParam("sourceType") == $this->getParam("targetType") && $sourceEl->getType() == $targetEl->getType()) {
         $rewriteConfig = [$this->getParam("sourceType") => [$sourceEl->getId() => $targetEl->getId()]];
         if ($element instanceof Document) {
             $element = Document\Service::rewriteIds($element, $rewriteConfig);
         } elseif ($element instanceof Object\AbstractObject) {
             $element = Object\Service::rewriteIds($element, $rewriteConfig);
         } elseif ($element instanceof Asset) {
             $element = Asset\Service::rewriteIds($element, $rewriteConfig);
         }
         $element->setUserModification($this->getUser()->getId());
         $element->save();
         $success = true;
     } else {
         $message = "source-type and target-type do not match";
     }
     $this->_helper->json(["success" => $success, "message" => $message]);
 }

作者:rolandstol    项目:pimcor   
public function correctPath()
 {
     // set path
     if ($this->getId() != 1) {
         // not for the root node
         if ($this->getParentId() == $this->getId()) {
             throw new \Exception("ParentID and ID is identical, an element can't be the parent of itself.");
         }
         $parent = AbstractObject::getById($this->getParentId());
         if ($parent) {
             // use the parent's path from the database here (getCurrentFullPath), to ensure the path really exists and does not rely on the path
             // that is currently in the parent object (in memory), because this might have changed but wasn't not saved
             $this->setPath(str_replace("//", "/", $parent->getCurrentFullPath() . "/"));
         } else {
             // parent document doesn't exist anymore, set the parent to to root
             $this->setParentId(1);
             $this->setPath("/");
         }
         if (strlen($this->getKey()) < 1) {
             $this->setKey("---no-valid-key---" . $this->getId());
             throw new \Exception("Document requires key, generated key automatically");
         }
     } else {
         if ($this->getId() == 1) {
             // some data in root node should always be the same
             $this->setParentId(0);
             $this->setPath("/");
             $this->setKey("");
             $this->setType("folder");
         }
     }
     if (Service::pathExists($this->getFullPath())) {
         $duplicate = AbstractObject::getByPath($this->getFullPath());
         if ($duplicate instanceof self and $duplicate->getId() != $this->getId()) {
             throw new \Exception("Duplicate full path [ " . $this->getFullPath() . " ] - cannot save object");
         }
     }
     if (strlen($this->getFullPath()) > 765) {
         throw new \Exception("Full path is limited to 765 characters, reduce the length of your parent's path");
     }
 }

作者:pimcor    项目:pimcor   
/**
  * returns a unique key for an element
  *
  * @param $element
  * @return string
  */
 public static function getUniqueKey($element)
 {
     if ($element instanceof Object\AbstractObject) {
         return Object\Service::getUniqueKey($element);
     } elseif ($element instanceof Document) {
         return Document\Service::getUniqueKey($element);
     } elseif ($element instanceof Asset) {
         return Asset\Service::getUniqueKey($element);
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号