コード例 #1
0
 /**
  * Save new categories based on the received array.
  * Takes a json encoded category.
  * Will append a json array of key pairs ["provided id":"saved category id", ] to the $output_array
  * @param array $category the json to array category
  * @param int $parent_id the parent ID of the category to save (the one in OUR database, not Kem's central one)
  */
 function saveCategory($category, $parent_id)
 {
     $cat = new Category();
     $cat->parent_category = $parent_id;
     $cat->visible = $category->visible;
     $cat->is_brand = $category->is_brand;
     $cat->save();
     foreach ($category->localizations as $localization) {
         $loc = new CategoryLocalization();
         $loc->locale_id = Locale::localeIdFromLongCode($localization->locale);
         $loc->category_id = $cat->id;
         $loc->name = $localization->name;
         $loc->visible = $localization->visible;
         $loc->save();
     }
     $GLOBALS['output_array'][$category->id] = $cat->id;
     // Think of the the children
     foreach ($category->children as $child) {
         saveCategory($child, $cat->id);
     }
 }
コード例 #2
0
ファイル: Order.php プロジェクト: KEMSolutions/Boukem1
 /**
  * An array to post to our payment processor (KEM payment) and order printer.
  * @return array order data to display to the end user or print on packing slip
  */
 public function frontendData()
 {
     $orderDetails = $this->orderDetails;
     // Only complete orders with order details can be processed.
     if ($orderDetails === null) {
         return null;
     }
     $user = $this->user;
     // Build a simple array with order data
     $orderdict = array();
     $orderdict["id"] = $this->id;
     $orderdict['user_id'] = $this->user_id;
     $orderdict['timestamp'] = $this->timestamp;
     $orderdict['shipping_type'] = $orderDetails->shipping_type;
     $orderdict["total"] = $orderDetails->total;
     $orderdict["subtotal"] = $orderDetails->subtotal;
     $orderdict["taxes"] = $orderDetails->taxes;
     $orderdict["discount"] = 0.0;
     $orderdict["delivery"] = $orderDetails->shipping;
     $orderdict["balance"] = $this->getBalance();
     $orderdict['email'] = $this->user->email;
     if ($orderDetails->billingAddress) {
         $billing = $orderDetails->billingAddress;
         $orderdict['billing'] = array();
         $orderdict['billing']['firstname'] = $user->firstname;
         $orderdict['billing']['lastname'] = $user->lastname;
         $orderdict['billing']['street1'] = $billing->street1 ? CHtml::encode($billing->street1) : null;
         $orderdict['billing']['street2'] = $billing->street2 ? CHtml::encode($billing->street2) : null;
         $orderdict['billing']['postcode'] = $billing->postcode ? CHtml::encode($billing->postcode) : null;
         $orderdict['billing']['city'] = $billing->city ? CHtml::encode($billing->city) : null;
         $orderdict['billing']['region'] = $billing->region ? CHtml::encode($billing->region) : null;
         $orderdict['billing']['country'] = $billing->country ? CHtml::encode($billing->country) : null;
     }
     if ($orderDetails->shippingAddress) {
         $shipping = $orderDetails->shippingAddress;
         $orderdict['shipping'] = array();
         $orderdict['shipping']['firstname'] = $user->firstname;
         $orderdict['shipping']['lastname'] = $user->lastname;
         $orderdict['shipping']['street1'] = $shipping->street1 ? CHtml::encode($shipping->street1) : null;
         $orderdict['shipping']['street2'] = $shipping->street2 ? CHtml::encode($shipping->street2) : null;
         $orderdict['shipping']['postcode'] = $shipping->postcode ? CHtml::encode($shipping->postcode) : null;
         $orderdict['shipping']['city'] = $shipping->city ? CHtml::encode($shipping->city) : null;
         $orderdict['shipping']['region'] = $shipping->region ? CHtml::encode($shipping->region) : null;
         $orderdict['shipping']['country'] = $shipping->country ? CHtml::encode($shipping->country) : null;
     }
     $orderdict['telephones'] = array();
     foreach ($user->userPhones as $phone) {
         $orderdict['telephones'][] = array("number" => $phone->number, 'can_receive_sms' => $phone->sms_opt_in);
     }
     // Build a list of items
     $orderdict['items'] = array();
     $dataProvider = new CActiveDataProvider('OrderHasProduct', array('criteria' => array('condition' => 'order_id=' . $this->id, 'with' => array('product')), 'pagination' => false));
     if ($user->lastname || $user->firstname) {
         $firstname = $user->firstname ? CHtml::encode($user->firstname) . " " : "";
         $lastname = $user->lastname ? CHtml::encode($user->lastname) : "";
         $orderdict["name"] = $firstname . $lastname;
     }
     $locale = Yii::app()->language . "_CA";
     $orderdict['locale'] = $locale;
     foreach ($dataProvider->getData() as $relationship) {
         $product = $relationship->product;
         $localization = $product->localizationForLanguage($locale, true);
         $itemdict = array("id" => $relationship->product_id, "name" => $localization->name, 'sku' => $product->sku, 'barcode' => $product->barcode, "quantity" => $relationship->quantity, "price_paid" => $relationship->price_paid, "brand" => array());
         $brand_id = $relationship->product->brand_id;
         if ($brand_id) {
             $brand_localization = CategoryLocalization::model()->find("category_id=:category_id AND locale_id=:locale_id", array(":category_id" => $brand_id, ":locale_id" => $user->locale_id));
             $itemdict["brand"]["id"] = $brand_id;
             if ($brand_localization) {
                 $itemdict["brand"]["name"] = $brand_localization->name;
             } else {
                 if (count($product->brand->categoryLocalizations) > 0) {
                     $any_localization = $product->brand->categoryLocalizations[0];
                     $itemdict["brand"]["name"] = $any_localization->name;
                 } else {
                     $itemdict["brand"]["name"] = null;
                 }
             }
         } else {
             $itemdict["brand"]["name"] = null;
             $itemdict["brand"]["id"] = null;
         }
         $orderdict['items'][] = $itemdict;
     }
     $orderdict["confirm_url"] = Yii::app()->createAbsoluteUrl('cart/confirm', array('order' => $this->id));
     $orderdict["cancel_url"] = Yii::app()->createAbsoluteUrl('cart/cancel', array('order' => $this->id));
     $orderdict["paypalconfirm_url"] = Yii::app()->createAbsoluteUrl('cart/confirmpaypal', array('order' => $this->id));
     $orderdict["paypalcancel_url"] = Yii::app()->createAbsoluteUrl('cart/cancelpaypal', array('order' => $this->id));
     return $orderdict;
 }
