예제 #1
0
 public function action_delete()
 {
     if (Input::has('tag_id') && Auth::check() && Session::has('id')) {
         $account = Account::find(Session::get('id'));
         $wishlistitem = WishlistItem::find(Input::get('tag_id'));
         $wishlistitem->delete();
     }
 }
예제 #2
0
    }
    sort($wishlistItemsAddedOrder);
    $wishlistItemsAddedOrder = array_flip($wishlistItemsAddedOrder);
    foreach ($wishlistItems as $wishlistItem) {
        $wishlistItem->added = $wishlistItemsAddedOrder[$wishlistItem->id] + 1;
    }
}
// fetch a single item
if (isset($_GET["item"])) {
    $sql = 'SELECT wishlistitems.id as id, wishlistitems.userID as userID, item, price, groupID, groupName';
    $sql .= ' FROM wishlistitems INNER JOIN wishlistgroups';
    $sql .= ' ON wishlistitems.groupID = wishlistgroups.id';
    $sql .= ' WHERE wishlistitems.userID = "' . $user->id . '"';
    $sql .= ' AND wishlistitems.id = ? LIMIT 1';
    $paramArray = array(trim($_GET["item"]));
    $wishlistItems = WishlistItem::findBySql($sql, $paramArray);
    if (!$wishlistItems) {
        $invalidItem = true;
    } else {
        $wishlistItem = $wishlistItems[0];
    }
}
// fetch a group
if (isset($_GET["group"])) {
    $sql = 'SELECT * FROM wishlistgroups WHERE userID = ? AND id = ? LIMIT 1';
    $paramArray = array($user->id, $_GET["group"]);
    $wishlistGroups = WishlistGroup::findBySql($sql, $paramArray);
    if (!$wishlistGroups) {
        $invalidGroup = true;
    } else {
        $wishlistGroup = $wishlistGroups[0];
예제 #3
0
            <form action="" method="post">
                <?php 
    if (isset($itemError) && isset($_POST["item"])) {
        $itemNameValue = htmlentities($_POST["item"]);
    } else {
        if (isset($wishlistItem) && isset($_GET["item"])) {
            $itemNameValue = htmlentities($wishlistItem->item);
        } else {
            $itemNameValue = "";
        }
    }
    if (isset($itemError) && isset($_POST["price"])) {
        $itemPriceValue = htmlentities($_POST["price"]);
    } else {
        if (isset($wishlistItem) && isset($_GET["item"])) {
            $itemPriceValue = htmlentities(WishlistItem::formatDisplayAmount($wishlistItem->price));
        } else {
            $itemPriceValue = "";
        }
    }
    if (isset($itemError) && isset($_POST["itemGroup"])) {
        $itemGroupValue = htmlentities($_POST["itemGroup"]);
    } else {
        if (isset($wishlistItem) && isset($_GET["item"])) {
            $itemGroupValue = htmlentities($wishlistItem->groupID);
        } else {
            $itemGroupValue = "";
        }
    }
    ?>
예제 #4
0
     $group = intval(trim($_POST["itemGroup"]));
     $itemError = false;
     if (!WishlistItem::isValidItem($item)) {
         $itemError = true;
         $itemNameError = true;
     }
     if (!WishlistItem::isValidAmount($price)) {
         $itemError = true;
         $itemPriceError = true;
     }
     if (!WishlistGroup::isValidGroup($user->id, $group)) {
         $itemError = true;
         $itemGroupError = true;
     }
     if (!$itemError) {
         $newItem = new WishlistItem();
         $newItem->userID = $user->id;
         $newItem->item = $item;
         $newItem->groupID = $group;
         $newItem->price = WishlistItem::formatAmount($price);
         if (isset($wishlistItem)) {
             $newItem->id = $wishlistItem->id;
         }
         $newItem->save();
         header("Location: " . BASE_URL . "planner");
         exit;
     } else {
         $processItemError = true;
     }
 }
 if (isset($processItemError) && $processItemError === true) {
 protected function getEditForm()
 {
     //New dialog box init, so load our initial data
     $strCode = Yii::app()->getRequest()->getParam('code');
     $intRow = Yii::app()->getRequest()->getParam('id');
     $objWishlist = Wishlist::model()->findByAttributes(array('gift_code' => $strCode));
     if (!$objWishlist->Visible) {
         _xls_404();
     }
     $objWishrow = WishlistItem::model()->findByAttributes(array('id' => $intRow, 'registry_id' => $objWishlist->id));
     $arrReturn = array('action' => 'update', 'code' => $objWishlist->gift_code, 'id' => $objWishrow->id, 'qty' => $objWishrow->qty, 'qty_received' => $objWishrow->qty_received, 'priority' => $objWishrow->priority, 'comment' => $objWishrow->comment);
     echo json_encode($arrReturn);
 }
예제 #6
0
 /**
  * Remove all items from the cart
  * @return bool
  */
 public function clearCart()
 {
     if ($this->model->cart_type != CartType::cart) {
         return false;
     }
     unset(Yii::app()->session['checkout.cache']);
     unset(Yii::app()->session[MultiCheckoutForm::$sessionKey]);
     $this->clearCachedShipping();
     foreach ($this->cartItems as $item) {
         if (!is_null($item->wishlist_item)) {
             WishlistItem::model()->updateByPk($item->wishlist_item, array('cart_item_id' => null));
         }
         $item->delete();
     }
     $this->model->fk_promo_id = null;
     $this->model->save();
     $this->model->refresh();
     $this->recalculateAndSave();
     $this->model->refresh();
     return true;
 }
예제 #7
0
                $newWishlistGroup->userID = $user->id;
                $newWishlistGroup->groupName = $groupName;
                if (isset($wishlistGroup)) {
                    $newWishlistGroup->id = $wishlistGroup->id;
                }
                $newWishlistGroup->save();
            }
            header("Location: " . BASE_URL . "planner/?manageGroups");
            exit;
        } else {
            $processGroupError = true;
        }
    }
    if (isset($processGroupError) && $processGroupError === true) {
        $session->setMessage("Error processing group.");
        if (isset($groupExists) && $groupExists === true) {
            $session->setMessage("Group already exists.");
        }
    }
} else {
    if (isset($_POST["deleteGroup"])) {
        // check if the group is empty
        if (WishlistItem::hasItemWithGroup($user->id, $wishlistGroup->id)) {
            $wishlistGroup->delete();
            header("Location: " . BASE_URL . "planner/?manageGroups");
            exit;
        } else {
            $session->setMessage("Error: There are still some items belonging to this group.");
        }
    }
}
예제 #8
0
 public function getDataItems()
 {
     $objItems = new WishlistItem();
     $objItems->registry_id = $this->id;
     return $objItems->editSearch();
 }
