示例#1
0
 /**
  * @param $user
  * @param $password
  * @return int|\Shopware_StoreApi_Models_Auth
  */
 private function login($user, $password)
 {
     $auth = $this->store->getAuthService()->login($user, $password);
     if ($auth instanceof \Shopware_StoreApi_Exception_Response) {
         $this->handleError(array('success' => false, 'source' => 'auth', 'code' => $auth->getCode(), 'message' => $auth->getMessage()));
     }
     return $auth;
 }
 /**
  * @param \Shopware_StoreApi_Models_Domain $domain
  * @param \Shopware_StoreApi_Models_Auth $auth
  * @param $productId
  * @param $rentVersion
  * @param $pluginNames
  * @param $licence
  * @return array|\Shopware_StoreApi_Models_Order
  */
 private function buyProduct(\Shopware_StoreApi_Models_Domain $domain, \Shopware_StoreApi_Models_Auth $auth, \Shopware_StoreApi_Models_Product $product, $rentVersion, $pluginNames, $licence)
 {
     //check if the user is logged in the community store and the token is valid
     if (!$this->store->getAuthService()->isTokenValid($auth)) {
         $this->handleError(array('success' => false, 'loginRequired' => true));
     }
     $licence = $licence . '';
     //        //licence required and isn't licence plugin?
     //        if (!empty($licence) && strlen($licence) > 0 && !in_array('SwagLicense', $pluginNames) ) {
     //            die('never');
     //            //the licence plugin requires the ionCubeLoader
     //            if (!$this->isIonCubeLoaderLoaded()) {
     //                return array(
     //                    'success' => false,
     //                    'noDecoder' => true
     //                );
     //            }
     //
     //            $localeLicensePlugin = $this->getLocaleLicensePlugin();
     //
     //            //license plugin exist on the shopware shop?
     //            if (!$localeLicensePlugin instanceof \Shopware\Models\Plugin\Plugin) {
     //                //return licensePluginRequired to send a new ajax request to buy the license plugin
     //                return array(
     //                    'success' => false,
     //                    'licensePluginRequired' => true
     //                );
     //            } else {
     //                /**@var $localeLicensePlugin \Shopware\Models\Plugin\Plugin*/
     //                if ($localeLicensePlugin->getInstalled() === null) {
     //                    $this->installPlugin($localeLicensePlugin);
     //                }
     //                if (!$localeLicensePlugin->getActive()) {
     //                    $this->activatePlugin($localeLicensePlugin);
     //                }
     //            }
     //        }
     //        $domain = new \Shopware_StoreApi_Models_Domain(array(
     //            'domain'     => $httpHost,
     //            'account_id' =>  Shopware()->BackendSession()->pluginManagerAccountId
     //        ));
     // after the domain resolved, we can perform the order
     /** @var $orderModel \Shopware_StoreApi_Models_Order*/
     $orderModel = $this->store->getOrderService()->orderProduct($auth, $domain, $product, $rentVersion);
     //first we have to check if an request error occurred. This errors will be displayed in a growl message
     if ($orderModel instanceof \Shopware_StoreApi_Exception_Response) {
         $this->handleError(array('code' => $orderModel->getCode(), 'message' => $this->getOrderExceptionMessage($orderModel->getCode())));
     }
     //if the request was successfully but the order process wasn't successfully, the account data are not completed
     // for example: The user hasn't enough credits or the user bought the plugin already.
     if (!$orderModel->wasSuccessful()) {
         $this->handleError(array('code' => $orderModel->getErrorType(), 'message' => $this->getOrderExceptionMessage($orderModel->getErrorType(), $orderModel->getErrorData())));
     }
     return $orderModel;
 }