/** * downloads a file * * @return void */ function downloadFile() { $app = JFactory::getApplication(); $user = JFactory::getUser(); $productfile_id = $app->input->getInt('id', 0); //$productfile_id = intval( JRequest::getvar( 'id', '', 'request', 'int' ) ); $product_id = $app->input->getInt('product_id', 0); $link = 'index.php?option=com_citruscart&view=products&task=edit&id=' . $product_id; Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance('ProductDownload', 'CitruscartHelper'); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_citruscart' . DS . 'tables'); $productfile = JTable::getInstance('ProductFiles', 'CitruscartTable'); $productfile->load($productfile_id); if (empty($productfile->productfile_id)) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_INVALID FILE'); $this->setRedirect($link, $this->message, $this->messagetype); return false; } // log and download Citruscart::load('CitruscartFile', 'library.file'); // geting the ProductDownloadId to updated for which productdownload_max is greater then 0 $productToDownload = $helper->getProductDownloadInfo($productfile->productfile_id, $user->id); if ($downloadFile = CitruscartFile::download($productfile)) { $link = JRoute::_($link, false); $this->setRedirect($link); } }
/** * Run function after saving */ function save($src = '', $orderingFilter = '', $ignore = '') { if ($return = parent::save($src, $orderingFilter, $ignore)) { Citruscart::load("CitruscartHelperProduct", 'helpers.product'); $helper = CitruscartHelperBase::getInstance('product'); $helper->doProductQuantitiesReconciliation($this->product_id, '0'); } return $return; }
/** * Run function when saving * @see Citruscart/admin/tables/CitruscartTable#save() */ function save($src = '', $orderingFilter = '', $ignore = '') { if ($return = parent::save($src, $orderingFilter, $ignore)) { $pa = JTable::getInstance('ProductAttributes', 'CitruscartTable'); $pa->load($this->productattribute_id); Citruscart::load("CitruscartHelperProduct", 'helpers.product'); $helper = CitruscartHelperBase::getInstance('product'); $helper->doProductQuantitiesReconciliation($pa->product_id); } return $return; }
/** * * @param unknown_type $updateNulls * @return unknown_type */ function store($updateNulls = false) { if ($return = parent::store($updateNulls)) { if ($this->notify_customer == '1') { Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); $model = Citruscart::getClass("CitruscartModelSubscriptions", "models.subscriptions"); $model->setId($this->subscription_id); $subscription = $model->getItem(); $helper->sendEmailNotices($subscription, 'subscription'); } } return $return; }
/** * * @param unknown_type $updateNulls * @return unknown_type */ function store($updateNulls = false) { if ($return = parent::store($updateNulls)) { if ($this->notify_customer == '1') { Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); $model = Citruscart::getClass("CitruscartModelOrders", "models.orders"); $model->setId($this->order_id); // this isn't necessary because you specify the requested PK id as a getItem() argument $order = $model->getItem($this->order_id, true); $helper->sendEmailNotices($order, 'order'); } } return $return; }
function display($cachable = false, $urlparams = false) { $uri = JURI::getInstance(); $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType()); $view->set('hidemenu', false); $view->set('_doTask', true); $view->setLayout('default'); if (version_compare(JVERSION, '1.6.0', 'ge')) { $url = "index.php?option=com_users&view=user&task=user.edit"; } else { $url = "index.php?option=com_user&view=user&task=edit"; } Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Ambra'); if ($helper->isInstalled()) { $url = "index.php?option=com_ambra&view=users&task=edit&return=" . base64_encode($uri->__toString()); } $view->assign('url_profile', $url); parent::display($cachable, $urlparams); }
protected function _buildQueryFields(&$query) { Citruscart::load('CitruscartHelperUser', 'helpers.user'); $date = JFactory::getDate()->toSql(); $filter_product = $this->getState('filter_product'); $user = CitruscartHelperBase::getInstance('user'); if (strlen($filter_product)) { $default_group = $user->getUserGroup(JFactory::getUser()->id, (int) $filter_product); } else { $default_group = Citruscart::getInstance()->get('default_user_group', '1'); } $fields = array(); $fields[] = " p_from.product_name as product_name_from "; $fields[] = " p_from.product_sku as product_sku_from "; $fields[] = " p_from.product_model as product_model_from "; $fields[] = "\n (\n SELECT\n prices.product_price\n FROM\n #__citruscart_productprices AS prices\n WHERE\n prices.product_id = tbl.product_id_from\n AND prices.group_id = '{$default_group}'\n AND prices.product_price_startdate <= '{$date}'\n AND (prices.product_price_enddate >= '{$date}' OR prices.product_price_enddate = '0000-00-00 00:00:00' )\n ORDER BY prices.price_quantity_start ASC\n LIMIT 1\n )\n AS product_price_from "; $fields[] = " p_to.product_name as product_name_to "; $fields[] = " p_to.product_sku as product_sku_to "; $fields[] = " p_to.product_model as product_model_to "; $fields[] = "\n (\n SELECT\n prices.product_price\n FROM\n #__citruscart_productprices AS prices\n WHERE\n prices.product_id = tbl.product_id_to\n AND prices.group_id = '{$default_group}'\n AND prices.product_price_startdate <= '{$date}'\n AND (prices.product_price_enddate >= '{$date}' OR prices.product_price_enddate = '0000-00-00 00:00:00' )\n ORDER BY prices.price_quantity_start ASC\n LIMIT 1\n )\n AS product_price_to "; $query->select($this->getState('select', 'tbl.*')); $query->select($fields); }
<?php /*------------------------------------------------------------------------ # com_citruscart # ------------------------------------------------------------------------ # author Citruscart Team - Citruscart http://www.citruscart.com # copyright Copyright (C) 2014 Citruscart.com All Rights Reserved. # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # Websites: http://citruscart.com # Technical Support: Forum - http://citruscart.com/forum/index.html -------------------------------------------------------------------------*/ /** ensure this file is being included by a parent file */ defined('_JEXEC') or die('Restricted access'); Citruscart::load("CitruscartHelperBase", 'helpers._base'); $currency_helper = CitruscartHelperBase::getInstance('Currency'); // Add CSS $document->addStyleSheet(JURI::root(true) . '/modules/mod_citruscart_my_orders/tmpl/mod_citruscart_my_orders.css'); $user = JFactory::getUser(); if ($orders && $user->id) { $count = 0; foreach (@$orders as $order) { ?> <div class="mod_citruscart_my_orders_item"> <?php if ($params->get('display_date')) { ?> <span class="mod_citruscart_my_orders_item_date"><a href="<?php echo $order->link; ?> "><?php echo JHTML::_('date', $order->created_date, Citruscart::getInstance()->get('date_format'));
/** * Migrate the images * * param int $product_id * param string $images */ private function _migrateImages($product_id, $images) { Citruscart::load('CitruscartImage', 'library.image'); foreach ($images->children() as $image) { $check = false; $multiple = false; $image = (string) $image; if (JURI::isInternal($image)) { $internal = true; $int_image = JPATH_SITE . DIRECTORY_SEPARATOR . $image; if (is_dir($int_image)) { $check = JFolder::exists($int_image); $multiple = true; } else { $check = JFile::exists($int_image); } // Now check the extracted images path if (!$check) { $dir = $this->_temp_dir . DIRECTORY_SEPARATOR . 'images' . DS; if (is_dir($dir . $image)) { $check = JFolder::exists($dir . $image); $multiple = true; } else { $check = JFile::exists($dir . $image); } if ($check) { $image = $dir . $image; } } else { $image = $int_image; } } else { $internal = false; $check = $this->url_exists($image); } // Add a single image if (!$multiple) { $images_to_copy = array($image); } else { // Fetch the images from the folder and add them $images_to_copy = Citruscart::getClass("CitruscartHelperProduct", 'helpers.product')->getGalleryImages($image); foreach ($images_to_copy as &$i) { $i = $image . DIRECTORY_SEPARATOR . $i; } } if ($check) { foreach ($images_to_copy as $image_to_copy) { if ($internal) { $img = new CitruscartImage($image_to_copy); } else { $tmp_path = JFactory::getApplication()->getCfg('tmp_path'); $file = fopen($image_to_copy, 'r'); $file_content = stream_get_contents($file); fclose($file); $file = fopen($tmp_path . DIRECTORY_SEPARATOR . $image_to_copy, 'w'); fwrite($file, $file_content); fclose($file); $img = new CitruscartImage($tmp_path . DIRECTORY_SEPARATOR . $image_to_copy); } Citruscart::load('CitruscartTableProducts', 'tables.products'); $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($product_id); $path = $product->getImagePath(); $type = $img->getExtension(); $img->load(); $img->setDirectory($path); // Save full Image $img->save($path . $img->getPhysicalName()); // Save Thumb Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); $imgHelper->resizeImage($img, 'product'); } } } }
private function _migrateImages($prefix = 'jos_', $vm_prefix = 'vm_', &$results, $internal = true) { $p = $prefix . $vm_prefix; // Fetch the VM full image if ($internal) { $db = JFactory::getDBO(); } else { $db = $this->_verifyDB(); } $query = "SELECT product_id as id, product_full_image as image FROM {$p}product"; $db->setQuery($query); $products = $db->loadAssocList(); Citruscart::load('CitruscartImage', 'library.image'); if ($internal) { $vm_image_path = JPATH_SITE . "/components/com_virtuemart/shop_image/product/"; } else { $state = $this->_getState(); $url = $state->external_site_url; $vm_image_path = $url . "/components/com_virtuemart/shop_image/product/"; } $n = count($results); $results[$n]->title = 'Product Images'; $results[$n]->query = 'Copy Product Images & Resize'; $results[$n]->error = ''; $results[$n]->affectedRows = 0; foreach ($products as $result) { $check = false; if ($internal) { $check = JFile::exists($vm_image_path . $result['image']); } else { $check = $this->url_exists($vm_image_path) && $result['image']; } if ($check) { if ($internal) { $img = new CitruscartImage($vm_image_path . $result['image']); } else { $tmp_path = JFactory::getApplication()->getCfg('tmp_path'); $file = fopen($vm_image_path . $result['image'], 'r'); $file_content = stream_get_contents($file); fclose($file); $file = fopen($tmp_path . DIRECTORY_SEPARATOR . $result['image'], 'w'); fwrite($file, $file_content); fclose($file); $img = new CitruscartImage($tmp_path . DS . $result['image']); } Citruscart::load('CitruscartTableProducts', 'tables.products'); $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($result['id']); $path = $product->getImagePath(); $type = $img->getExtension(); $img->load(); $name = $img->getPhysicalName(); // Save full Image if (!$img->save($path . $name)) { $results[$n]->error .= '::Could not Save Product Image- From: ' . $vm_image_path . $result['image'] . ' To: ' . $path . $result['image']; } $img->setDirectory($path); // Save Thumb Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); if (!$imgHelper->resizeImage($img, 'product')) { $results[$n]->error .= '::Could not Save Product Thumb'; } // Save correct image naming $product->product_full_image = $name; $product->save(); $results[$n]->affectedRows++; } } $n++; // CATEGORIES // Fetch the VM full image $query = "SELECT category_id as id, category_full_image as image FROM {$p}category"; $db->setQuery($query); $products = $db->loadAssocList(); Citruscart::load('CitruscartImage', 'library.image'); if ($internal) { $vm_image_path = JPATH_SITE . "/components/com_virtuemart/shop_image/category/"; } else { $state = $this->_getState(); $url = $state->external_site_url; $vm_image_path = $url . "/components/com_virtuemart/shop_image/category/"; } $results[$n]->title = 'Category Images'; $results[$n]->query = 'Copy Category Images & Resize'; $results[$n]->error = ''; $results[$n]->affectedRows = 0; foreach ($products as $result) { $check = false; if ($internal) { $check = JFile::exists($vm_image_path . $result['image']); } else { $check = $this->url_exists($vm_image_path) && $result['image']; } if ($check) { if ($internal) { $img = new CitruscartImage($vm_image_path . $result['image']); } else { $tmp_path = JFactory::getApplication()->getCfg('tmp_path'); $file = fopen($vm_image_path . $result['image'], 'r'); $file_content = stream_get_contents($file); fclose($file); $file = fopen($tmp_path . DS . $result['image'], 'w'); fwrite($file, $file_content); fclose($file); $img = new CitruscartImage($tmp_path . DS . $result['image']); } $img->load(); $path = Citruscart::getPath('categories_images') . DS; $name = $img->getPhysicalName(); // Save full Image if (!$img->save($path . $name)) { $results[$n]->error .= '::Could not Save Category Image - From: ' . $vm_image_path . $result['image'] . ' To: ' . $path . $result['image']; } $img->setDirectory($path); // Save Thumb Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); if (!$imgHelper->resizeImage($img, 'category')) { $results[$n]->error .= '::Could not Save Category Thumb'; } // Save correct image name Citruscart::load('CitruscartTableCategories', 'tables.categories'); $category = JTable::getInstance('Categories', 'CitruscartTable'); $category->load($result['id']); $category->category_full_image = $name; $category->save(); $results[$n]->affectedRows++; } } }
/*------------------------------------------------------------------------ # com_citruscart # ------------------------------------------------------------------------ # author Citruscart Team - Citruscart http://www.citruscart.com # copyright Copyright (C) 2014 Citruscart.com All Rights Reserved. # @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL # Websites: http://citruscart.com # Technical Support: Forum - http://citruscart.com/forum/index.html -------------------------------------------------------------------------*/ /** ensure this file is being included by a parent file */ defined('_JEXEC') or die('Restricted access'); Citruscart::load('CitruscartHelperBase', 'helpers._base'); Citruscart::load('CitruscartSelect', 'library.select'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $helper = CitruscartHelperBase::getInstance(); $url = JRoute::_('index.php?option=com_citruscart&view=currency&task=set&return=' . base64_encode(JURI::getInstance()->__toString()), false); // Check the currently selected currency $selected = CitruscartHelperBase::getSessionVariable('currency_id', Citruscart::getInstance()->get('default_currencyid', 1)); ?> <div id="mod_citruscart_currency"> <form action="<?php echo $url; ?> " method="post" name="currencySwitch"> <?php // echo JText::_('COM_CITRUSCART_SELECT_CURRENCY').': '; ?> <?php $attribs = array('onChange' => 'document.currencySwitch.submit(); ');
/** * Loads a row from the database and binds the fields to the object properties * If $load_eav is true, binds also the eav fields linked to this entity * * @access public * @param mixed Optional primary key. If not specifed, the value of current key is used * @param bool reset the object values? * @param bool load the eav values for this object * * @return boolean True if successful */ function load($oid = null, $reset = true, $load_eav = true) { $eavs = array(); /* Get the application */ $app = JFactory::getApplication(); $editable_by = $app->isAdmin() ? 1 : 2; if ($app->isAdmin()) { $view = $app->input->get('view', ''); //$view = JRequest::get('view', '' ); if ($view == 'pos') { // display all for POS $editable_by = array(1, 2); } } if (!is_array($oid)) { // load by primary key if not array $keyName = $this->getKeyName(); $oid = array($keyName => $oid); } if (empty($oid)) { // if empty, use the value of the current key $keyName = $this->getKeyName(); $oid = $this->{$keyName}; if (empty($oid)) { // if still empty, fail $this->setError(JText::_('COM_CITRUSCART_CANNOT_LOAD_WITH_EMPTY_KEY')); return false; } } // allow $oid to be an array of key=>values to use when loading $oid = (array) $oid; $this->_linked_table_key = isset($this->_linked_table_key) ? $this->_linked_table_key : (isset($oid[$this->_linked_table_key_name]) ? $oid[$this->_linked_table_key_name] : ''); if (!empty($reset)) { $this->reset(); } $db = $this->getDBO(); // initialize the query $query = new DSCQuery(); $query->select('*'); $query->from($this->getTableName()); if ($load_eav) { Citruscart::load("CitruscartHelperBase", 'helpers._base'); $eav_helper = CitruscartHelperBase::getInstance('Eav'); $k = $this->_tbl_key; $id = $this->{$k}; // Get the custom fields for this entities Citruscart::load('CitruscartHelperEav', 'helpers.eav'); $eavs = CitruscartHelperEav::getAttributes($this->get('_suffix'), $id, true, $editable_by); // Is this a mirrored table (see decription at the beginning of this file) if (strlen($this->_linked_table) && $this->_linked_table_key) { // Copy the custom field value to this table $mirrored_eavs = $eav_helper->getAttributes($this->_linked_table, $this->_linked_table_key, true, $editable_by); $eavs = array_merge($eavs, $mirrored_eavs); } } foreach ($oid as $key => $value) { // Check that $key is field in table if (!in_array($key, array_keys($this->getProperties()))) { // Check if it is a eav field if ($load_eav) { // loop through until the key is found or the eav are finished $found = false; $i = 0; while (!$found && $i < count($eavs)) { // Does the key exists? if ($key == $eavs[$i]->eavattribute_alias) { $found = true; } else { $i++; } } // Was the key found? if (!$found) { // IF not return an error $this->setError(get_class($this) . ' does not have the field ' . $key); return false; } // key was found -> add this EAV field $value_tbl_name = 'value_' . $eavs[$i]->eavattribute_alias; // for some reason MySQL makes spaces around '-' charachter // (which is often charachter in aliases) that's why we replace it with '_' $value_tbl_name = str_replace("-", "_", $value_tbl_name); // Join the table based on the type of the value $table_type = $eav_helper->getType($eavs[$i]->eavattribute_alias); // Join the tables $query->join('LEFT', '#__citruscart_eavvalues' . $table_type . ' AS ' . $value_tbl_name . ' ON ( ' . $value_tbl_name . '.eavattribute_id = ' . $eavs[$i]->eavattribute_id . ' AND ' . $value_tbl_name . '.eaventity_id = ' . $this->_tbl_key . ' )'); // Filter using '=' $query->where($value_tbl_name . ".eavvalue_value = '" . $value . "'"); // else let the store() method worry over this } else { $this->setError(get_class($this) . ' does not have the field ' . $key); return false; } } else { // add the key=>value pair to the query $value = $db->q($db->escape(trim(strtolower($value)))); $query->where($key . ' = ' . $value); } } $db->setQuery((string) $query); if ($result = $db->loadAssoc()) { $result = $this->bind($result); if ($result) { // Only now load the eav, in necessary // Check if it is a eav field if ($load_eav) { $k = $this->_tbl_key; $id = $this->{$k}; // Get the custom fields for this entities Citruscart::load('CitruscartHelperEav', 'helpers.eav'); $eavs = CitruscartHelperEav::getAttributes($this->get('_suffix'), $id, false, $editable_by); // Is this a mirrored table (see decription at the beginning of this file) if (strlen($this->_linked_table) && $this->_linked_table_key) { // Copy the custom field value to this table $mirrored_eavs = $eav_helper->getAttributes($this->_linked_table, $this->_linked_table_key); $eavs = array_merge($eavs, $mirrored_eavs); } if (count($eavs)) { foreach ($eavs as $eav) { $key = $eav->eavattribute_alias; $value = $eav_helper->getAttributeValue($eav, $this->get('_suffix'), $id); $this->{$key} = $value; } } } $app->triggerEvent('onLoad' . $this->get('_suffix'), array(&$this)); } return $result; } else { $this->setError($db->getErrorMsg()); return false; } }
/** * Batch resize of thumbs * @author Skullbock */ function recreateThumbs() { $app = JFactory::getApplication(); $per_step = 100; $from_id = $app->input->getInt('from_id', 0); $to = $from_id + $per_step; Citruscart::load('CitruscartHelperManufacturer', 'helpers.manufacturer'); Citruscart::load('CitruscartImage', 'library.image'); $width = Citruscart::getInstance()->get('manufacturer_img_width', '0'); $height = Citruscart::getInstance()->get('manufacturer_img_height', '0'); $model = $this->getModel('Manufacturers', 'CitruscartModel'); $model->setState('limistart', $from_id); $model->setState('limit', $to); $row = $model->getTable(); $count = $model->getTotal(); $manufacturers = $model->getList(); $i = 0; $last_id = $from_id; foreach ($manufacturers as $p) { $i++; $image = $p->manufacturer_full_image; if ($image != '') { $img = new CitruscartImage($image, 'manufacturer'); $img->setDirectory(Citruscart::getPath('manufacturers_images')); // Thumb Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); $imgHelper->resizeImage($img, 'manufacturer'); } $last_id = $p->manufacturer_id; } if ($i < $count) { $redirect = "index.php?option=com_citruscart&controller=manufacturers&task=recreateThumbs&from_id=" . ($last_id + 1); } else { $redirect = "index.php?option=com_citruscart&view=config"; } $redirect = JRoute::_($redirect, false); $this->setRedirect($redirect, JText::_('COM_CITRUSCART_DONE'), 'notice'); return; }
public function getItem($pk = null, $refresh = false, $emptyState = true) { if (empty($this->_item)) { Citruscart::load('CitruscartHelperBase', 'helpers._base'); JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $amigos = CitruscartHelperBase::getInstance('Amigos'); $currency_helper = CitruscartHelperBase::getInstance('Currency'); if ($item = parent::getItem($pk, $refresh, $emptyState)) { // get the orderinfo $item->orderinfo = JTable::getInstance('OrderInfo', 'CitruscartTable'); $item->orderinfo->load(array('order_id' => $item->order_id)); //retrieve the order's items $model = JModelLegacy::getInstance('OrderItems', 'CitruscartModel'); $model->setState('filter_orderid', $item->order_id); $model->setState('order', 'tbl.orderitem_name'); $model->setState('direction', 'ASC'); $item->orderitems = $model->getList($refresh); foreach ($item->orderitems as $orderitem) { $model = JModelLegacy::getInstance('OrderItemAttributes', 'CitruscartModel'); $model->setState('filter_orderitemid', $orderitem->orderitem_id); $attributes = $model->getList(); $attributes_names = array(); $attributes_codes = array(); foreach ($attributes as $attribute) { // store a csv of the attrib names $attributes_names[] = JText::_($attribute->orderitemattribute_name); if ($attribute->orderitemattribute_code) { $attributes_codes[] = JText::_($attribute->orderitemattribute_code); } } $orderitem->attributes_names = implode(', ', $attributes_names); $orderitem->attributes_codes = implode(', ', $attributes_codes); // adjust the price $orderitem->orderitem_price = $orderitem->orderitem_price + floatval($orderitem->orderitem_attributes_price); } //retrieve the order's history $model = JModelLegacy::getInstance('OrderHistory', 'CitruscartModel'); $model->setState('filter_orderid', $item->order_id); $model->setState('order', 'tbl.date_added'); $model->setState('direction', 'ASC'); $item->orderhistory = $model->getList($refresh); $item->link_view = 'index.php?option=com_citruscart&view=orders&task=view&id=' . $item->order_id; //retrieve the order's payments $model = JModelLegacy::getInstance('OrderPayments', 'CitruscartModel'); $model->setState('filter_orderid', $item->order_id); $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'ASC'); $item->orderpayments = $model->getList($refresh); //retrieve the order's shippings $model = JModelLegacy::getInstance('OrderShippings', 'CitruscartModel'); $model->setState('filter_orderid', $item->order_id); $model->setState('order', 'tbl.created_date'); $model->setState('direction', 'ASC'); $item->ordershippings = $model->getList($refresh); //retrieve the order's taxclasses $model = JModelLegacy::getInstance('OrderTaxClasses', 'CitruscartModel'); $model->setState('filter_orderid', $item->order_id); $model->setState('order', 'tbl.ordertaxclass_description'); $model->setState('direction', 'ASC'); $item->ordertaxclasses = $model->getList($refresh); // retrieve the order's taxrates $model = JModelLegacy::getInstance('OrderTaxRates', 'CitruscartModel'); $model->setState('filter_orderid', $item->order_id); $model->setState('order', 'tbl.ordertaxclass_id, tbl.ordertaxrate_level'); $item->ordertaxrates = $model->getList($refresh); // retrieve the order's currency // this loads the currency, using the FK is it is the same of the // currency used in the order, or the DSCParameter currency of the order otherwise $order_currency = new DSCParameter($item->order_currency); $order_currency = $order_currency->toArray(); //$model = JModelLegacy::getInstance( 'Currencies', 'CitruscartModel' ); //$model->setId($item->currency_id); $item->currency = $currency_helper->load($item->currency_id); // if the order currency is not the same as it was during the order if (!empty($item->currency) && !empty($order_currency['currency_code']) && $item->currency->currency_code != $order_currency['currency_code']) { // overwrite it with the original one foreach ($order_currency as $k => $v) { $item->currency->{$k} = $v; } } // has a commission? if ($amigos->isInstalled()) { $item->commissions = $amigos->getCommissions($item->order_id); } } $this->_item = $item; } JFactory::getApplication()->triggerEvent('onPrepare' . $this->getTable()->get('_suffix'), array(&$this->_item)); return $this->_item; }
/** * Checks that a password and password2 match * return unknown_type */ function checkPassword2() { $input = JFactory::getApplication()->input; Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance(); $response = array(); $response['msg'] = ''; $response['error'] = ''; // get elements from post $elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $input->getString('elements'))); // convert elements to array that can be binded $values = CitruscartHelperBase::elementsToArray($elements); $password = $values['password']; $password2 = $values['password2']; if (empty($password)) { $response['msg'] = $helper->validationMessage("COM_CITRUSCART_PASSWORD_CANNOT_BE_EMPTY", 'fail'); $response['error'] = '1'; echo json_encode($response); return; } if (empty($password2)) { $response['msg'] = $helper->validationMessage("COM_CITRUSCART_PASSWORD_VERIFY_CANNOT_BE_EMPTY", 'fail'); $response['error'] = '1'; echo json_encode($response); return; } $message = ""; if ($password != $password2) { $message .= $helper->validationMessage('COM_CITRUSCART_PASSWORD_DO_NOT_MATCH', 'fail'); } else { // no error $message .= $helper->validationMessage('COM_CITRUSCART_PASSWORD_VALID', 'success'); } $response['msg'] = $message; $response['error'] = '1'; echo json_encode($response); return; }
/** * Upload via ajax through Uploadify * It's here because when the swf connects to the admin side, it would need to login. */ function uploadifyImage() { $app = JFactory::getApplication(); JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); $product_id = $app->input->getInt('product_id', 0); if ($product_id) { Citruscart::load('CitruscartImage', 'library.image'); $upload = new CitruscartImage(); // handle upload creates upload object properties $upload->handleUpload('Filedata'); // then save image to appropriate folder $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($product_id); $path = $product->getImagePath(); $upload->setDirectory($path); // Do the real upload! $success = $upload->upload(); Citruscart::load('CitruscartHelperImage', 'helpers.image'); $imgHelper = CitruscartHelperBase::getInstance('Image', 'CitruscartHelper'); if (!$imgHelper->resizeImage($upload, 'product')) { $success = false; } if ($success) { // save as default? if (empty($product->product_full_image)) { $product->product_full_image = $upload->getPhysicalName(); $product->save(); } echo JText::_('COM_CITRUSCART_IMAGE_UPLOADED_CORRECTLY'); } else { echo 'Error: ' . $upload->getError(); } } }
/** * * Adds a product relationship */ function addRelationship() { $app = JFactory::getApplication(); $response = array(); $response['msg'] = ''; $response['error'] = ''; Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance(); // get elements from post $elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $app->input->getString('elements'))); // convert elements to array that can be binded Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance(); $submitted_values = $helper->elementsToArray($elements); $product_id = $submitted_values['new_relationship_productid_from']; $product_to = $submitted_values['new_relationship_productid_to']; $relation_type = $submitted_values['new_relationship_type']; // verify product id exists $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($product_to, true, false); if (empty($product->product_id) || $product_id == $product_to) { $response['error'] = '1'; $response['msg'] = $helper->generateMessage(JText::_('COM_CITRUSCART_INVALID_PRODUCT')); $response['msg'] .= $this->getRelationshipsHtml(null, $product_id); echo json_encode($response); return; } // and that relationship doesn't already exist $producthelper = CitruscartHelperBase::getInstance('Product'); if ($producthelper->relationshipExists($product_id, $product_to, $relation_type)) { $response['error'] = '1'; $response['msg'] = $helper->generateMessage(JText::_('COM_CITRUSCART_RELATIONSHIP_ALREADY_EXISTS')); $response['msg'] .= $this->getRelationshipsHtml(null, $product_id); echo json_encode($response); return; } switch ($relation_type) { case "child": case "required_by": // for these two, we must flip to/from switch ($relation_type) { case "child": $rtype = 'parent'; break; case "required_by": $rtype = 'requires'; break; } // check existence of required_by relationship if ($producthelper->relationshipExists($product_to, $product_id, $rtype)) { $response['error'] = '1'; $response['msg'] = $helper->generateMessage(JText::_('COM_CITRUSCART_RELATIONSHIP_ALREADY_EXISTS')); $response['msg'] .= $this->getRelationshipsHtml(null, $product_id); echo json_encode($response); $app->close(); } // then add it, need to flip to/from $table = JTable::getInstance('ProductRelations', 'CitruscartTable'); $table->product_id_from = $product_to; $table->product_id_to = $product_id; $table->relation_type = $rtype; $table->save(); break; default: $table = JTable::getInstance('ProductRelations', 'CitruscartTable'); $table->product_id_from = $product_id; $table->product_id_to = $product_to; $table->relation_type = $relation_type; $table->save(); break; } JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = JModelLegacy::getInstance('ProductRelations', 'CitruscartModel'); $model->clearCache(); $response['error'] = '0'; $response['msg'] = $this->getRelationshipsHtml(null, $product_id); echo json_encode($response); // Close the application. $app->close(); }
/** * Returns a formatted path for the category * @param $id * @param $format * @return unknown_type */ public static function getPathName($id, $format = 'flat', $linkSelf = false) { $name = ''; if (empty($id)) { return $name; } if (isset($this) && is_a($this, 'CitruscartHelperCategory')) { $helper = $this; } else { $helper = CitruscartHelperBase::getInstance('Category'); } if (empty($helper->categories[$id])) { JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $helper->categories[$id] = JTable::getInstance('Categories', 'CitruscartTable'); $helper->categories[$id]->load($id); } $item = $helper->categories[$id]; if (empty($item->category_id)) { return $name; } $path = $item->getPath(); switch ($format) { case "array": $name = array(); foreach ($path as $cat) { $include_root = Citruscart::getInstance()->get('include_root_pathway', false); if (!$cat->isroot || $include_root) { $pathway_object = new JObject(); $pathway_object->name = $cat->category_name; $slug = $cat->category_alias ? ":{$cat->category_alias}" : ""; $link = "index.php?option=com_citruscart&view=products&filter_category=" . $cat->category_id . $slug; $pathway_object->link = $link; $pathway_object->id = $cat->category_id; $name[] = $pathway_object; } } // add the item $pathway_object = new JObject(); $pathway_object->name = $item->category_name; $slug = $item->category_alias ? ":{$item->category_alias}" : ""; $link = "index.php?option=com_citruscart&view=products&filter_category=" . $item->category_id . $slug; $pathway_object->link = $link; $pathway_object->id = $item->category_id; $name[] = $pathway_object; break; case "bullet": foreach ($path as $cat) { if (!$cat->isroot) { $name .= '• '; $name .= JText::_($cat->category_name); $name .= "<br/>"; } } $name .= '• '; $name .= JText::_($item->category_name); break; case 'links': // get the root category JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $root = JTable::getInstance('Categories', 'CitruscartTable')->getRoot(); $root_itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($root->category_id, true); $include_root = Citruscart::getInstance()->get('include_root_pathway', false); if ($include_root) { $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $root->category_id . "&Itemid=" . $root_itemid, false); $name .= " <a href='{$link}'>" . JText::_('COM_CITRUSCART_ALL_CATEGORIES') . '</a> '; } foreach ($path as $cat) { if (!$cat->isroot) { if (!($itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($cat->category_id, true))) { $itemid = $root_itemid; } $slug = $cat->category_alias ? ":{$cat->category_alias}" : ""; $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $cat->category_id . $slug . "&Itemid=" . $itemid, false); if (!empty($name)) { $name .= " > "; } $name .= " <a href='{$link}'>" . JText::_($cat->category_name) . '</a> '; } } if (!empty($name)) { $name .= " > "; } if ($linkSelf) { if (!($itemid = Citruscart::getClass("CitruscartHelperRoute", 'helpers.route')->category($item->category_id, true))) { $itemid = $root_itemid; } $slug = $item->category_alias ? ":{$item->category_alias}" : ""; $link = JRoute::_("index.php?option=com_citruscart&view=products&filter_category=" . $item->category_id . $slug . "&Itemid=" . $itemid, false); $name .= " <a href='{$link}'>" . JText::_($item->category_name) . '</a> '; } else { $name .= JText::_($item->category_name); } break; default: foreach ($path as $cat) { if (!$cat->isroot) { $name .= " / "; $name .= JText::_($cat->category_name); } } $name .= " / "; $name .= JText::_($item->category_name); break; } return $name; }
/** * Verifies the fields in a submitted form. * Then adds the item to the users cart * * @return unknown_type */ function addChildrenToCart() { $input = JFactory::getApplication()->input; JSession::checkToken() or jexit('Invalid Token'); $product_id = $input->getInt('product_id'); $quantities = $input->get('quantities', array(0), 'request', 'array'); $filter_category = $input->getInt('filter_category'); Citruscart::load("CitruscartHelperRoute", 'helpers.route'); $router = new CitruscartHelperRoute(); if (!($itemid = $router->product($product_id, $filter_category, true))) { $itemid = $router->category(1, true); } // set the default redirect URL $redirect = "index.php?option=com_citruscart&view=products&task=view&id=" . $product_id . "&filter_category=" . $filter_category . "&Itemid=" . $itemid; $redirect = JRoute::_($redirect, false); Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance(); if (!Citruscart::getInstance()->get('shop_enabled', '1')) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_SHOP_DISABLED'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } $items = array(); // this will collect the items to add to the cart // convert elements to array that can be binded $values = $input->getArray($_POST); $attributes_csv = ''; $user = JFactory::getUser(); $cart_id = $user->id; $id_type = "user_id"; if (empty($user->id)) { $session = JFactory::getSession(); $cart_id = $session->getId(); $id_type = "session"; } Citruscart::load('CitruscartHelperCarts', 'helpers.carts'); $carthelper = new CitruscartHelperCarts(); $cart_recurs = $carthelper->hasRecurringItem($cart_id, $id_type); // TODO get the children // loop thru each child, // get the list JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = JModelLegacy::getInstance('ProductRelations', 'CitruscartModel'); $model->setState('filter_product', $product_id); $model->setState('filter_relation', 'parent'); if ($children = $model->getList()) { foreach ($children as $child) { $product_qty = $quantities[$child->product_id_to]; // Integrity checks on quantity being added if ($product_qty < 0) { $product_qty = '1'; } // using a helper file to determine the product's information related to inventory $availableQuantity = Citruscart::getClass('CitruscartHelperProduct', 'helpers.product')->getAvailableQuantity($child->product_id_to, $attributes_csv); if ($availableQuantity->product_check_inventory && $product_qty > $availableQuantity->quantity) { $this->messagetype = 'notice'; $this->message = JText::_(JText::sprintf("COM_CITRUSCART_NOT_AVAILABLE_QUANTITY", $availableQuantity->product_name, $product_qty)); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } // do the item's charges recur? does the cart already have a subscription in it? if so, fail with notice $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load(array('product_id' => $child->product_id_to)); // if product notforsale, fail if ($product->product_notforsale) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_PRODUCT_NOT_FOR_SALE'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } if ($product->product_recurs && $cart_recurs) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_CART_ALREADY_RECURS'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } if ($product->product_recurs) { $product_qty = '1'; } // create cart object out of item properties $item = new JObject(); $item->user_id = JFactory::getUser()->id; $item->product_id = (int) $child->product_id_to; $item->product_qty = (int) $product_qty; $item->product_attributes = $attributes_csv; $item->vendor_id = '0'; // vendors only in enterprise version // does the user/cart match all dependencies? $canAddToCart = $carthelper->canAddItem($item, $cart_id, $id_type); if (!$canAddToCart) { $this->messagetype = 'notice'; $this->message = JText::_('COM_CITRUSCART_CANNOT_ADD_ITEM_TO_CART') . " - " . $carthelper->getError(); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } // no matter what, fire this validation plugin event for plugins that extend the checkout workflow $results = array(); $results = JFactory::getApplication()->triggerEvent("onBeforeAddToCart", array($item, $values)); for ($i = 0; $i < count($results); $i++) { $result = $results[$i]; if (!empty($result->error)) { $this->messagetype = 'notice'; $this->message = $result->message; $this->setRedirect($redirect, $this->message, $this->messagetype); return; } } // if here, add to cart $items[] = $item; } } if (!empty($items)) { Citruscart::load('CitruscartHelperCarts', 'helpers.carts'); foreach ($items as $item) { // add the item to the cart $cart_helper = new CitruscartHelperCarts(); $cartitem = $cart_helper->addItem($item); // fire plugin event JFactory::getApplication()->triggerEvent('onAfterAddToCart', array($cartitem, $values)); } $this->messagetype = 'message'; $this->message = JText::_('COM_CITRUSCART_ITEMS_ADDED_TO_YOUR_CART'); } // After login, session_id is changed by Joomla, so store this for reference $session = JFactory::getSession(); $session->set('old_sessionid', $session->getId()); // get the 'success' redirect url // TODO Enable redirect via base64_encoded urls? switch (Citruscart::getInstance()->get('addtocartaction', 'redirect')) { case "redirect": $returnUrl = base64_encode($redirect); $itemid = $router->findItemid(array('view' => 'checkout')); $redirect = JRoute::_("index.php?option=com_citruscart&view=carts&Itemid=" . $itemid, false); if (strpos($redirect, '?') === false) { $redirect .= "?return=" . $returnUrl; } else { $redirect .= "&return=" . $returnUrl; } break; case "0": case "none": break; case "lightbox": default: // TODO Figure out how to get the lightbox to display even after a redirect break; } $this->setRedirect($redirect, $this->message, $this->messagetype); return; }
/** * Returning total amount value * * @return unknown_type */ function totalAmountDue() { $input = JFactory::getApplication()->input; $elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $input->getString('elements'))); // convert elements to array that can be binded Citruscart::load('CitruscartHelperBase', 'helpers._base'); $helper = CitruscartHelperBase::getInstance(); $values = $helper->elementsToArray($elements); $response = array(); $response['msg'] = ''; $response['error'] = ''; // get the order object so we can populate it $order = $this->_order; // a TableOrders object (see constructor) // bind what you can from the post $order->bind($values); // set the currency $order->currency_id = Citruscart::getInstance()->get('default_currencyid', '1'); // USD is default if no currency selected // get the items and add them to the order Citruscart::load("CitruscartHelperBase", 'helpers._base'); //$cart_helper = CitruscartHelperBase::getInstance( 'Carts' ); //$items = $cart_helper->getProductsInfo(); //foreach ($items as $item) //{ //$order->addItem( $item ); //} // get all coupons and add them to the order if (!empty($values['coupons'])) { foreach ($values['coupons'] as $coupon_id) { $coupon = JTable::getInstance('Coupons', 'CitruscartTable'); $coupon->load(array('coupon_id' => $coupon_id)); $order->addCoupon($coupon); } } // get the order totals $order->calculateTotals(); // now get the summary $html = $this->getTotalAmountDue(); $response = array(); $response['msg'] = $html; $response['error'] = ''; // encode and echo (need to echo to send back to browser) echo json_encode($response); }
/** * Formats and converts a number according to currency rules * As of v0.5.0 is a wrapper * * @param unknown_type $amount * @param unknown_type $currency * @return unknown_type */ public static function currency($amount, $currency = '', $options = '') { $currency_selected = CitruscartHelperBase::getSessionVariable('currency_id', Citruscart::getInstance()->get('default_currencyid', 1)); $currency = $currency_selected; $currency_helper = CitruscartHelperBase::getInstance('Currency'); $amount = $currency_helper->_($amount, $currency, $options); return $amount; }
/** * Converts an amount from one currency to another * * @param float $amount * @param str $currencyFrom * @param str $currencyTo * @return boolean */ function convert($currencyFrom, $currencyTo = 'USD', $amount = '1', $refresh = false) { static $rates; if (!is_array($rates)) { $rates = array(); } if (empty($rates[$currencyFrom]) || !is_array($rates[$currencyFrom])) { $rates[$currencyFrom] = array(); } if (empty($rates[$currencyFrom][$currencyTo])) { if (isset($this) && is_a($this, 'CitruscartHelperCurrency')) { $helper = $this; } else { $helper = CitruscartHelperBase::getInstance('Currency'); } // get the exchange rate, and let the getexchange rate method handle refreshing the cache $rates[$currencyFrom][$currencyTo] = $helper->getExchangeRate($currencyFrom, $currencyTo, $refresh); } $exchange_rate = $rates[$currencyFrom][$currencyTo]; // convert the amount $return = $amount * $exchange_rate; return $return; }
-------------------------------------------------------------------------*/ /** ensure this file is being included by a parent file */ defined('_JEXEC') or die('Restricted access'); JHtml::_('stylesheet', 'media/citruscart/css/pos.css'); JHtml::_('stylesheet', 'media/citruscart/css/citruscart.css'); $row = @$this->product; $values = @$this->values; $changed_attr = isset($values['changed_attr']) ? $values['changed_attr'] : -1; $changed_pao = -1; if ($changed_attr > -1) { $changed_pao = $values['attribute_' . $changed_attr]; } Citruscart::load('CitruscartHelperBase', 'helpers._base'); $js_strings = array('COM_CITRUSCART_UPDATING_ATTRIBUTES'); CitruscartHelperBase::addJsTranslationStrings($js_strings); $helper_product = CitruscartHelperBase::getInstance('Product'); // Selected attribute options (for child attributes) $selected_opts = !empty($this->selected_opts) ? json_decode($this->selected_opts) : 0; if (!count($selected_opts)) { $selected_opts = 0; } $attributes = CitruscartHelperProduct::getAttributes($row->product_id, $selected_opts); $default = CitruscartHelperProduct::getDefaultAttributeOptions($attributes); // First view of the page: select the first value in the list if (!$selected_opts) { $selected_opts = $default; $selected_opts[] = 0; } foreach ($attributes as $attribute) { ?> <div class="pao" id='productattributeoption_<?php
/** * (non-PHPdoc) * @see CitruscartController::display() */ function view($cachable = false, $urlparams = '') { $input = JFactory::getApplication()->input; $model = $this->getModel($this->get('suffix')); $items_model = $this->getModel('wishlistitems'); $products_model = $this->getModel('products'); Citruscart::load("CitruscartHelperRoute", 'helpers.route'); $router = CitruscartHelperBase::getInstance('Route'); // clear unecessary session ids $items_model->clearSessionIds(); $user = JFactory::getUser(); $items_model->mergeUserItems($user->id); $this->_setModelState(); $wishlist_id = $input->getInt('id'); $item = $model->getItem($wishlist_id); $redirect = JRoute::_("index.php?option=com_citruscart&view=wishlists&Itemid=" . $router->findItemid(array('view' => 'wishlists')), false); if ($item == null) { // this item does not exist $this->messagetype = 'error'; $this->message = JText::_('COM_CITRUSCART_WISHLIST_DOEST_EXIST'); $this->setRedirect($redirect, $this->message, $this->messagetype); return; } // TODO Is this a public or the user's wishlist? if no, fail. $items_model->setState('filter_wishlist', $wishlist_id); if ($items = $items_model->getList(true)) { } $checkout_itemid = $router->findItemid(array('view' => 'checkout')); if (empty($checkout_itemid)) { $checkout_itemid = $input->getInt('Itemid'); } if ($return = $input->getBase64('return')) { $return = base64_decode($return); if (!JURI::isInternal($return)) { $return = ''; } } $redirect = $return ? $return : JRoute::_("index.php?option=com_citruscart&view=products"); $view = $this->getView($this->get('suffix'), JFactory::getDocument()->getType()); $view->assign('return', $redirect); $view->assign('checkout_itemid', $checkout_itemid); $view->assign('row', $item); $view->assign('items', $items); $view->set('no_items', true); $view->set('hidemenu', true); $view->set('_doTask', true); $view->setModel($model, true); $view->setModel($items_model); $view->setModel($products_model); $view->setLayout('view'); $input->set('layout', 'view'); parent::display($cachable, $urlparams); }
/** * Set basic properties for the item, whether in a list or a singleton * * @param unknown_type $item * @param unknown_type $key * @param unknown_type $refresh */ protected function prepareItem(&$item, $key = 0, $refresh = false) { $input = JFactory::getApplication()->input; $getEav = $this->_getEav; $options = $this->_getEavOptions; $eavStates = count($this->getEavState()->getProperties()); if (!empty($getEav) || $eavStates > 0) { $app = JFactory::getApplication(); $editable_by = $app->isAdmin() ? 1 : 2; $view = $input->get('view', ''); if ($app->isAdmin() && $view == 'pos') { $editable_by = array(1, 2); } Citruscart::load('CitruscartModelEavAttributes', 'models.eavattributes'); Citruscart::load("CitruscartHelperBase", 'helpers._base'); $eav_helper = CitruscartHelperBase::getInstance('Eav'); $entity = $this->getTable()->get('_suffix'); $tbl_key = $this->getTable()->getKeyName(); $entity_id = $item->{$tbl_key}; // add the custom fields as properties $eavs = $eav_helper->getAttributes($entity, $entity_id, false, $editable_by); // Mirrored table? if (!count($eavs) && strlen($this->getTable()->getLinkedTable())) { $entity = $this->getTable()->getLinkedTable(); $entity_id = $item->{$this->getTable()->getLinkedTableKeyName()}; $eavs = $eav_helper->getAttributes($entity, $entity_id, false, $editable_by); } foreach ($eavs as $eav) { $key = $eav->eavattribute_alias; $add = true; // Include Mode: Fetch only these fields if (array_key_exists('include', $options)) { foreach ($options['include'] as $k) { if ($key != $k) { $add = false; } } } else { // Exclude Mode: Fetch everything except these fields if (array_key_exists('exclude', $options)) { foreach ($options['exclude'] as $k) { if ($key == $k) { $add = false; } } } // Default Mode: Fetch Everything } if ($add) { $value = $eav_helper->getAttributeValue($eav, $this->getTable()->get('_suffix'), $item->{$tbl_key}, false, true); // Do NOT override properties if (!property_exists($item, $key)) { $item->{$key} = $value; } } } } parent::prepareItem($item, $key, $refresh); }
/** * Will check if there are any items in the cart for which shipping is required * * @return Boolean */ public function getShippingIsEnabled() { $model = JModelLegacy::getInstance('Carts', 'CitruscartModel'); $session = JFactory::getSession(); $user = JFactory::getUser(); $model->setState('filter_user', $user->id); if (empty($user->id)) { $model->setState('filter_session', $session->getId()); } $list = $model->getList(); // If no item in the list, return false if (empty($list)) { return false; } Citruscart::load("CitruscartHelperBase", 'helpers._base'); $product_helper = CitruscartHelperBase::getInstance('Product'); foreach ($list as $item) { echo $shipping = $product_helper->isShippingEnabled($item->product_id); if ($shipping) { return true; } } return false; }
/** * Briefly, this method "converts" the items in the cart to a order Object * * @return array of OrderItem */ public static function getProductsInfo() { Citruscart::load("CitruscartHelperCarts", 'helpers.carts'); $carthelper = new CitruscartHelperCarts(); Citruscart::load("CitruscartHelperProduct", 'helpers.product'); $product_helper = CitruscartHelperBase::getInstance('Product'); JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_citruscart/models'); JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $model = JModelLegacy::getInstance('Carts', 'CitruscartModel'); $session = JFactory::getSession(); $session_id = $session->getId(); $user = JFactory::getUser(); $model->setState('filter_user', $user->id); if (empty($user->id)) { $model->setState('filter_session', $session_id); } Citruscart::load("CitruscartHelperBase", 'helpers._base'); $user_helper = CitruscartHelperBase::getInstance('User'); $filter_group = $user_helper->getUserGroup($user->id); $model->setState('filter_group', $filter_group); $cartitems = $model->getList(); $productitems = array(); foreach ($cartitems as $cartitem) { unset($productModel); $productModel = JModelLegacy::getInstance('Products', 'CitruscartModel'); $filter_group = $user_helper->getUserGroup($user->id, $cartitem->product_id); $productModel->setState('filter_group', $filter_group); $productModel->setId($cartitem->product_id); if ($productItem = $productModel->getItem(false)) { $productItem->price = $productItem->product_price = isset($cartitem->product_price_override->override) ? !$cartitem->product_price_override->override : "" ? $cartitem->product_price : $productItem->price; //we are not overriding the price if its a recurring && price if (!$productItem->product_recurs && isset($cartitem->product_price_override->override) ? $cartitem->product_price_override->override : "") { // at this point, ->product_price holds the default price for the product, // but the user may qualify for a discount based on volume or date, so let's get that price override // TODO Shouldn't we remove this? Is it necessary? $cartitem has already done this in the carts model! $productItem->product_price_override = $product_helper->getPrice($productItem->product_id, $cartitem->product_qty, $filter_group, JFactory::getDate()->toSql()); if (!empty($productItem->product_price_override)) { $productItem->product_price = $productItem->product_price_override->product_price; } } if ($productItem->product_check_inventory) { // using a helper file,To determine the product's information related to inventory $availableQuantity = $product_helper->getAvailableQuantity($productItem->product_id, $cartitem->product_attributes); if ($availableQuantity->product_check_inventory && $cartitem->product_qty > $availableQuantity->quantity && $availableQuantity->quantity >= 1) { JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_CITRUSCART_CART_QUANTITY_ADJUSTED", $productItem->product_name, $cartitem->product_qty, $availableQuantity->quantity)); $cartitem->product_qty = $availableQuantity->quantity; } // removing the product from the cart if it's not available if ($availableQuantity->quantity == 0) { if (empty($cartitem->user_id)) { $carthelper->removeCartItem($session_id, $cartitem->user_id, $cartitem->product_id); } else { $carthelper->removeCartItem($cartitem->session_id, $cartitem->user_id, $cartitem->product_id); } JFactory::getApplication()->enqueueMessage(JText::sprintf("COM_CITRUSCART_NOT_AVAILABLE") . " " . $productItem->product_name); continue; } } // TODO Push this into the orders object->addItem() method? $orderItem = JTable::getInstance('OrderItems', 'CitruscartTable'); $orderItem->cart_id = $cartitem->cart_id; $orderItem->product_id = $productItem->product_id; $orderItem->orderitem_sku = $cartitem->product_sku; $orderItem->orderitem_name = $productItem->product_name; $orderItem->orderitem_quantity = $cartitem->product_qty; $orderItem->orderitem_price = $cartitem->product_price - $cartitem->orderitem_attributes_price; $orderItem->orderitem_attributes = $cartitem->product_attributes; $orderItem->orderitem_attribute_names = $cartitem->attributes_names; $orderItem->orderitem_attributes_price = $cartitem->orderitem_attributes_price; $orderItem->orderitem_attributes_weight = $cartitem->orderitem_attributes_weight; $orderItem->orderitem_weight = $cartitem->product_weight; $orderItem->orderitem_final_price = ($orderItem->orderitem_price + $orderItem->orderitem_attributes_price) * $orderItem->orderitem_quantity; $orderItem->orderitem_recurs = $productItem->product_recurs; if ($productItem->product_recurs) { $orderItem->recurring_price = $productItem->recurring_price; $orderItem->recurring_payments = $productItem->recurring_payments; $orderItem->recurring_period_interval = $productItem->recurring_period_interval; $orderItem->recurring_period_unit = $productItem->recurring_period_unit; $orderItem->recurring_trial = $productItem->recurring_trial; $orderItem->recurring_trial_period_interval = $productItem->recurring_trial_period_interval; $orderItem->recurring_trial_period_unit = $productItem->recurring_trial_period_unit; $orderItem->recurring_trial_price = $productItem->recurring_trial_price; } $results = JFactory::getApplication()->triggerEvent("onGetAdditionalOrderitemKeyValues", array($cartitem)); foreach ($results as $result) { foreach ($result as $key => $value) { $orderItem->set($key, $value); } } //adding plugin event, this is useful for editing the item before it is added for checkout from the cart. makes support for variable pricing JFactory::getApplication()->triggerEvent("onAddOrderitemFromCart", array($orderItem, $cartitem)); // TODO When do attributes for selected item get set during admin-side order creation? array_push($productitems, $orderItem); } } return $productitems; }
function sendAskedQuestion() { $input = JFactory::getApplication()->input; $config = Citruscart::getInstance(); $post = $input->getArray($_POST); $valid = true; $this->messagetype = 'message'; $this->message = ''; $add_link = ''; $json = array(); if (empty($post['sender_name']) && $valid) { $valid = false; $this->message = JText::_('COM_CITRUSCART_NAME_FIELD_IS_REQUIRED'); $this->messagetype = 'notice'; $json['error']['sender_name'] = JText::_('COM_CITRUSCART_NAME_FIELD_IS_REQUIRED'); } jimport('joomla.mail.helper'); if (!$json && !JMailHelper::isEmailAddress($post['sender_mail']) && $valid) { $valid = false; $this->message = JText::_('COM_CITRUSCART_PLEASE_ENTER_A_CORRECT_EMAIL_ADDRESS'); $this->messagetype = 'notice'; $json['error']['sender_mail'] = JText::_('COM_CITRUSCART_PLEASE_ENTER_A_CORRECT_EMAIL_ADDRESS'); $add_link .= "&sender_name={$post['sender_name']}"; $add_link .= !empty($post['sender_message']) ? "&sender_message={$post['sender_message']}" : ''; } if (!$json && empty($post['sender_message']) && $valid) { $valid = false; $this->message = JText::_('COM_CITRUSCART_MESSAGE_FIELD_IS_REQUIRED'); $this->messagetype = 'notice'; // $json['error']['message'] = JText::_('COM_CITRUSCART_MESSAGE_FIELD_IS_REQUIRED'); $add_link .= "&sender_name={$post['sender_name']}&sender_mail={$post['sender_mail']}"; } //captcha checking $captcha = true; if ($config->get('ask_question_showcaptcha', '1') == 1 && $valid) { $privatekey = "6LcAcbwSAAAAANZOTZWYzYWRULBU_S--368ld2Fb"; $captcha = false; if ($_POST["recaptcha_response_field"]) { Citruscart::load('CitruscartRecaptcha', 'library.recaptcha'); $recaptcha = new CitruscartRecaptcha(); $resp = $recaptcha->recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $post['recaptcha_challenge_field'], $post['recaptcha_response_field']); if ($resp->is_valid) { $captcha = true; } } } if (!$json && !$captcha) { $valid = false; $this->message = JText::_('COM_CITRUSCART_INCORRECT_CAPTCHA'); $json['error']['captcha'] = JText::_('COM_CITRUSCART_INCORRECT_CAPTCHA'); $this->messagetype = 'notice'; $add_link .= "&sender_name={$post['sender_name']}&sender_mail={$post['sender_mail']}&sender_message={$post['sender_message']}"; } if ($valid) { $mainframe = JFactory::getApplication(); $sendObject = new JObject(); $sendObject->mailfrom = $post['sender_mail']; $sendObject->namefrom = $post['sender_name']; $sendObject->mailto = $config->get('emails_defaultemail', $mainframe->getCfg('mailfrom')); $sendObject->body = $post['sender_message']; //get product info JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = JModelLegacy::getInstance('Products', 'CitruscartModel'); $model->setId($post['product_id']); $sendObject->item = $model->getItem(); Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); if ($send = $helper->sendEmailToAskQuestionOnProduct($sendObject)) { $this->message = JText::_('COM_CITRUSCART_MESSAGE_SUCCESSFULLY_SENT'); } else { $this->message = JText::_('COM_CITRUSCART_ERROR_IN_SENDING_MESSAGE'); $this->messagetype = 'notice'; } if (Citruscart::getInstance()->get('ask_question_modal', '1')) { $url = "index.php?option=com_citruscart&view=products&task=askquestion&id={$post['product_id']}&tmpl=component&return=" . $post['return'] . $add_link . "&success=1"; $redirect = JRoute::_($url); } else { $redirect = JRoute::_(base64_decode($post['return'])); } } else { $url = "index.php?option=com_citruscart&view=products&task=askquestion&id={$post['product_id']}&tmpl=component&return=" . $post['return'] . $add_link; $redirect = JRoute::_($url); } $this->setRedirect($redirect, $this->message, $this->messagetype); }
/** * * Get Avatar based on the installed community component * @param int $id - userid * @return object */ function getAvatar($id) { $avatar = ''; $found = false; Citruscart::load('CitruscartHelperAmbra', 'helpers.ambra'); $helper_ambra = CitruscartHelperBase::getInstance('Ambra'); //check if ambra installed if ($helper_ambra->isInstalled() && !$found) { if (!class_exists('Ambra')) { JLoader::register("Ambra", JPATH_ADMINISTRATOR . "/components/com_ambra/defines.php"); } //Get Ambra Avatar if ($image = Ambra::getClass("AmbraHelperUser", 'helpers.user')->getAvatar($id)) { $link = JRoute::_(JURI::root() . 'index.php?option=com_ambra&view=users&id=' . $id, false); $avatar .= "<a href='{$link}' target='_blank'>"; $avatar .= "<img src='{$image}' style='max-width:80px; border:1px solid #ccccce;' />"; $avatar .= "</a>"; } $found = true; } //check if jomsocial installed if (DSC::getApp()->isComponentInstalled('com_community') && !$found) { //Get JomSocial Avatar $database = JFactory::getDBO(); $query = "\r\n\t\t\tSELECT\r\n\t\t\t\t*\r\n\t\t\tFROM\r\n\t\t\t\t#__community_users\r\n\t\t\tWHERE\r\n\t\t\t\t`userid` = '" . $id . "'\r\n\t\t\t"; $database->setQuery($query); $result = $database->loadObject(); if (isset($result->thumb)) { $image = JURI::root() . $result->thumb; } $link = JRoute::_(JURI::root() . 'index.php?option=com_community&view=profile&userid=' . $id, false); $avatar .= "<a href='{$link}' target='_blank'>"; $avatar .= "<img src='{$image}' style='max-width:80px; border:1px solid #ccccce;' />"; $avatar .= "</a>"; $found = true; } //check if community builder is installed if (DSC::getApp()->isComponentInstalled('com_comprofiler') && !$found) { //Get JomSocial Avatar $database = JFactory::getDBO(); $query = "\r\n\t\t\tSELECT\r\n\t\t\t\t*\r\n\t\t\tFROM\r\n\t\t\t\t#__comprofiler\r\n\t\t\tWHERE\r\n\t\t\t\t`id` = '" . $id . "'\r\n\t\t\t"; $database->setQuery($query); $result = $database->loadObject(); if (isset($result->avatar)) { $image = JURI::root() . 'images/comprofiler/' . $result->avatar; } else { $image = JRoute::_(JURI::root() . 'components/com_comprofiler/plugin/templates/default/images/avatar/nophoto_n.png'); } $link = JRoute::_(JURI::root() . 'index.php?option=com_comprofiler&userid=' . $id, false); $avatar .= "<a href='{$link}' target='_blank'>"; $avatar .= "<img src='{$image}' style='max-width:80px; border:1px solid #ccccce;' />"; $avatar .= "</a>"; $found = true; } return $avatar; }
/** * * Enter description here ... * @param $data * @return unknown_type */ public function _processSubscriptionPayment($data) { // if we're here, a successful payment has been made. // the normal notice that requires action. // create a subscription_id if no subscr_id record exists // set expiration dates // add a sub history entry, email the user? $errors = array(); // Check that custom (orderpayment_id) is present, we need it for payment amount verification if (empty($data['custom'])) { $this->setError(JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID')); return false; } // load the orderpayment record and set some values JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $orderpayment = JTable::getInstance('OrderPayments', 'CitruscartTable'); $orderpayment->load($data['custom']); if (empty($data['custom']) || empty($orderpayment->orderpayment_id)) { $this->setError(JText::_('PAYPAL MESSAGE INVALID ORDERPAYMENTID')); return false; } $orderpayment->transaction_details = $data['transaction_details']; $orderpayment->transaction_id = $data['txn_id']; $orderpayment->transaction_status = $data['payment_status']; if (!$orderpayment->save()) { $errors[] = $orderpayment->getError(); } JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $order = JTable::getInstance('Orders', 'CitruscartTable'); $order->load($data['item_number']); $items = $order->getItems(); // Update orderitem_status $order_item = $order->getRecurringItem(); $orderitem = JTable::getInstance('OrderItems', 'CitruscartTable'); $orderitem->orderitem_id = $order_item->orderitem_id; $orderitem->orderitem_status = '1'; $orderitem->save(); // TODO Here we need to verify the payment amount // if no subscription exists for this subscr_id, // create new subscription for the user $subscription = JTable::getInstance('Subscriptions', 'CitruscartTable'); $subscription->load(array('transaction_id' => $data['subscr_id'])); if (empty($subscription->subscription_id)) { $date = JFactory::getDate(); // create new subscription // if recurring trial, set it // for the order's recurring_trial_period_interval // using its recurring_trial_period_unit // otherwise, do the normal recurring_period_interval // and the recurring_period_unit $recurring_period_unit = $order->recurring_period_unit; $recurring_period_interval = $order->recurring_period_interval; if (!empty($order->recurring_trial)) { $recurring_period_unit = $order->recurring_trial_period_unit; $recurring_period_interval = $order->recurring_trial_period_interval; } $subscription->user_id = $order->user_id; $subscription->order_id = $order->order_id; $subscription->product_id = $orderitem->product_id; $subscription->orderitem_id = $orderitem->orderitem_id; $subscription->transaction_id = $data['subscr_id']; $subscription->created_datetime = $date->toSql(); $subscription->subscription_enabled = '1'; switch ($recurring_period_unit) { case "Y": $period_unit = "YEAR"; break; case "M": $period_unit = "MONTH"; break; case "W": $period_unit = "WEEK"; break; case "D": default: $period_unit = "DAY"; break; } $database = JFactory::getDBO(); $query = " SELECT DATE_ADD('{$subscription->created_datetime}', INTERVAL {$recurring_period_interval} {$period_unit} ) "; $database->setQuery($query); $subscription->expires_datetime = $database->loadResult(); if (!$subscription->save()) { $this->setError($subscription->getError()); return false; } // add a sub history entry, email the user? $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'CitruscartTable'); $subscriptionhistory->subscription_id = $subscription->subscription_id; $subscriptionhistory->subscriptionhistory_type = 'creation'; $subscriptionhistory->created_datetime = $date->toSql(); $subscriptionhistory->notify_customer = '0'; // notify customer of new trial subscription? $subscriptionhistory->comments = JText::_('NEW SUBSCRIPTION CREATED'); $subscriptionhistory->save(); } else { // subscription exists, just update its expiration date // based on normal interval and period switch ($order->recurring_period_unit) { case "Y": $period_unit = "YEAR"; break; case "M": $period_unit = "MONTH"; break; case "W": $period_unit = "WEEK"; break; case "D": default: $period_unit = "DAY"; break; } $database = JFactory::getDBO(); $today = $date = JFactory::getDate(); $query = " SELECT DATE_ADD('{$today}', INTERVAL {$order->recurring_period_interval} {$period_unit} ) "; $database->setQuery($query); $subscription->expires_datetime = $database->loadResult(); if (!$subscription->save()) { $this->setError($subscription->getError()); return false; } // add a sub history entry, email the user? $subscriptionhistory = JTable::getInstance('SubscriptionHistory', 'CitruscartTable'); $subscriptionhistory->subscription_id = $subscription->subscription_id; $subscriptionhistory->subscriptionhistory_type = 'payment'; $subscriptionhistory->created_datetime = $date->toSql(); $subscriptionhistory->notify_customer = '0'; // notify customer of new trial subscription? $subscriptionhistory->comments = JText::_('NEW SUBSCRIPTION PAYMENT RECEIVED'); $subscriptionhistory->save(); } if (count($items) == '1') { // update order status Citruscart::load('CitruscartHelperOrder', 'helpers.order'); Citruscart::load('CitruscartHelperCarts', 'helpers.carts'); $order->order_state_id = $this->params->get('payment_received_order_state', '17'); // PAYMENT RECEIVED // do post payment actions $setOrderPaymentReceived = true; // send email $send_email = true; // save the order if (!$order->save()) { $errors[] = $order->getError(); } if (!empty($setOrderPaymentReceived)) { $this->setOrderPaymentReceived($orderpayment->order_id); } if ($send_email) { // send notice of new order Citruscart::load("CitruscartHelperBase", 'helpers._base'); $helper = CitruscartHelperBase::getInstance('Email'); $model = Citruscart::getClass("CitruscartModelOrders", "models.orders"); $model->setId($orderpayment->order_id); $order = $model->getItem(); $helper->sendEmailNotices($order, 'new_order'); } } $error = count($errors) ? implode("\n", $errors) : ''; if (!empty($error)) { $this->setError($error); return false; } return true; }