Exemplo n.º 1
0
 /**
  * Stores the object
  * @param object
  * @return boolean
  */
 function store($updateNulls = false)
 {
     $date = JFactory::getDate();
     $this->modified_date = $date->toSql();
     $store = parent::store($updateNulls);
     return $store;
 }
 /**
  * 
  * @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;
 }
Exemplo n.º 3
0
 /**
  * 
  * @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;
 }
Exemplo n.º 4
0
 public function store($updateNulls = false)
 {
     // Check the table activation status first
     if (!$this->active) {
         // Activate it with a default value
         $this->setType('');
     }
     if ($this->getType() == 'datetime') {
         if (isset($this->eavvalue_value)) {
             $null_date = JFactory::getDbo()->getNullDate();
             if ($this->eavvalue_value == $null_date || $this->eavvalue_value == '') {
                 $this->eavvalue_value = $null_date;
             } else {
                 $offset = JFactory::getConfig()->getValue('config.offset');
                 $this->eavvalue_value = date('Y-m-d H:i:s', strtotime(CitruscartHelperBase::getOffsetDate($this->eavvalue_value, -$offset)));
             }
         }
     }
     return parent::store($updateNulls);
 }
Exemplo n.º 5
0
 /**
  * First stores the record
  * Then checks if it should be the default
  *
  * @see Citruscart/admin/tables/CitruscartTable#store($updateNulls)
  */
 function store($updateNulls = false)
 {
     if ($return = parent::store($updateNulls)) {
         if ($this->is_default_shipping == '1' || $this->is_default_billing == '1') {
             // update the defaults
             $query = new CitruscartQuery();
             $query->update("#__citruscart_addresses");
             $query->where("`user_id` = '{$this->user_id}'");
             $query->where("`address_id` != '{$this->address_id}'");
             if ($this->is_default_shipping == '1') {
                 $query->set("`is_default_shipping` = '0'");
             }
             if ($this->is_default_billing == '1') {
                 $query->set("`is_default_billing` = '0'");
             }
             $this->_db->setQuery((string) $query);
             if (!$this->_db->query()) {
                 $this->setError($this->_db->getErrorMsg());
                 return false;
             }
         }
     }
     return $return;
 }
