Jump to content

Check availability on another page and show next to the product


janeklass

Recommended Posts

13 minutes ago, ps8moduly.cz said:

Hi, as far as Prestashop is concerned, it's not a problem.
As for the dealer, no information is known.
Do you have any API access from the dealer? Can you only get quantities of one product?
Do dealer update availability often?

I have access to the xml file that the dealer keeps updating. The file contains prices, quantities, product id (code assigned to the product). Is presta able to check this file regularly and automatically update my quantities?

Link to comment
Share on other sites

Hi, yes it is possible.
All you need is either a mini module or a custom script that detects the product ID based on the reference code and updates the quantity. You set a regular Cron task on your server (web hosting) (perhaps every hour).
If there are more products, you need to adjust the update to several parts before the max_execution_time expires.

For an average programmer, it's a maximum of half an hour's work 😉

It is necessary to know the XML structure in advance, whether it contains combinations, etc.

 

 

Link to comment
Share on other sites

Sample script "quantityUpdate.php"

  /* CRON SAMPLE : * 3 * * * /path_to_script/quantityUpdate.php token=A1b2C3 */
  /* XML sample */
  /* 
    <products>
      <product reference="12345" quantity="10" />
      <product reference="67890" quantity="20" />
    </products>
  */
  header("Access-Control-Allow-Origin: *");

  include('./config/config.inc.php');
  include('./init.php');

  $urlToken = '';

  $db = Db::getInstance();

  if ($argv){
    parse_str($argv[3], $params);
    $urlToken = $params['token'];  
  }

  $token = 'A1b2C3';

  if ($token == $urlToken) {
    $context = stream_context_create( array( 'http' => array( 'follow_location' => false ) ) ); 
    $content = file_get_contents('https://sample.com/test.xml', false, $context);

    $products = new SimpleXMLElement($content);

    foreach($products as $p)
    {
      $getIdProduct = $db->getValue('SELECT id_product FROM '._DB_PREFIX_.'product WHERE reference = \''.$p['reference'].'\''); 

      if ($getIdProduct) {
        StockAvailable::setQuantity((int)$getIdProduct, 0, (int)$p['quantity']);
      }

    }

  }

 

Link to comment
Share on other sites

7 hours ago, ps8moduly.cz said:

Sample script "quantityUpdate.php"

  /* CRON SAMPLE : * 3 * * * /path_to_script/quantityUpdate.php token=A1b2C3 */
  /* XML sample */
  /* 
    <products>
      <product reference="12345" quantity="10" />
      <product reference="67890" quantity="20" />
    </products>
  */
  header("Access-Control-Allow-Origin: *");

  include('./config/config.inc.php');
  include('./init.php');

  $urlToken = '';

  $db = Db::getInstance();

  if ($argv){
    parse_str($argv[3], $params);
    $urlToken = $params['token'];  
  }

  $token = 'A1b2C3';

  if ($token == $urlToken) {
    $context = stream_context_create( array( 'http' => array( 'follow_location' => false ) ) ); 
    $content = file_get_contents('https://sample.com/test.xml', false, $context);

    $products = new SimpleXMLElement($content);

    foreach($products as $p)
    {
      $getIdProduct = $db->getValue('SELECT id_product FROM '._DB_PREFIX_.'product WHERE reference = \''.$p['reference'].'\''); 

      if ($getIdProduct) {
        StockAvailable::setQuantity((int)$getIdProduct, 0, (int)$p['quantity']);
      }

    }

  }

 

Ok, looks interesting :D But I'm not a programmer and I don't use this code.
What is the price of an average programmer for a job like this? :D
Is this control applied to each product separately?
If I add new products, is it easy for me to use this code or does it require some special knowledge?
How is such code used in the presta back office?

Link to comment
Share on other sites

Hi, the average price of a programmer (not an agency) is on average €45 for every hour started.

The time to create the update script depends on many factors that are not yet known.
1. Vendor XML size
2. the complexity of the XML structure
3. number of items to update
4. combination
5. max_execution_time seever parameters
6. matching according to the supplier's reference

There is no need to build an extra module for administration.

Valid on existing and matchable products only.

Link to comment
Share on other sites

4 minutes ago, ps8moduly.cz said:

Hi, the average price of a programmer (not an agency) is on average €45 for every hour started.

The time to create the update script depends on many factors that are not yet known.
1. Vendor XML size
2. the complexity of the XML structure
3. number of items to update
4. combination
5. max_execution_time seever parameters
6. matching according to the supplier's reference

There is no need to build an extra module for administration.

Valid on existing and matchable products only.

OK, but when I add new products - Is it easy for me to apply this script to a new product or do I have to hire a programmer for each new product :D

Link to comment
Share on other sites

8 minutes ago, ps8moduly.cz said:

I will answer with a question.
Is the new product in XML from the supplier?
Yes = updating
No = not updated

The script goes through all the products in XML from the supplier.

Do you have multiple suppliers?

Yes, I have several suppliers, but only one has information in xml form. So it would be necessary to check the products of this one supplier.

I enter new products manually. I just need the quantities to update automatically after entering.

Link to comment
Share on other sites

7 minutes ago, ps8moduly.cz said:

If you enter them manually, do you also enter the reference code from the supplier?

Yes, I use the referral code. I don't know if I put it in the right place (I put it in the MPN box), but putting it in the right place wouldn't be a problem.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...