本文整理匯總了PHP中yii\base\Component::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP Component::add方法的具體用法?PHP Component::add怎麽用?PHP Component::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類yii\base\Component
的用法示例。
在下文中一共展示了Component::add方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: update
/**
* Updates the position in the shopping cart
* If the position was previously added, then it will be updated in shopping cart,
* if the position was not previously in the cart, it will be added there.
* If the count of less than 1, the position will be deleted.
*
* @param IECartPosition $position
* @param int $quantity
*/
public function update(CartPosition $position, $quantity)
{
if (!$position instanceof Component) {
throw new InvalidArgumentException('invalid argument 1, product must implement CComponent interface');
}
$key = $position->getId();
$position->attachBehavior("CartPosition", new CartPositionBehaviour());
$position->setRefresh($this->refresh);
$position->setQuantity($quantity);
if ($position->getQuantity() < 1) {
$this->remove($key);
} else {
parent::add($key, $position);
}
$this->applyDiscounts();
$this->onUpdatePoistion(new Event($this));
$this->saveState();
}