Inheritance: extends Pimcore\Model\AbstractModel, implements Iterator
Exemplo n.º 1
0
 public function reloadProductsAction()
 {
     /**
      * @var $filterDefinition \Pimcore\Model\Object\Fieldcollection
      */
     $filterDefinition = \Pimcore\Model\Object\Fieldcollection::getById(intval($this->_getParam("filterdef")));
     $this->view->filterDefinitionObject = $filterDefinition;
     $indexService = OnlineShop_Framework_Factory::getInstance()->getIndexService();
     $productList = $indexService->getProductListForCurrentTenant();
     $productList->setVariantMode(OnlineShop_Framework_IProductList::VARIANT_MODE_INCLUDE_PARENT_OBJECT);
     $filterService = OnlineShop_Framework_Factory::getInstance()->getFilterService($this->view);
     $orderByOptions = array();
     $this->view->orderByOptions = $orderByOptions;
     if ($filterDefinition) {
         // set up product list
         OnlineShop_Framework_FilterService_Helper::setupProductList($filterDefinition, $productList, $this->_getAllParams(), $this->view, $filterService, true, true);
         // end set up product list
     }
     $this->view->productList = $productList;
     $this->view->filterService = $filterService;
 }
Exemplo n.º 2
0
 /**
  * @param $object
  */
 public function delete($object)
 {
     $container = new Object\Fieldcollection(null, $this->getName());
     $container->delete($object);
 }
Exemplo n.º 3
0
 /**
  * @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";
                 }
                 $this->logger->info("Updated review " . $reviewObject->getId(), $reviewObject, null, self::COMPONENT);
                 if ($page % 5 == 0) {
                     \Pimcore::collectGarbage();
                 }
             }
             if (count($reviews) < $pageSize) {
                 break;
             }
             $page++;
         }
         $shopConfiguration->setLastSync(new Pimcore\Date($startTime));
         $shopConfiguration->save();
     }
 }
 public function addressAction()
 {
     $this->view->redirect = $this->getParam("redirect", $this->view->url(array("lang" => $this->language, "action" => "addresses"), "coreshop_user", true));
     $update = $this->getParam("address");
     $this->view->isNew = false;
     foreach ($this->session->user->getAddresses() as $address) {
         if ($address->getName() === $update) {
             $this->view->address = $address;
         }
     }
     if (!$this->view->address instanceof CoreShopUserAddress) {
         $this->view->address = new CoreShopUserAddress();
         $this->view->isNew = true;
     }
     if ($this->getRequest()->isPost()) {
         $params = $this->getAllParams();
         $addressParams = array();
         foreach ($params as $key => $value) {
             if (startsWith($key, "address_")) {
                 $addressKey = str_replace("address_", "", $key);
                 $addressParams[$addressKey] = $value;
             }
         }
         $adresses = $this->session->user->getAddresses();
         if (!$adresses instanceof Object\Fieldcollection) {
             $adresses = new Object\Fieldcollection();
         }
         if ($update) {
             for ($i = 0; $i < count($this->session->user->getAddresses()); $i++) {
                 if ($this->session->user->getAddresses()->get($i)->getName() == $update) {
                     //$this->session->user->getAddresses()->remove($i);
                     break;
                 }
             }
         }
         $this->view->address->setValues($addressParams);
         //TODO: Check if country exists and is valid
         $this->view->address->setCountry(Country::getById($addressParams['country']));
         if ($this->view->isNew) {
             $adresses->add($this->view->address);
         }
         $this->session->user->save();
         if (array_key_exists("_redirect", $params)) {
             $this->_redirect($params['_redirect']);
         } else {
             $this->_redirect("/de/shop");
         }
     }
 }