Exemplo n.º 6
0
 /**
  * Inserts a new row if id is zero or updates an existing row in the database table
  * Check for custom fields and store them in the right table
  * Can be overloaded/supplemented by the child class
  *
  * @access public
  * @param boolean If false, null object variables are not updated
  * @return null|string null if successful otherwise returns and error message
  */
 function store($updateNulls = false)
 {
     Citruscart::load("CitruscartHelperEav", 'helpers.eav');
     /* Get the application */
     $app = JFactory::getApplication();
     $before = $app->triggerEvent('onBeforeStore' . $this->get('_suffix'), array(&$this));
     if (in_array(false, $before, true)) {
         return false;
     }
     $key = $this->_tbl_key;
     $id = $this->{$key};
     /* ID from post */
     $post_id = $app->input->getInt($key, 0);
     $editable_by = $app->isAdmin() ? 1 : 2;
     if ($app->isAdmin()) {
         $view = $app->input->get('view', '');
         if ($view == 'pos') {
             // display all for POS
             $editable_by = array(0, 1, 2);
         }
     }
     // Get the custom fields for this entities
     $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 = CitruscartHelperEav::getAttributes($this->_linked_table, $this->_linked_table_key, false, $editable_by);
         $eavs = array_merge($eavs, $mirrored_eavs);
     }
     $custom_fields = array();
     // Is this a mirrored table (see decription at the beginning of this file)
     // Get is eavs first, and then override them with values from the request
     if (strlen($this->_linked_table) && $this->_linked_table_key) {
         // Copy the custom field value to this table
         $mirrored_eavs = CitruscartHelperEav::getAttributes($this->_linked_table, $this->_linked_table_key, false, $editable_by);
         // If there are Custom Fields for the linked key
         if (count($mirrored_eavs)) {
             foreach ($mirrored_eavs as $eav) {
                 $key = $eav->eavattribute_alias;
                 // Check if the key exists in this object (already mirrored)
                 if (!property_exists($this, $key)) {
                     // Get the value
                     //						if( $id === null || $post_id == $id )
                     $value = CitruscartHelperEav::getAttributeValue($eav, $this->_linked_table, $this->_linked_table_key, !($id === null || $post_id == $id), false);
                     //						else
                     //							$value = null;
                     // Store it into the array for eav values
                     if ($value !== null) {
                         $custom_fields[$key] = array('eav' => $eav, 'value' => $value);
                     }
                 } else {
                     $value = $this->{$key};
                     unset($this->{$key});
                     // Store it into the array for eav values
                     $custom_fields[$key] = array('eav' => $eav, 'value' => $value);
                 }
             }
         }
     }
     // If there are Custom Fields in this object
     if (count($eavs)) {
         foreach ($eavs as $eav) {
             $key = $eav->eavattribute_alias;
             // Check if the key exists in this object (could be a ->load() ->set() ->store() workflow)
             if (property_exists($this, $key)) {
                 // Fetch the value from the post (if any) and overwrite the object value if it exists
                 if ($eav->eavattribute_type == 'text') {
                     $value = $app->input->getHtml($key);
                 } else {
                     $value = $app->input->get($key);
                 }
                 if ($value === null) {
                     // If not, use the object value
                     $value = $this->{$key};
                 }
                 unset($this->{$key});
                 // Store it into the array for eav values
                 $custom_fields[$key] = array('eav' => $eav, 'value' => $value);
             } else {
                 if ($id === null || $post_id == $id) {
                     // Fetch the value from the post (if any)
                     $value = $app->input->get($key);
                 } else {
                     $value = null;
                 }
                 if ($value !== null) {
                     // Store it into the array for eav values
                     $custom_fields[$key] = array('eav' => $eav, 'value' => $value);
                 }
             }
         }
     }
     if ($return = parent::store($updateNulls)) {
         // Store custom fields if needed
         if (count($custom_fields)) {
             $key = $this->_tbl_key;
             $id = $this->{$key};
             foreach ($custom_fields as $cf) {
                 // get the value table
                 $table = JTable::getInstance('EavValues', 'CitruscartTable');
                 // set the type based on the attribute
                 $table->setType($cf['eav']->eavattribute_type);
                 // load the value based on the entity id
                 $keynames = array();
                 $keynames['eavattribute_id'] = $cf['eav']->eavattribute_id;
                 $keynames['eaventity_id'] = $id;
                 $loaded = $table->load($keynames);
                 // Add the value if it's a first time save
                 if (!$loaded) {
                     $table->eavattribute_id = $cf['eav']->eavattribute_id;
                     $table->eaventity_id = $id;
                 }
                 // Store the value
                 $table->eavvalue_value = $cf['value'];
                 $table->eaventity_type = $this->get('_suffix');
                 $stored = $table->store();
                 // Log the errors
                 if (!$stored) {
                     if (strlen($this->getError())) {
                         $this->setError($this->getError());
                     }
                 }
             }
         }
         JFactory::getApplication()->triggerEvent('onAfterStore' . $this->get('_suffix'), array($this));
     }
     return $return;
 }
Exemplo n.º 7
0
 /**
  * (non-PHPdoc)
  * @see DSCTable::save()
  */
 function save($src = '', $orderingFilter = '', $ignore = '')
 {
     $isNew = false;
     if (empty($this->productcomment_id)) {
         $isNew = true;
     }
     if ($save = parent::save($src, $orderingFilter, $ignore)) {
         if ($this->productcomment_enabled && empty($this->rating_updated)) {
             // get the product row
             $product = JTable::getInstance('Products', 'CitruscartTable');
             $product->load($this->product_id);
             $product->updateOverallRating();
             if (!$product->save()) {
                 $this->setError($product->getError());
             } else {
                 $this->rating_updated = '1';
                 parent::store();
             }
         } elseif (!$this->productcomment_enabled && !empty($this->rating_updated)) {
             // comment has been disabled after it already updated the overall rating
             // so remove it from the overall rating
             // get the product row
             $product = JTable::getInstance('Products', 'CitruscartTable');
             $product->load($this->product_id);
             $product->updateOverallRating();
             if (!$product->save()) {
                 $this->setError($product->getError());
             } else {
                 $this->rating_updated = '0';
                 parent::store();
             }
         }
     }
     return $save;
 }
Exemplo n.º 8
0
 /**
  *
  * @param unknown_type $updateNulls
  * @return unknown_type
  */
 function store($updateNulls = false)
 {
     $app = JFactory::getApplication();
     // relative paths start with DSDS
     if (strpos($this->productfile_path, DS . DS) === false) {
         $prefix = DS . DS;
         if ($this->productfile_path[0] == DS) {
             // in case we use UNIX path (starting with /)
             $prefix = DS;
         }
         if ($app->isAdmin()) {
             //saving on admin site -> path_base contains "/Administrator"
             $this->productfile_path = $prefix . substr($this->productfile_path, strlen(JPATH_BASE) - 14);
         } else {
             $this->productfile_path = $prefix . substr($this->productfile_path, strlen(JPATH_BASE));
         }
     }
     return parent::store($updateNulls);
 }
