*

mwindey

  • ***
  • 93 posts
Issue when updating table expire_date =NULL
« on: August 17, 2021, 09:13:30 AM »
I noticed that when a user pays for sms premium, table item_sms_premium_expires inserts a new row instead of updating the existing row that contains value NULL or a previous expire date.
A big issue when a user wants to pay during his premium period to extend the date and sees that the date is set to the same date he has already payed for.
Instead of updating the existing row that contains date or NULL it creates a new date but when you hover on live site to button premium it shows the old date because the empty row is there and outputs the empty row.
In model the function looks correct so i don't now what is wrong.
I believe =NULL cannot be found as a value null so i thought to change model to IS NULL but that screws up the whole webiste.
code in model:
Code: [Select]
  public function updateExpireByItemId( $item_id, $date = NULL ) {
    $aSet = array('expire_date' => $date);
    $aWhere = array('item_id' => $item_id);

    return $this->_update($this->getTable_PremiumExpire(), $aSet, $aWhere);
  }


  public function insertExpireByItemId( $item_id, $date ) {
    $aSet = array(
      'item_id' => $item_id,
      'expire_date' => $date
    );

    return $this->dao->insert( $this->getTable_PremiumExpire(), $aSet);
  } 
 

Attached a screenshot from what happens in db... 4 rows with same item_id after payment when expired and renewed 3 times for 30 days.
The NULL does not gets updated after payment and it leaves the old day as is ... Instead it creates extra rows with a new date.... or same date starting from NULL
« Last Edit: August 17, 2021, 09:30:57 AM by mwindey »

*

MB Themes

Re: Issue when updating table expire_date =NULL
« Reply #1 on: August 17, 2021, 09:32:04 AM »
@mwindey
if expire is set to null, it should mean "no expire" and basically should never been updated.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • ***
  • 93 posts
Re: Issue when updating table expire_date =NULL
« Reply #2 on: August 17, 2021, 09:39:23 AM »
The NULL becomes active automatically when the item expires.
In table items premium is set to 0 by cron and in item_sms_premium the date is set to NULL.
It is expired at that time and user receives email that premium is expired.
When user wants to renew ..... NULL does not change....... So what you are saying is that the item is not expired????
Why is it not visible anymore then after expire mail and set to 0 in items db?
I think this time your way of thinking is not correct.... Sorry
Why is this part of code in model if it is un-useful? : public function updateExpireByItemId( $item_id, $date = NULL ) {
« Last Edit: August 17, 2021, 10:24:56 AM by mwindey »

*

MB Themes

Re: Issue when updating table expire_date =NULL
« Reply #3 on: August 17, 2021, 10:44:03 AM »
@mwinedy
Your eyes are on wrong part of code.

Code: [Select]
function sp_change_premium( $item_id, $premium, $date = NULL) {
  ModelSP::newInstance()->updatePremiumByItemId( $item_id, $premium );                    // change b_premium in t_item table

  // CHANGE EXPIRATION
  $check = ModelSP::newInstance()->getExpire( $item_id );

  if( isset($check['expire_date']) && $check['expire_date'] <> '' ) {
    ModelSP::newInstance()->updateExpireByItemId( $item_id, $date );
  } else {
    ModelSP::newInstance()->insertExpireByItemId( $item_id, $date );
  }
}

I think in this case, you could do update like this.
Change line:
Code: [Select]
if( isset($check['expire_date']) && $check['expire_date'] <> '' ) {
Into:
Code: [Select]
if( isset($check['item_id']) && $check['item_id'] <> '' ) {
The problem you have is that first record (with NULL expire) is always returned as only record.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • ***
  • 93 posts
Re: Issue when updating table expire_date =NULL
« Reply #4 on: August 17, 2021, 11:30:18 AM »
@MB Themes

I need glasses for looking in the right place i think  :) :)
Still i was right saying that the NULL (empty field) gets created when premium ends....
I am using official download script without modification so i guess more people will have the issue later.
The solution you have given me now is PERFECT! Big thanks for that.....
Existing NULL tables are getting updated correctly now.
Super support so i will keep this in mind when reviewing in the future  ;)


*

MB Themes

Re: Issue when updating table expire_date =NULL
« Reply #5 on: August 17, 2021, 11:36:04 AM »
Cool, glad to hear that ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots