Zen Cart Logo
Forums / General Questions / Data Available - Make stock available mod , does it exist ?

Data Available - Make stock available mod , does it exist ?

Views: 552

Results 1 to 4 of 4
18 Jun 2016, 3:32 PM
#1
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Data Available - Make stock available mod , does it exist ?

Hi
I'm using the a mix of date available + publishing date from bookx module... but more or less it's the same.
So the upcoming books or products have a stock 0 .
Is there already some kind of module that does this automatically ?

And if not, is this a routine checking that it's better to do on the admin or in the "front" code ?

Thanks

18 Jun 2016, 3:41 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Data Available - Make stock available mod , does it exist ?

mesnitu:

Hi
I'm using the a mix of date available + publishing date from bookx module... but more or less it's the same.
So the upcoming books or products have a stock 0 .
Is there already some kind of module that does this automatically ?

And if not, is this a routine checking that it's better to do on the admin or in the "front" code ?

Thanks

Are you asking if there is something that will make a product available based on date?

There is code in ZC that already does something similar (on front end) for things like specials and sales. It could be "extended" to work with other such dates.

18 Jun 2016, 4:00 PM
#3
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: Data Available - Make stock available mod , does it exist ?

Thanks.
Yes, it's something like that.
I mean, there are shops and shops....ones work with real stocks, others dont.
In this shop, the stocks are controled by the Sage software, but they are not sincronize with the online shop.....that something that I would like to do in EP4 , mapping the fields....
Well, anyway, to say, that this is cool for shops that don't have those "real" stocks.
The day comes, a some stock is added to the product.
Got to check that code to see if I van make this happen
Thanks

19 Jun 2016, 7:35 PM
#4
mesnitu avatar

mesnitu

Totally Zenned

Join Date:
Aug 2014
Location:
Lisbon
Posts:
597
Plugin Contributions:
0

Re: Data Available - Make stock available mod , does it exist ?

well, to anyone that might find this usefull
I've override the file init_special_func and added this to the IF :

if (!isset($_SESSION['updateExpirations']) || $_SESSION['updateExpirations'] !== true) {

require(DIR_WS_FUNCTIONS . 'upcoming_expire.php');
zen_expire_upcoming();

Then created a new function file upcoming_expire.php with

function zen_update_upcoming_status($upcoming_id) {
    global $db;
    $sql = "update " . TABLE_PRODUCTS . "
            set products_quantity = '100'
            where products_id = '" . (int)$upcoming_id . "'";

    return $db->Execute($sql);
   }

  function zen_expire_upcoming() {
    global $db;
    $today = $_SESSION['today_is'];
   
    $upcoming_query = "select p.products_id
                       from " . TABLE_PRODUCTS . " p 
                       LEFT JOIN ".TABLE_PRODUCT_BOOKX_EXTRA." be on p.products_id = be.products_id
                       where p.products_status = '1' AND p.products_quantity = '0' 
                       and ((" . $today . " <=  be.publishing_date and be.publishing_date != '0000-00-00 00:00:00')
                       or (" . $today. " <= p.products_date_available and p.products_date_available != null))";

    $upcoming = $db->Execute($upcoming_query);

    if ($upcoming->RecordCount() > 0) {
      while (!$upcoming->EOF) {
        zen_update_upcoming_status($upcoming->fields['products_id']);
        $upcoming->MoveNext();
      }
    }
  }

In this case I'm using a bookx module. For a normal product, I guess this is enough

function zen_expire_upcoming() {
    global $db;
    $today = $_SESSION['today_is'];
   
    $upcoming_query = "select p.products_id
                       from " . TABLE_PRODUCTS . " p 
                       
                       where p.products_status = '1' AND p.products_quantity = '0' 
                       
                       and (" . $today. " <= p.products_date_available and p.products_date_available != null))";

    $upcoming = $db->Execute($upcoming_query);

    if ($upcoming->RecordCount() > 0) {
      while (!$upcoming->EOF) {
        zen_update_upcoming_status($upcoming->fields['products_id']);
        $upcoming->MoveNext();
      }
    }
  }

And I'm also hardcoding the 100 for a stock.