17 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
18 require_once SQ_FUDGE_PATH.
'/general/text.inc';
19 require_once dirname(__FILE__).
'/../interfaces/buyable/buyable.inc';
46 $this->_ser_attrs = TRUE;
47 parent::__construct($assetid);
78 require_once SQ_PACKAGES_PATH.
'/ecommerce/price/product_price.inc';
94 protected function _getName($short_name=FALSE, $contextid=NULL)
97 if ($contextid === NULL) {
98 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
102 $values = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'name', $this->
type(), Array($this->
id), $contextid);
103 if (empty($values) === TRUE) {
104 return parent::_getName($short_name, $contextid);
106 return $values[$this->id];
127 $price_obj = $this->
attr(
'price_obj');
128 $price_obj->value = $value;
132 if (!parent::setAttrValue($name, $value))
return FALSE;
133 $price_obj = $this->
attr(
'price_obj');
134 if (!parent::setAttrValue(
'price', $price_obj->value)) {
140 return parent::setAttrValue($name, $value);
158 if (!is_null($qty = array_get_index($_POST,
'quantity', NULL))) {
163 }
else if ($qty < 1 || !is_int($qty)) {
168 parent::printFrontend();
184 <form action=
"<?php echo $this->getURL(); ?>" method=
"post">
187 $replacement_array = Array();
197 foreach ($keywords as $keyword => $info) {
198 $replacement_array[$keyword] = $info[
'value'];
200 $product_description = $this->
attr(
'description');
201 echo replace_keywords($product_description, $replacement_array);
224 if ($cart_assetid === FALSE) {
225 trigger_localised_error(
'ECOM0011', E_USER_WARNING);
229 if (!is_numeric($qty = $_POST[
'quantity'])) {
230 trigger_localised_error(
'ECOM0012', E_USER_WARNING);
235 $cart =& $GLOBALS[
'SQ_SYSTEM']->am->getAsset($cart_assetid);
238 if (isset($_SESSION[
'sq_cart_contents'][$this->
id])) {
239 $cart->update($this->
id, (
int)$qty);
241 $cart->add($this->
id, $this->
attr(
'price'), (
int)$qty);
258 $parents = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getParents($this->id,
'ecommerce_cart', FALSE));
260 switch (count($parents)) {
266 return reset($parents);
271 $lineage = array_reverse($GLOBALS[
'SQ_SYSTEM']->am->getLineageFromURL());
274 foreach ($lineage as $lineage_item) {
275 if (FALSE !== ($index = array_search($lineage_item[
'assetid'], $parents))) {
276 return $parents[$index];
311 $keywords = parent::getAssetKeywords($descriptions);
319 if (isset($_SESSION[
'sq_cart_contents'])) {
321 $qty = array_get_index($_SESSION[
'sq_cart_contents'], $this->
id, Array(
'quantity' => 0));
322 if ($qty[
'quantity'] != 0) {
323 $keywords[
'quantity_field'][
'value'] =
'<input type="text" name="update_quantity['.$this->id.
']" size="10" value="'.$qty[
'quantity'].
'" />';
324 $keywords[
'commit_button'][
'value'] =
'<input type="submit" value="Update Quantity" />';
326 $keywords[
'quantity_field'][
'value'] =
'<input type="text" name="quantity" size="10" />';
327 $keywords[
'commit_button'][
'value'] =
'<input type="submit" value="Add to Cart" />';
332 $images = array_keys($GLOBALS[
'SQ_SYSTEM']->am->getChildren($this->id,
'image', FALSE));
333 foreach ($images as $image_assetid) {
334 $keywords[
'image_'.$image_assetid][
'value'] =
'<img src="'.$GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($image_assetid).
'">';
351 $price_obj = $this->
attr(
'price_obj');
352 if (is_null($price_obj->value))
return 0;
353 return $price_obj->value;