コード例 #1
0
 public function addSubtitleFromProduct($encoder, &$item, $product)
 {
     if ($product->description_short) {
         $subtitle = $product->description_short;
         $subtitle = CartAPI_Handlers_Helpers::removeHtmlTags($subtitle);
         $encoder->addString($item, 'Subtitle', $subtitle);
     }
 }
コード例 #2
0
 public function handleBuyerRegisterUserPassword($metadata, $request, $encoder)
 {
     // prepare the fields inside the POST (so we can use Prestashop's validateController)
     unset($_POST['email']);
     if (isset($request['Buyer']['Username'])) {
         $_POST['email'] = $request['Buyer']['Username'];
     }
     unset($_POST['passwd']);
     if (isset($request['Buyer']['Password'])) {
         $_POST['passwd'] = $request['Buyer']['Password'];
     }
     unset($_POST['firstname']);
     if (isset($request['Buyer']['FirstName'])) {
         $_POST['firstname'] = $request['Buyer']['FirstName'];
     }
     unset($_POST['lastname']);
     if (isset($request['Buyer']['LastName'])) {
         $_POST['lastname'] = $request['Buyer']['LastName'];
     }
     // verify fields are valid
     $customer = new Customer();
     if (_PS_VERSION_ < '1.5') {
         $errors = $customer->validateControler();
     } else {
         $errors = $customer->validateController();
     }
     if (is_array($errors) && count($errors) > 0) {
         CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags($errors[0]));
     }
     // make sure the customer doesn't already exist
     if (Customer::customerExists($_POST['email'])) {
         CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags(Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.')));
     }
     // add the new user
     $customer->active = 1;
     if (property_exists('Customer', 'is_guest')) {
         $customer->is_guest = 0;
     }
     if (!$customer->add()) {
         CartAPI_Helpers::dieOnError($encoder, 'RegisterNotAuthorized', CartAPI_Handlers_Helpers::removeHtmlTags(Tools::displayError('An error occurred while creating your account.')));
     }
     // see if we need to login too
     if (!isset($request['Login']) || $request['Login'] == 'true') {
         $cookie = $this->syncCookie($customer);
         // run the after login events, actually don't since prestashop AuthController doesn't do it
         // $this->afterBuyerLogin($customer);
     }
     // run the after register events
     $this->afterBuyerRegister($customer, $request['Buyer']);
 }
コード例 #3
0
 public function validateGlobalCartDiscounts(&$errors, $reportErrors = false)
 {
     global $cart, $cookie;
     if (_PS_VERSION_ < '1.5') {
         // code taken from CartController preProcess()
         $discounts = $cart->getDiscounts();
         foreach ($discounts as $discount) {
             $discountObj = new Discount((int) $discount['id_discount'], (int) $cookie->id_lang);
             if ($error = $cart->checkDiscountValidity($discountObj, $discounts, $cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), $cart->getProducts())) {
                 $cart->deleteDiscount((int) $discount['id_discount']);
                 $cart->update();
                 // reportErrors added to accomodate the initial checkDiscountValidity() in the beginning of CartController preProcess()
                 if ($reportErrors) {
                     $errors[] = CartAPI_Handlers_Helpers::removeHtmlTags($error);
                     return false;
                 }
             }
         }
     } else {
         // code taken from CartController processChangeProductInCart()
         $more_errors = CartRule::autoRemoveFromCart();
         if (count($more_errors) && $reportErrors) {
             $errors = array_merge($errors, $more_errors);
             return false;
         }
     }
     return true;
 }