コード例 #3
0
ファイル: Category.php プロジェクト: KEMSolutions/Boukem1
 /**
  * Returns a localization for the specified category and language.
  * @param string $language The two letter locale id for the language.
  * @param boolean $accept_substitute if true, will return any other localization in lieu if the one asked is unavailable.
  * @return CategoryLocalization the localized category
  */
 public function localizationForLanguage($language, $accept_substitute = false)
 {
     if ($this->_localizationForLanguage !== null) {
         return $this->_localizationForLanguage;
     }
     $criteria = new CDbCriteria();
     $criteria->addCondition('category_id=' . $this->id);
     $criteria->addCondition('locale_id="' . $language . '"');
     $localizationForCategory = CategoryLocalization::model()->find($criteria);
     if ($localizationForCategory === null && $accept_substitute) {
         // No localization exists for the current page localization. User might have added the product from a page in another language than switched language. Just pick the first localization available for the product and call it a day.
         // We need to run on multiple hosts, some supporting PHP 5.3 and others supporting 5.4 and up
         if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
             // 5.4 and up
             // We can't use the new PHP 5.4 syntax directly since 5.3 will throw a syntax error.
             eval('$localizationForCategory = $this->categoryLocalizations[0];');
         } else {
             // Older than 5.4
             $localizationForCategory = array_shift(array_values($this->categoryLocalizations));
         }
     }
     $this->_localizationForLanguage = $localizationForCategory;
     return $localizationForCategory;
 }
コード例 #4
0
 /**
  * Returns the localization model based on the localization's slug key given in the GET variable.
  * If the data model is not found, an HTTP exception of type 404 will be raised.
  * @param str $slug the slug key of the model to be loaded
  * @return CategoryLocalization the loaded model
  * @throws CHttpException
  */
 public function loadLocalizationModelSlug($slug)
 {
     $model = CategoryLocalization::model()->findByAttributes(array('slug' => $slug));
     // Check if model exists
     if ($model === null) {
         throw new CHttpException(404, Yii::t('app', 'La page demandée n\'existe pas.'));
     }
     // If model exists, make sure it's in the same language as the site global variable
     if ($model->locale_id !== Yii::app()->language) {
         // Current slug doesn't exist in the appropriate language. Redirect the user to the appropriate language (if any)
         $appropriate_model = $model->category->localizationForLanguage(Yii::app()->language, $accept_substitute = false);
         if ($appropriate_model) {
             // Redirect to that localized model
             $redict_url = $this->createUrl(Yii::app()->controller->action->id, array('slug' => $appropriate_model->slug, 'language' => $appropriate_model->locale_id));
             $this->redirect($redict_url);
         }
         // This product doesn't have a localization in the current's site language
         throw new CHttpException(404, Yii::t('app', 'La page demandée n\'existe pas.'));
     }
     return $model;
 }