/** * Get the Eav Attributes for a particular entity * @param unknown_type $entity * @param unknown_type $id * @param boolean $only_enabled */ public static function getAttributes($entity, $id, $only_enabled = false, $editable_by = '') { // $sets[$entity][$id] static $sets; if (!is_array($sets)) { $sets = array(); } if (is_array($editable_by)) { $editable_by = implode(',', $editable_by); } else { if (!strlen($editable_by)) { $editable_by = '-1'; } } if (!isset($sets[$entity][$id][$editable_by])) { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = DSCModel::getInstance('EavAttributes', 'TiendaModel'); $model->setState('filter_entitytype', $entity); $model->setState('filter_entityid', $id); $model->setState('filter_enabled', '1'); if ($editable_by != '-1') { $model->setState('filter_editable', $editable_by); } $sets[$entity][$id][$editable_by] = $model->getList(); } // Let the plugins change the list of custom fields $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onAfterGetCustomFields', array(&$sets[$entity][$id][$editable_by], $entity, $id)); return $sets[$entity][$id][$editable_by]; }
public function getAttributes($oid = null) { $k = $this->_tbl_key; if ($oid) { $this->{$k} = intval($oid); } if (empty($this->{$k})) { return array(); } DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('OrderitemAttributes', 'CitruscartModel'); $model->setState('filter_orderitemid', $this->{$k}); return $model->getList(); }
/** * Run function after deleteing */ function delete($oid = null, $doReconciliation = true) { $k = $this->_tbl_key; if ($oid) { $this->{$k} = intval($oid); } if ($doReconciliation) { if ($oid) { $row = JTable::getInstance('ProductAttributes', 'TiendaTable'); $row->load($oid); $product_id = $row->product_id; } else { $product_id = $this->product_id; } } $db = $this->getDBO(); $db->setQuery('SET foreign_key_checks = 0;'); $db->query(); if ($return = parent::delete($oid)) { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = DSCModel::getInstance('ProductAttributeOptions', 'TiendaModel'); $model->setState('filter_attribute', $this->{$k}); if ($items = $model->getList()) { $table = $model->getTable(); foreach ($items as $item) { if (!$table->delete($item->productattributeoption_id)) { $this->setError($table->getError()); } } } if ($doReconciliation) { Tienda::load("TiendaHelperProduct", 'helpers.product'); TiendaHelperProduct::doProductQuantitiesReconciliation($product_id); } } $db->setQuery('SET foreign_key_checks = 1;'); $db->query(); return parent::check(); }
/** * * @param $oid * @return unknown_type */ function delete($oid = null, $doReconciliation = true) { $k = $this->_tbl_key; if ($oid) { $this->{$k} = intval($oid); } if ($doReconciliation) { if ($oid) { $row = JTable::getInstance('ProductComments', 'CitruscartTable'); $row->load($oid); $product_id = $row->product_id; } else { $product_id = $this->product_id; } } if (parent::delete($oid)) { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('ProductCommentsHelpfulness', 'CitruscartModel'); $model->setState('filter_comment', $this->{$k}); if ($items = $model->getList()) { $table = $model->getTable(); foreach ($items as $item) { if (!$table->delete($item->productcommentshelpfulness_id)) { $this->setError($table->getError()); } } } if ($doReconciliation) { $product = JTable::getInstance('Products', 'CitruscartTable'); $product->load($product_id); $product->updateOverallRating(); if (!$product->save()) { $this->setError($product->getError()); } } } return parent::check(); }
public function deleteItems($type, $oid = null) { $failed = false; $k = $this->_tbl_key; if ($oid) { $this->{$k} = intval($oid); } DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = DSCModel::getInstance('Order' . $type, 'TiendaModel'); $model->setState('filter_orderid', $this->{$k}); if ($items = $model->getList()) { $table = $model->getTable(); $table_pk = $table->getKeyName(); foreach ($items as $item) { if (!$table->delete($item->{$table_pk})) { $errors = $table->getErrors(); if (!empty($errors)) { foreach ($errors as $key => $error) { $error = trim($error); if (!empty($error)) { $failed = true; $this->setError($error); } } } } } } if ($failed) { return false; } return true; }
/** * Clean the cache * * @return void * * @since 11.1 */ public function clearCacheAuxiliary() { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = DSCModel::getInstance('ProductCategories', 'TiendaModel'); $model->clearCache(); $model = DSCModel::getInstance('ProductAttributeOptions', 'TiendaModel'); $model->clearCache(); $model = DSCModel::getInstance('ProductAttributeOptionValues', 'TiendaModel'); $model->clearCache(); $model = DSCModel::getInstance('ProductAttributes', 'TiendaModel'); $model->clearCache(); $model = DSCModel::getInstance('ProductCompare', 'TiendaModel'); $model->clearCache(); $model = DSCModel::getInstance('ProductFiles', 'TiendaModel'); $model->clearCache(); $model = DSCModel::getInstance('ProductPrices', 'TiendaModel'); $model->clearCache(); $model = DSCModel::getInstance('ProductRelations', 'TiendaModel'); $model->clearCache(); }
public function getCountry() { if (empty($this->country_id)) { return false; } DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('Countries', 'CitruscartModel'); $model->setId($this->country_id); return $model->getItem(); }
<div class="well options"> <legend> <?php echo JText::_('COM_TIENDA_ADD_NEW_RELATIONSHIP'); ?> </legend> <div id="new_relationship" class="dsc-wrap dsc-table"> <div class="dsc-row"> <div class="dsc-cell"> <?php echo TiendaSelect::relationship('', 'new_relationship_type'); ?> </div> <div class="dsc-cell"> <?php DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = DSCModel::getInstance('ElementProduct', 'TiendaModel'); echo $model->fetchElement('new_relationship_productid_to'); echo $model->clearElement('new_relationship_productid_to'); //<input name="new_relationship_productid_to" size="15" type="text" /> ?> <input name="new_relationship_productid_from" value="<?php echo @$row->product_id; ?> " type="hidden" /> </div> <div class="dsc-cell"> <input type="button" value="<?php echo JText::_('COM_TIENDA_ADD'); ?>
public function deleteItemsWithoutReconciliation($type, $oid = null, $doReconciliation = false) { $failed = false; $k = $this->_tbl_key; if ($oid) { $this->{$k} = intval($oid); } DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('Product' . $type, 'CitruscartModel'); $model->setState('filter_productid', $this->{$k}); if ($items = $model->getList()) { $table = $model->getTable(); $table_pk = $table->getKeyName(); foreach ($items as $item) { if (!$table->delete($item->{$table_pk}, $doReconciliation)) { $errors = $table->getErrors(); if (!empty($errors)) { foreach ($errors as $key => $error) { $error = trim($error); if (!empty($error)) { $failed = true; $this->setError($error); } } } } } } if ($failed) { return false; } return true; }
/** * Gets the model * only creating it if it doesn't exist * * @return array */ function _getModel($name = '', $prefix = 'SampleModel', $config = array()) { if (empty($name)) { $name = $this->get('default_model', 'Base'); } $fullname = strtolower($prefix . $name); if (empty($this->_models[$fullname])) { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_sample/models'); if (!($model = DSCModel::getInstance($name, $prefix, $config))) { $model = new SampleModelBase(); } $this->_models[$fullname] = $model; } return $this->_models[$fullname]; }
/** * * @param array $values * @param boolean $saveAddressesToDB Save the addresses to the database * @param boolean $ajax * @return unknown_type */ public function setAddresses(&$values, $saveAddressesToDB = false, $ajax = false) { $clearAddressCache = false; $order = $this->_order; Citruscart::load('CitruscartHelperCurrency', 'helpers.currency'); $currency_id = CitruscartHelperCurrency::getCurrentCurrency(); $billing_address_id = !empty($values['billing_address_id']) ? $values['billing_address_id'] : 0; $shipping_address_id = !empty($values['shipping_address_id']) ? $values['shipping_address_id'] : 0; $same_as_billing = !empty($values['sameasbilling']) ? true : false; $user_id = $values['user_id']; $billing_input_prefix = $this->billing_input_prefix; $shipping_input_prefix = $this->shipping_input_prefix; if (empty($user_id) && $this->defines->get('guest_checkout_enabled', '1')) { $user_id = -1; } $billing_zone_id = 0; $billingAddressArray = $this->getAddressArray($billing_address_id, $billing_input_prefix, $values); if (array_key_exists('zone_id', $billingAddressArray)) { $billing_zone_id = $billingAddressArray['zone_id']; } //SHIPPING ADDRESS: get shipping address from dropdown or form (depending on selection) $shipping_zone_id = 0; if ($same_as_billing) { $shippingAddressArray = $billingAddressArray; } else { $shippingAddressArray = $this->getAddressArray($shipping_address_id, $shipping_input_prefix, $values); } if (array_key_exists('zone_id', $shippingAddressArray)) { $shipping_zone_id = $shippingAddressArray['zone_id']; } // keep the array for binding during the saveOrderInfo process $this->_orderinfoBillingAddressArray = $this->filterArrayUsingPrefix($billingAddressArray, '', 'billing_', true); $this->_orderinfoShippingAddressArray = $this->filterArrayUsingPrefix($shippingAddressArray, '', 'shipping_', true); $this->_billingAddressArray = $billingAddressArray; $this->_shippingAddressArray = $shippingAddressArray; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $billingAddress = JTable::getInstance('Addresses', 'CitruscartTable'); $shippingAddress = JTable::getInstance('Addresses', 'CitruscartTable'); // set the order billing address $billingAddress->bind($billingAddressArray); $billingAddress->user_id = $user_id; $billingAddress->addresstype_id = 1; if ($saveAddressesToDB && !$billing_address_id) { $clearAddressCache = true; $billingAddress->save(); if (!$billing_address_id) { $values['billing_address_id'] = $billingAddress->address_id; } } $order->setAddress($billingAddress); // set the order shipping address $shippingAddress->bind($shippingAddressArray); $shippingAddress->user_id = $user_id; $shippingAddress->addresstype_id = 2; if ($saveAddressesToDB && !$same_as_billing && !$shipping_address_id) { $clearAddressCache = true; $shippingAddress->save(); if (!$shipping_address_id) { $values['shipping_address_id'] = $shippingAddress->address_id; } } if ($clearAddressCache) { DSCModel::addIncludePath(JPATH_SITE . '/components/com_citruscart/models'); $model = DSCModel::getInstance('Addresses', 'CitruscartModel'); $model->clearCache(); } $order->setAddress($shippingAddress, 'shipping'); return $this; }
public function save($values, $options = array()) { $result = new stdClass(); $result->error = false; Citruscart::load('CitruscartHelperUser', 'helpers.user'); $userHelper = new CitruscartHelperUser(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $userinfo = JTable::getInstance('UserInfo', 'CitruscartTable'); $user_id = $values["user_id"]; $create_account = $values["checkout_method"] == 'register' ? true : false; $guest_checkout = $this->defines->get('guest_checkout_enabled', '1'); if ($values["checkout_method"] == "guest") { // save the real user info in the userinfo table $userinfo->user_id = $user_id; $userinfo->email = $values['email_address']; if (!$userinfo->save()) { $result->error = true; $this->setError($userinfo->getError()); } // save the billing and shipping addresses? //$this->setAddresses($submitted_values, true, true); } elseif ($values["checkout_method"] == "register") { // create a new user from billing info $details = array('email' => $values['email_address'], 'name' => $values['billing_input_first_name'] . ' ' . $values['billing_input_middle_name'] . ' ' . $values['billing_input_last_name'], 'username' => $values['email_address']); if (strlen(trim($details['name'])) == 0) { $details['name'] = JText::_('COM_CITRUSCART_USER'); } $details['password'] = $values["register-new-password"]; $details['password2'] = $values["register-new-password2"]; if (!($user = $userHelper->createNewUser($details))) { $result->error = true; //$this->setError( $user->getError() ); } else { $userHelper->login(array('username' => $user->username, 'password' => $details['password'])); $user_id = $user->id; $userinfo->load(array('user_id' => $user_id)); $userinfo->user_id = $user_id; $userinfo->first_name = $values['billing_input_first_name']; $userinfo->last_name = $values['billing_input_last_name']; $userinfo->company = $values['billing_input_company']; $userinfo->middle_name = $values['billing_input_middle_name']; $userinfo->phone_1 = $values['billing_input_phone_1']; $userinfo->email = $values['email_address']; if (!$userinfo->save()) { $result->error = true; $this->setError($userinfo->getError()); } } } $result->user_id = $user_id; $result->userinfo = $userinfo; $this->result = $result; DSCModel::addIncludePath(JPATH_SITE . '/components/com_citruscart/models'); $model = DSCModel::getInstance('Userinfo', 'CitruscartModel'); $model->clearCache(); if ($result->error) { return false; } return $result; }
public function setPayment() { $app = JFactory::getApplication(); $input = JFactory::getApplication()->input; $this->setFormat(); $session = JFactory::getSession(); $response = $this->getResponseObject(); $post = $input->getArray($_POST); $order = $this->_order; $order = $this->populateOrder(); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $dummyaddress = JTable::getInstance('Addresses', 'CitruscartTable'); $billingAddress = unserialize($session->get('citruscart.opc.billingAddress')); $shippingAddress = unserialize($session->get('citruscart.opc.shippingAddress')); $order->setAddress($billingAddress); if (!empty($shippingAddress)) { $order->setAddress($shippingAddress, 'shipping'); } if ($shippingMethod = unserialize($session->get('citruscart.opc.shippingMethod'))) { $order->setShippingRate($shippingMethod); } if ($shippingMethod = unserialize($session->get('citruscart.opc.shippingMethod'))) { $order->setShippingRate($shippingMethod); } $order->calculateTotals(); $errorMessage = ''; if (empty($post['payment_plugin']) && $order->isPaymentRequired()) { $errorMessage = '<ul class="text-error">'; $errorMessage .= "<li>" . JText::_("COM_CITRUSCART_PLEASE_SELECT_PAYMENT_METHOD") . "</li>"; $errorMessage .= '</ul>'; $response->goto_section = 'payment'; $response->summary->html = $errorMessage; echo json_encode($response); $app->close(); } if ($order->isPaymentRequired()) { // Validate the results of the payment plugin $errorMessagesFromPlugins = ''; $dispatcher = JDispatcher::getInstance(); $results = JFactory::getApplication()->triggerEvent("onGetPaymentFormVerify", array($post['payment_plugin'], $post)); foreach ($results as $result) { if (!empty($result->error)) { $errorMessagesFromPlugins .= $result->message; } } } if (!empty($errorMessagesFromPlugins)) { $errorMessage = '<ul class="text-error">'; $errorMessage .= $errorMessagesFromPlugins; $errorMessage .= '</ul>'; $response->goto_section = 'payment'; $response->summary->id = 'opc-payment-validation'; $response->summary->html = $errorMessage; echo json_encode($response); $app->close(); } if ($order->isPaymentRequired()) { $dispatcher = JDispatcher::getInstance(); $results = JFactory::getApplication()->triggerEvent("onGetPaymentSummary", array($post['payment_plugin'], $post)); $text = ''; for ($i = 0, $count = count($results); $i < $count; $i++) { $text .= $results[$i]; } if (empty($text)) { // success summary, for now, is just the name of the plugin DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('Payment', 'CitruscartModel'); $model->setState('limit', '1'); $model->setState('filter_element', $post['payment_plugin']); if ($items = $model->getList()) { $item = $items[0]; $text = $item->name; } } $response->summary->html = $text; } else { $response->summary->html = JText::_("COM_CITRUSCART_NO_PAYMENT_NECESSARY"); } $response->summaries = array(); $summary = $this->getSummaryResponseObject(); $summary->id = 'opc-review-body'; $summary->html = $this->getOrderSummary('review'); $response->summaries[] = $summary; $response->goto_section = 'review'; echo json_encode($response); $app->close(); }
/** * Returns an array of objects, * each containing the parsed html of all articles that should be displayed * after an order is completed, * based on the defined global article and any product-, shippingmethod-, and paymentmethod-specific articles * * @param $order_id * @return array */ function getOrderArticles($order_id) { Tienda::load('TiendaArticle', 'library.article'); $articles = array(); DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = DSCModel::getInstance('OrderItems', 'TiendaModel'); $model->setState('filter_orderid', $order_id); $orderitems = $model->getList(); foreach ($orderitems as $item) { if (!empty($item->product_article)) { $articles[] = TiendaArticle::display($item->product_article); } } $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onGetOrderArticles', array($order_id, &$articles)); return $articles; }
/** * One a new order, * increase the uses count on all the ordercoupons. * * @param $order_id * @return unknown_type */ public function processOrder($order_id) { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('Ordercoupons', 'CitruscartModel'); $model->setState('filter_orderid', $order_id); if ($items = $model->getList()) { DSCTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/tables'); $coupon = DSCTable::getInstance('Coupons', 'CitruscartTable'); foreach ($items as $item) { $coupon->load(array('coupon_id' => $item->coupon_id)); $coupon->coupon_uses = $coupon->coupon_uses + 1; if (!$coupon->save()) { //JFactory::getApplication()->enqueueMessage( $coupon->getError() ); } } } }
/** * Returns an array of objects, * each containing the parsed html of all articles that should be displayed * after an order is completed, * based on the defined global article and any product-, shippingmethod-, and paymentmethod-specific articles * * @param $order_id * @return array */ function getOrderArticles($order_id) { Citruscart::load('CitruscartArticle', 'library.article'); $articles = array(); DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('OrderItems', 'CitruscartModel'); $model->setState('filter_orderid', $order_id); $orderitems = $model->getList(); foreach ($orderitems as $item) { if (!empty($item->product_article)) { $articles[] = CitruscartArticle::display($item->product_article); } } JFactory::getApplication()->triggerEvent('onGetOrderArticles', array($order_id, &$articles)); return $articles; }
/** * Run function when deleting * @see Citruscart/admin/tables/CitruscartTable#save() */ function delete($oid = null, $doReconciliation = true) { $k = $this->_tbl_key; if ($oid) { $this->{$k} = intval($oid); } if ($doReconciliation) { $pa = JTable::getInstance('ProductAttributes', 'CitruscartTable'); if ($oid) { $row = JTable::getInstance('ProductAttributeOptions', 'CitruscartTable'); $row->load($oid); $pa->load($row->productattribute_id); } else { $pa->load($this->productattribute_id); } $product_id = $pa->product_id; } if ($return = parent::delete($oid)) { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('ProductAttributeOptionValues', 'CitruscartModel'); $model->setState('filter_option', $this->{$k}); if ($items = $model->getList()) { $table = $model->getTable(); foreach ($items as $item) { if (!$table->delete($item->productattributeoptionvalue_id)) { $this->setError($table->getError()); } } } if ($doReconciliation) { Citruscart::load("CitruscartHelperProduct", 'helpers.product'); CitruscartHelperProduct::doProductQuantitiesReconciliation($product_id); } } return parent::check(); }
/** * Clean the cache * * @return void * * @since 11.1 */ public function clearCacheAuxiliary() { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('ZoneRelations', 'CitruscartModel'); $model->clearCache(); }
/** * Clean the cache * * @return void * * @since 11.1 */ public function clearCacheAuxiliary() { DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models'); $model = DSCModel::getInstance('SubscriptionHistory', 'TiendaModel'); $model->clearCache(); }
<legend> <?php echo JText::_('COM_CITRUSCART_ADD_NEW_RELATIONSHIP'); ?> </legend> <div id="new_relationship" class="dsc-wrap dsc-table"> <div class="dsc-row"> <div class="dsc-cell"> <?php echo CitruscartSelect::relationship('', 'new_relationship_type'); ?> </div> <div class="dsc-cell"> <?php DSCModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_citruscart/models'); $model = DSCModel::getInstance('ElementProduct', 'CitruscartModel'); echo $model->fetchElement('new_relationship_productid_to'); echo $model->clearElement('new_relationship_productid_to'); //<input name="new_relationship_productid_to" size="15" type="text" /> ?> <input name="new_relationship_productid_from" value="<?php echo $row->product_id; ?> " type="hidden" /> </div> <div class="dsc-cell"> <input type="button" value="<?php echo JText::_('COM_CITRUSCART_ADD'); ?>