コード例 #1
0
ファイル: DefaultService.php プロジェクト: ascertain/NGshop
 public function __construct($offerClass, $offerItemClass, $parentFolderPath)
 {
     $this->offerClass = $offerClass;
     $this->offerItemClass = $offerItemClass;
     $this->parentFolderPath = strftime($parentFolderPath, time());
     \Pimcore\Model\Object\Service::createFolderByPath($this->parentFolderPath);
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
ファイル: Importer.php プロジェクト: ascertain/NGshop
 /**
  * @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();
     }
 }
コード例 #5
0
 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"));
 }