예제 #9
0
 /**
  * Update the Quantity of an Item in the cart
  * Then force recalculation of Cart values
  * @param int $intItemId
  * @param int $intQuantity
  * @return string[]|true|void|CartItem
  */
 public function UpdateItemQuantity($objItem, $intQuantity)
 {
     if ($intQuantity <= 0) {
         if ($objItem->wishlist_item > 0) {
             WishlistItem::model()->updateByPk($objItem->wishlist_item, array('cart_item_id' => null));
         }
         $objItem->delete();
         return true;
     }
     if ($intQuantity == $objItem->qty) {
         return;
     }
     if (_xls_get_conf('PRICE_REQUIRE_LOGIN', 0) == 1 && Yii::app()->user->isGuest) {
         return array('errorId' => 'notLoggedIn', 'errorMessage' => Yii::t('cart', 'You must log in before Adding to Cart.'));
     }
     if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD', 0) < Product::InventoryAllowBackorders && $intQuantity > $objItem->qty && $objItem->product->inventoried && $objItem->product->inventory_avail < $intQuantity) {
         if (_xls_get_conf('INVENTORY_DISPLAY', 0) == 0) {
             $availQty = null;
         } else {
             $availQty = $objItem->product->inventory_avail;
         }
         return array('errorId' => 'invalidQuantity', 'errorMessage' => Yii::t('cart', 'Your chosen quantity is not available for ordering. Please come back and order later.'), 'availQty' => $availQty);
     }
     // qty discount?
     $arrtmp = ProductQtyPricing::model()->findAllByAttributes(array('product_id' => $objItem->product_id, 'pricing_level' => 1), array('order' => 'qty ASC'));
     $tmpprice = 0;
     foreach ($arrtmp as $tmp) {
         $tmpprice = $intQuantity >= $tmp->qty ? $tmp->price : $tmpprice;
     }
     $objItem->discount = $tmpprice > 0 ? $objItem->sell_base - $tmpprice : 0;
     $objItem->qty = $intQuantity;
     $objItem->save();
     $this->recalculateAndSave();
     return $objItem;
 }
 /**
  * Product lookup and optional delete, shows inventory numbers
  */
 public function actionProducts()
 {
     if (isset($_POST['pk']) && isset($_POST['name']) && isset($_POST['value'])) {
         if ($_POST['name'] == 'code' && $_POST['value'] == "") {
             $items = CartItem::model()->findAll("product_id=" . $_POST['pk'] . " AND (cart_type=" . CartType::order . " OR cart_type=" . CartType::awaitpayment . ")");
             if ($items) {
                 echo "You cannot delete a product that has been used on an order";
             } else {
                 _dbx("set foreign_key_checks=0;");
                 Product::model()->updateAll(array('image_id' => null), 'id =' . $_POST['pk']);
                 Images::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductRelated::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductRelated::model()->deleteAllByAttributes(array('related_id' => $_POST['pk']));
                 ProductTags::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductQtyPricing::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 ProductText::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 WishlistItem::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 TaskQueue::model()->deleteAllByAttributes(array('product_id' => $_POST['pk']));
                 Product::model()->deleteByPk($_POST['pk']);
                 _dbx("set foreign_key_checks=1;");
                 echo "delete";
             }
         } else {
             echo Yii::t('admin', 'You cannot change a product code here. Delete the code to remove it manually from the Web Store database');
         }
     } else {
         $model = new Product();
         if (isset($_GET['q'])) {
             $model->code = $_GET['q'];
         }
         $this->render("products", array('model' => $model));
     }
 }
