コード例 #1
0
ファイル: Wishlist.php プロジェクト: uiDeveloper116/webstore
 public static function LoadFirstCode()
 {
     $objLists = Wishlist::LoadUserLists();
     if (count($objLists) == 0) {
         return null;
     }
     return $objLists[0]->gift_code;
 }
コード例 #2
0
 public function getLists()
 {
     $retValue = Wishlist::LoadUserLists();
     if (!is_null($retValue)) {
         return CHtml::listData($retValue, 'gift_code', 'registry_name');
     } else {
         return null;
     }
 }
コード例 #3
0
<div id="wish-lists" class="col-sm-12 clickbar" onclick="$('#WishList').slideToggle('fast');"><?php 
echo Yii::t('global', 'Wish Lists');
?>
</div>

<div class="containers" id="WishList" style="display:hidden;">
	<?php 
if (!Yii::app()->user->isGuest) {
    foreach (Wishlist::LoadUserLists() as $list) {
        ?>
            <a href="<?php 
        echo Yii::app()->createUrl('wishlist/view', array('code' => $list->gift_code));
        ?>
">
	            <strong><?php 
        echo $list->registry_name;
        ?>
</strong></a><br />
		<?php 
    }
    ?>
		</br>
        <a id="wish-lists-view" href="<?php 
    echo Yii::app()->createUrl('/wishlist');
    ?>
"><strong><?php 
    echo Yii::t('global', 'View all my wish lists');
    ?>
</strong></a> <br />
        <a id="wish-lists-view-create" href="<?php 
    echo Yii::app()->createUrl('wishlist/create');
コード例 #4
0
 public function actionAdd()
 {
     if (Yii::app()->user->isGuest) {
         echo Yii::t('wishlist', "You must be logged in to add to a wish list. Please sign in and try again.");
         return;
     }
     if (Yii::app()->request->isAjaxRequest) {
         $model = new WishlistAddForm();
         // collect user input data
         if (isset($_POST)) {
             if (isset($_POST['WishlistAddForm'])) {
                 $model->attributes = $_POST['WishlistAddForm'];
             } else {
                 $model->attributes = $_POST;
             }
             if ($model->validate()) {
                 $intProductId = $model->id;
                 $intQty = $model->qty;
                 $strSize = $model->size;
                 $strColor = $model->color;
                 $objProduct = Product::model()->findByPk($intProductId);
                 if (!$objProduct instanceof Product) {
                     return;
                 }
                 if ($objProduct->IsMaster) {
                     if (isset($strSize) || isset($strColor)) {
                         $objProduct = Product::LoadChildProduct($intProductId, $strSize, $strColor);
                         if (!$objProduct instanceof Product) {
                             echo Yii::t('wishlist', "Please choose options before selecting {button}", array('{button}' => Yii::t('product', 'Add to Wish List')));
                             return;
                         }
                         $model->id = $intProductId = $objProduct->id;
                     } else {
                         echo Yii::t('wishlist', "Please choose options before selecting {button}", array('{button}' => Yii::t('product', 'Add to Wish List')));
                         return;
                     }
                 }
                 //If we don't have a wish list, create one and add. If we only have one wish list, add it. If we have more than
                 //one, we need to prompt for which one to add
                 $objWishLists = Wishlist::LoadUserLists();
                 switch (count($objWishLists)) {
                     case 0:
                         //We don't have a wish list, so let's create one
                         $objWishList = new Wishlist();
                         $objWishList->registry_name = Yii::t('wishlist', 'My Wish List');
                         $objWishList->visibility = Wishlist::PERSONALLIST;
                         $objWishList->after_purchase = Wishlist::LEAVEINLIST;
                         $objWishList->customer_id = Yii::app()->user->id;
                         $objWishList->gift_code = md5(uniqid());
                         $objWishList->ship_option = 0;
                         if (!$objWishList->save()) {
                             Yii::log("Error creating Wish List " . print_r($objWishList->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                         }
                         $objWishLists = array();
                         $objWishLists[0] = $objWishList;
                         // No break so we drop to the next set of instructions
                     // No break so we drop to the next set of instructions
                     case 1:
                         $objWishList = $objWishLists[0];
                         $objWishItem = new WishlistItem();
                         $objWishItem->registry_id = $objWishList->id;
                         $objWishItem->product_id = $intProductId;
                         $objWishItem->qty = $intQty;
                         if ($objWishItem->save()) {
                             echo Yii::t('wishlist', 'Item has been added to your Wish List.');
                         } else {
                             Yii::log("error saving wishlist item " . print_r($objWishItem->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                             echo Yii::t('wishlist', 'An error occurred adding this item to your Wish List.');
                         }
                         break;
                     default:
                         $Wishlistadd = new WishlistAddForm();
                         if (isset($_POST['WishlistAddForm'])) {
                             $Wishlistadd->attributes = $_POST['WishlistAddForm'];
                         }
                         if ($Wishlistadd->validate()) {
                             $objWishList = Wishlist::model()->findByAttributes(array('gift_code' => $Wishlistadd->gift_code));
                             $objWishItem = new WishlistItem();
                             $objWishItem->registry_id = $objWishList->id;
                             $objWishItem->product_id = $intProductId;
                             $objWishItem->qty = $Wishlistadd->qty;
                             if ($objWishItem->save()) {
                                 echo Yii::t('global', 'Item has been added to your Wish List.');
                             } else {
                                 Yii::log("error saving wishlist item " . print_r($objWishItem->getErrors(), true), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
                                 echo Yii::t('global', 'An error occurred adding this item to your Wish List.');
                             }
                         } else {
                             echo "multiple";
                         }
                         break;
                 }
             } else {
                 echo print_r($model->getErrors(), true);
             }
         } else {
             echo "Error missing POST";
         }
     } else {
         echo "Error not AJAX";
     }
 }