/** * Set fields from a product record * @return InvoiceItem provides fluent interface */ public function copyProductSettings(IProduct $p) { foreach (self::$_productInvoiceFields as $kp => $ki) { $this->{$ki} = call_user_func(array($p, 'get' . ucfirst($kp))); if (strpos($kp, 'is') === 0) { $this->{$ki} = (bool) $this->{$ki}; } } if (!$p->getRebillTimes()) { $this->second_price = null; $this->second_period = null; } $options = $p->getOptions(); if ($options) { $this->option1 = array_shift($options); } if ($options) { $this->option2 = array_shift($options); } if ($options) { $this->option3 = array_shift($options); } $this->setBillingPlanData($p->getBillingPlanData()); return $this; }
/** * Add a product or calculated charge as a line to invoice * @throws Am_Exception_InvalidRequest if items is incompatible * @return Invoice provides fluent interface */ function add(IProduct $product, $qty = 1) { $item = $this->findItem($product->getType(), $product->getProductId()); if (null == $item) { $item = $this->createItem($product); $error = $this->isItemCompatible($item); if (null != $error) { throw new Am_Exception_InputError($error); } $this->_items[] = $item; } $item->add($qty); return $this; }
/** * Add a product or calculated charge as a line to invoice * @throws Am_Exception_InvalidRequest if items is incompatible * @return Invoice provides fluent interface */ function add(IProduct $product, $qty = 1) { $item = $this->findItem($product->getType(), $product->getProductId(), $product->getBillingPlanId()); if (null == $item) { $item = $this->createItem($product); $error = $this->isItemCompatible($item); if (null != $error) { throw new Am_Exception_InputError($error); } $this->addItem($item); } if (!$item->variable_qty) { $qty = $product->getQty(); } // get default qty $item->add($qty); return $this; }