예제 #11
0
 /**
  * Ajax receiver function to Add To Cart.
  * This function adds to the cart and then returns a JSON encoded string of
  * the cart contents.  This is typically used by the Cart Display widget.
  * This routine will always send back all the info, but some people may
  * choose to only have some details like the total and item count display.
  */
 public function actionAddToCart()
 {
     if (Yii::app()->request->isAjaxRequest) {
         $intProductId = Yii::app()->getRequest()->getParam('id');
         $strSize = Yii::app()->getRequest()->getParam('product_size');
         $strColor = Yii::app()->getRequest()->getParam('product_color');
         if (isset($strSize) || isset($strColor)) {
             // We passed a size and or color selection, so get the right item
             $objProduct = Product::LoadChildProduct($intProductId, $strSize, $strColor);
             if ($objProduct instanceof Product) {
                 $intProductId = $objProduct->id;
             }
         }
         $intQty = Yii::app()->getRequest()->getParam('qty');
         $intWishId = Yii::app()->getRequest()->getParam('wishid');
         if (!isset($intWishId)) {
             $intWishId = null;
         }
         $intCount = Yii::app()->shoppingcart->item_count;
         $intRowId = Yii::app()->shoppingcart->addProduct($intProductId, $intQty, $intWishId);
         if ($intRowId) {
             if (!is_numeric($intRowId)) {
                 //We got back an error message, not a rowid
                 if (is_array($intRowId)) {
                     $message = $intRowId['errorMessage'];
                 } else {
                     $message = $intRowId;
                 }
                 Yii::log("Error attempting to add product " . $intProductId . ": " . $message, 'error', 'application . ' . __CLASS__ . " . " . __FUNCTION__);
                 $arrReturn['action'] = "alert";
                 $arrReturn['errormsg'] = Yii::t('global', $message);
             } else {
                 Yii::log("Added item " . $intProductId . " as cart_items id " . $intRowId, 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
                 $objCart = Yii::app()->shoppingcart;
                 $objCartItem = CartItem::model()->findByPk($intRowId);
                 //If this was a result of a Wish List add, update that record
                 if (!is_null($intWishId)) {
                     WishlistItem::model()->updateByPk($intWishId, array('cart_item_id' => $intRowId));
                 }
                 $arrReturn['action'] = "success";
                 $arrReturn['totalItemCount'] = Yii::app()->shoppingcart->totalItemCount;
                 if ($intWishId !== null) {
                     $arrReturn['purchaseStatus'] = WishlistItem::model()->findByPk($intWishId)->PurchaseStatus;
                 }
                 $strCartfile = Yii::app()->getRequest()->getParam('cart');
                 $strCartfile = empty($strCartfile) ? "_sidecart" : $strCartfile;
                 $arrReturn['shoppingcart'] = $this->renderPartial('/site/' . $strCartfile, array('objCartItem' => $objCartItem), true);
             }
             $this->renderJSON($arrReturn);
         } else {
             Yii::log("Error attempting to add product " . $intProductId . " for qty " . $intQty, 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         }
     }
 }