本文整理汇总了PHP中ShoppingCart::setQuantity方法的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart::setQuantity方法的具体用法?PHP ShoppingCart::setQuantity怎么用?PHP ShoppingCart::setQuantity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShoppingCart
的用法示例。
在下文中一共展示了ShoppingCart::setQuantity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setquantityitem
/**
* Sets the exact passed quantity.
* Note: If no ?quantity=x is specified in URL, then quantity will be set to 1.
*@return Mixed - if the request is AJAX, it returns JSON - CartResponse::ReturnCartData(); If it is not AJAX it redirects back to requesting page.
*/
public function setquantityitem($request)
{
$this->cart->setQuantity($this->buyable(), $this->quantity(), $this->parameters());
return $this->cart->setMessageAndReturn();
}
示例2: executeAddToCart
public function executeAddToCart()
{
if ($this->getRequest()->isXmlHttpRequest()) {
sfProjectConfiguration::getActive()->loadHelpers('Partial');
$this->user = $this->getUser()->getRaykuUser();
$item_id = $this->getRequestParameter('it');
$quantity = 1;
$this->item = ItemPeer::retrieveByPK($item_id);
if (!$this->item->getIsActive()) {
$this->item = NULL;
}
if ($this->item) {
if ($this->item->getQuantity() > $quantity) {
$this->user = $this->getUser()->getRaykuUser();
$c = new Criteria();
$c->add(ShoppingCartPeer::IS_ACTIVE, true);
$c->add(ShoppingCartPeer::USER_ID, $this->user->getId());
$c->addDescendingOrderByColumn(ShoppingCartPeer::CREATED_AT);
$this->cart_items = ShoppingCartPeer::doSelect($c);
$tot_price = 0;
foreach ($this->cart_items as $cart_item) {
$tot_price = $tot_price + $cart_item->getTotalPrice() + $cart_item->getTotalShippingCharge();
}
$tot_price = $tot_price + $this->item->getPricePerUnit() * $quantity + $this->item->getShippingChargePerUnit() * $quantity;
if ($tot_price <= $this->user->getPoints()) {
$shopping_cart = new ShoppingCart();
$shopping_cart->setItemId($item_id);
$shopping_cart->setUserId($this->user->getId());
$shopping_cart->setQuantity($quantity);
$shopping_cart->setTotalPrice($this->item->getPricePerUnit() * $quantity);
$shopping_cart->setTotalShippingCharge($this->item->getShippingChargePerUnit() * $quantity);
$shopping_cart->setIsActive(true);
$shopping_cart->save();
$quantity_avail = $this->item->getQuantity();
$quantity_avail = $quantity_avail - $quantity;
$this->item->setQuantity($quantity_avail);
$this->item->save();
return $this->renderText(get_component('shop', 'cartBox'));
} else {
return $this->renderText('<span style="line-height:26px"><center>Sorry! Not enough RP!</center></span>' . get_component('shop', 'cartBox'));
}
} else {
return $this->renderText('Sorry! Item out of stock' . get_component('shop', 'cartBox'));
}
} else {
return $this->renderText('Sorry! No item is there' . get_component('shop', 'cartBox'));
}
}
}