Exemplo n.º 9
0
 function store($updateNulls = false)
 {
     // add hash to orders which are placed by guests
     if (!$this->order_id && !strlen($this->order_hash) && $this->user_id < Citruscart::getGuestIdStart()) {
         Citruscart::load('CitruscartHelperOrder', 'helpers.order');
         $this->order_hash = CitruscartHelperOrder::getHashInvoice($this);
     }
     return parent::store($updateNulls);
 }
Exemplo n.º 10
0
 function save($src = '', $orderingFilter = '', $ignore = '')
 {
     $isNew = false;
     if (empty($this->credit_id)) {
         $isNew = true;
     }
     $prev = clone $this;
     $prev->load($this->id);
     $wasWithdrawableBefore = $prev->credit_withdrawable;
     $wasEnabledBefore = $prev->credit_enabled;
     if ($save = parent::save($src, $orderingFilter, $ignore)) {
         if (($isNew && $this->credit_enabled || !$isNew && $this->credit_enabled) && empty($this->credits_updated)) {
             // add the credits to the total
             $userdata = JTable::getInstance('UserInfo', 'CitruscartTable');
             $userdata->load(array('user_id' => $this->user_id));
             $userdata->user_id = $this->user_id;
             $credit_balance_before = $userdata->credits_total;
             $withdrawable_balance_before = $userdata->credits_withdrawable_total;
             $userdata->credits_total = $userdata->credits_total + $this->credit_amount;
             if ($this->credit_withdrawable) {
                 $userdata->credits_withdrawable_total = $userdata->credits_withdrawable_total + $this->credit_amount;
             }
             if (!$userdata->save()) {
                 $this->setError($userdata->getError());
             } else {
                 $this->credits_updated = '1';
                 $this->credit_balance_before = $credit_balance_before;
                 $this->credit_balance_after = $userdata->credits_total;
                 $this->withdrawable_balance_before = $withdrawable_balance_before;
                 $this->withdrawable_balance_after = $userdata->credits_withdrawable_total;
                 parent::store();
             }
         } elseif (!$isNew && !$this->credit_enabled && !empty($this->credits_updated)) {
             // if this is an existing credit that is now being disabled,
             // remove the credits from the total
             $userdata = JTable::getInstance('UserInfo', 'CitruscartTable');
             $userdata->load(array('user_id' => $this->user_id));
             $userdata->user_id = $this->user_id;
             $userdata->credits_total = $userdata->credits_total - $this->credit_amount;
             if ($this->credit_withdrawable) {
                 $userdata->credits_withdrawable_total = $userdata->credits_withdrawable_total - $this->credit_amount;
             }
             if (!$userdata->save()) {
                 $this->setError($userdata->getError());
             } else {
                 $this->credits_updated = '0';
                 $this->credit_balance_before = 0;
                 $this->credit_balance_after = 0;
                 $this->withdrawable_balance_before = 0;
                 $this->withdrawable_balance_after = 0;
                 parent::store();
             }
         }
         if (!$isNew && $this->credit_enabled && !empty($this->credits_updated) && $this->credit_withdrawable && !$wasWithdrawableBefore) {
             // if this is an existing credit that is enabled
             // and it has already updated the credits_total for the user
             // but is now being changed to a withdrawable amount,
             // then we need to adjust the user's withdrawable total
             $userdata = JTable::getInstance('UserInfo', 'CitruscartTable');
             $userdata->load(array('user_id' => $this->user_id));
             $userdata->user_id = $this->user_id;
             $withdrawable_balance_before = $userdata->credits_withdrawable_total;
             $userdata->credits_withdrawable_total = $userdata->credits_withdrawable_total + $this->credit_amount;
             if ($userdata->save()) {
                 $this->withdrawable_balance_before = $withdrawable_balance_before;
                 $this->withdrawable_balance_after = $userdata->credits_withdrawable_total;
                 parent::store();
             }
         }
         if (!$isNew && !empty($this->credits_updated) && !$this->credit_withdrawable && $wasWithdrawableBefore && $wasEnabledBefore) {
             // if this is an existing credit
             // and it has already updated the credits_total for the user
             // but is now being changed to a non-withdrawable amount,
             // then we need to adjust the user's withdrawable total
             $userdata = JTable::getInstance('UserInfo', 'CitruscartTable');
             $userdata->load(array('user_id' => $this->user_id));
             $userdata->user_id = $this->user_id;
             $withdrawable_balance_before = $userdata->credits_withdrawable_total;
             $userdata->credits_withdrawable_total = $userdata->credits_withdrawable_total - $this->credit_amount;
             if ($userdata->save()) {
                 $this->withdrawable_balance_before = $withdrawable_balance_before;
                 $this->withdrawable_balance_after = $userdata->credits_withdrawable_total;
                 parent::store();
             }
         }
     }
     return $save;
 }