email this wishlist'; } } /*public function onBeforeCheckoutStep($controller, &$go_back, $original_go_back, &$ctrlr) { error_log('foo'); }*/ public function onAfterCheckoutStep($ctrlrName, &$go_back, $original_go_back, &$ctrlr) { // this keeps the checkout process from completing (and hikashop from deleting the cart!) $go_back = true; } public function onBeforeCartUpdate(&$cartClass, &$cart, $product_id, $quantity, $add, $type, $resetCartWhenUpdate, $force, &$do) { // NOTE - db-to-page output is done @ hikashop cart override. $dbOpResult = null; foreach ($_POST as $k => $v) { if (preg_match('/^steiner_product_note_(\d+)$/', $k, $m)) { $cart_product_id = $m[count($m) - 1]; $dbContent = $this->getNote($cart_product_id); if (!empty($v)) { if (!empty($dbContent) && ($dbContent->product_note != $v)) { $dbOpResult = $this->upsertNote($cart_product_id, $v, false); // update } else if (!empty($dbContent) && ($dbContent->product_note == $v)) { continue; } else { $dbOpResult = $this->upsertNote($cart_product_id, $v); // insert } } error_log('database operation result: ' . $dbOpResult); //error_log(print_r($this->getNote($cart_product_id), true)); //error_log('[before] id: ' . $cart_product_id . "\tcontent: $v"); } } } public function onAfterCartUpdate(&$cartClass, &$cart, $product_id, $quantity, $add, $type, $resetCartWhenUpdate, $force, &$do) { $retval = null; foreach ($product_id as $id => $value) { if (!is_array($value) && !$value) { //error_log("$id has been removed"); if ($this->getNote($id)) { $retval = $this->removeNote($id); } } } error_log('after cart update returns: ' . $retval); } private function getNote($cart_product_id) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query ->select($db->quoteName('product_note')) ->from($db->quoteName($this->wishcartTable)) ->where($db->quoteName('cart_product_id') . ' = ' . $db->quote($cart_product_id)); $db->setQuery($query); $retval = $db->loadObjectList(); return (!count($retval)) ? null : $retval[0]; } private function upsertNote($cart_product_id, $content, $insert = true) { $db = JFactory::getDbo(); $query = $db->getQuery(true); if ($insert) { $query ->insert($db->quoteName($this->wishcartTable)) ->columns(array($db->quoteName('cart_product_id'), $db->quoteName('product_note'))) ->values(implode(',', array((int)$cart_product_id, $db->quote($content)))); } else { $fields = array( $db->quoteName('product_note') . ' = ' . $db->quote($content) ); $conditions = array( $db->quoteName('cart_product_id') . ' = ' . (int)$cart_product_id ); $query ->update($db->quoteName($this->wishcartTable)) ->set($fields) ->where($conditions); } $db->setQuery($query); return $db->execute(); } private function removeNote($cart_product_id) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $conditions = array( $db->quoteName('cart_product_id') . ' = ' . (int)$cart_product_id ); $query->delete($db->quoteName($this->wishcartTable))->where($conditions); $db->setQuery($query); return $db->execute(); } }