1. brajput001
  2. RO CSVI
  3. Wednesday, 23 October 2019
  4.  Subscribe via email
We have a client who, for various reasons, needs two copies of their website (or more specifically their J2Store): one local version which runs on a computer in their physical store, and one live version which can be accessed over the internet. New products will only be added to the local version, but both versions should be able to independently process sales. The synchronization should happen automatically.

I think the synchronization problem splits into two subproblems:
1) Transfer new products: how do we transfer the new products from the local site to the live site, preferably without altering the state of any other product?
2) Synchronizing sales and inventory: how can we make sure that both websites have accurate records of sale and consistent inventories?

I think I have an idea of how to do #1. On the local site I want to export only those parts which have been created since the last New Parts Transfer. Then I want to look in the export file for all of the images' file paths, and for each path I copy the file located there to the live server via FTP, and then have the live server import the new parts. Can you tell me if RO CSVI is capable of only exporting/importing select files like that? Assuming this is possible, I think I mostly know how to automate each of these steps with scripts and cron jobs (or maybe even a button click).

Problem #2 seems much more complicated though, since if both sites change independently it's not clear to me how to amalgamate their states, and I don't want to accidentally lose track of sales or inventory. One possibility is to have the live site export its state whenever it changes and have the local site constantly watch the live site to see if it has a new export file, and if it does then download and import; conversely, whenever the local site's state changes it should upload its state to the live site and call an import command. This still doesn't seem satisfactory since a transaction on the local site and one on the live site could randomly happen within a minute of each other. Can you suggest a potential solution to this using RO CSVI?
Accepted Answer Pending Moderation
Hello,
I think I have an idea of how to do #1. On the local site I want to export only those parts which have been created since the last New Parts Transfer. Then I want to look in the export file for all of the images' file paths, and for each path I copy the file located there to the live server via FTP, and then have the live server import the new parts. Can you tell me if RO CSVI is capable of only exporting/importing select files like that? Assuming this is possible, I think I mostly know how to automate each of these steps with scripts and cron jobs (or maybe even a button click).

You can set the Export file of your local site to be saved on FTP of live server and import the file on live server from the placed location. That is fine but i am wondering how to differentiate the new products in local site so the export file has been created based on that. We do not have any such option to export products since last transfer.

Problem #2 seems much more complicated though, since if both sites change independently it's not clear to me how to amalgamate their states, and I don't want to accidentally lose track of sales or inventory. One possibility is to have the live site export its state whenever it changes and have the local site constantly watch the live site to see if it has a new export file, and if it does then download and import; conversely, whenever the local site's state changes it should upload its state to the live site and call an import command. This still doesn't seem satisfactory since a transaction on the local site and one on the live site could randomly happen within a minute of each other. Can you suggest a potential solution to this using RO CSVI?

With J2Store Order export there is an option of exporting orders from Last run. You can find this option in your export template under Options tab and under Date range field. This option will export orders which have not been included in your last export and are new. You can use this state in both of your sites and export files and import them. Let me know if this solutions helps.
Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory
  1. more than a month ago
  2. RO CSVI
  3. # 1
Accepted Answer Pending Moderation
Hello,

I would like to give some input on point 2. There is no perfect solution here. If you do not designate a single point of truth, all you can hope for is mercy ;) If both the webshop and the POS update the stock for the same product, you sync that data, there is basically a conflict, who wins? The client needs to decide then what to do in that case. The software is not going to know what to do, it can only update one way or another.

This is not only an issue for inventory as you state you want to sync orders too. How to deal with order IDs? They shouldn't overlap either. I think they are making it way more difficult for themselves by maintaining 2 separate sites and syncing it all up as compared to have a single site used by both the live site and the POS.
Kind regards,

RolandD

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory
  1. more than a month ago
  2. RO CSVI
  3. # 2
Accepted Answer Pending Moderation
Thank you for your answers.

For exporting only new items, I was wondering is it possible to give the From Date as an argument when using a template from the command line? If so then I could have a script which maintains a "last export" date and uses this date as an argument for a New Parts Export template. Or alternatively, Tharuna suggested a "since last run" option for J2Store Orders, could I also just use this option for products?

As for the second problem, it does sound like there's no perfect solution. However, our client wants to use a Quickbooks extension to keep track of sales, so maybe if both websites are forwarding their data to the Quickbooks account, that could solve the issue of keeping sales in order. Then we still have to keep track of inventory, but there are actually only a few parts which have inventory enabled and the quantity is only ever either "1" or "0". Our idea is to have the client manually approve those orders, so that if they find a conflict on the two websites they can manually fix it. Do you see anything wrong with these strategies?
  1. more than a month ago
  2. RO CSVI
  3. # 3
Accepted Answer Pending Moderation
Hello,
For exporting only new items, I was wondering is it possible to give the From Date as an argument when using a template from the command line? If so then I could have a script which maintains a "last export" date and uses this date as an argument for a New Parts Export template. Or alternatively, Tharuna suggested a "since last run" option for J2Store Orders, could I also just use this option for products?

We do not have "Since last run" option in product export. That is only with order export template. What you can do is using from date and with some custom coding in J2Store Product export you can change the query to export the rows from the given date. You can then set this as an override for J2Store product export.

As for the second problem, it does sound like there's no perfect solution. However, our client wants to use a Quickbooks extension to keep track of sales, so maybe if both websites are forwarding their data to the Quickbooks account, that could solve the issue of keeping sales in order. Then we still have to keep track of inventory, but there are actually only a few parts which have inventory enabled and the quantity is only ever either "1" or "0". Our idea is to have the client manually approve those orders, so that if they find a conflict on the two websites they can manually fix it. Do you see anything wrong with these strategies?

I don't know how Quickbooks extension works but the way you explain it seems like it is one place to keep all the sales from both your live and local sites and should have no conflicts with orders.
Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory
  1. more than a month ago
  2. RO CSVI
  3. # 4
Accepted Answer Pending Moderation
Hi Thruna, thank you for referring me to the overriding tutorial. I made a file called "<website root>/administrator/templates/isis/html/com_csvi/com_j2store/model/export/productcustom.php" and made the necessary changes, then around line 335 I added the following:
$file_name = JPATH_SITE . "/exports/NewParts/last_run.txt";
$last_run = strtotime(file_get_contents($file_name));
$date = date("Y-m-d H:i:s", $last_run);
$query->where('j2store_products.created_on > ' . $this->db->quote($date));

I put the string "2019-10-24 00:00:00" into the last_run.txt file, and the override correctly exported only those items created since October 24. Then after the export actually occurs I added the following (around line 764):
$date = date("Y-m-d H:i:s");
file_put_contents($file_name, $date);

so that it saves the current datetime as the "last run" data. As far as I can tell, this export template is doing what I want it to be doing.


One thing I still need to sort out is the file name of the export file. I want to add the datetime information to the file name so the system doesn't accidentally overwrite anything, but when i follow the link in the administrator "Help" text (https://rolandd.com/support/questions-and-answers/220-virtuemart/714-customizing-the-export-filename) it just brings me to the main support page with all of the questions. Is there an up-to-date link for a tutorial on this?
  1. more than a month ago
  2. RO CSVI
  3. # 5
Accepted Answer Pending Moderation
Hello,
Glad to know that your issue is solved with the override file.

Is there an up-to-date link for a tutorial on this?

Yes, please have a look at document link here.
Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory
  1. more than a month ago
  2. RO CSVI
  3. # 6
Accepted Answer Pending Moderation
Thank you Tharuna, that works perfectly.

I think the New Products Transfer part of the project is more or less sorted out, but I'm still working out some details for the Inventory Synch part. Here's my plan:

- There will be a J2Store plugin that listens for an inventory decrease, and when that happens it makes a record in some file called "changed.txt" that the state has changed, and both copies of the site will have this plugin installed.

- The local server will regularly run a Synch Event. It will check both copies to see if either of them have had a state change, and then implement the following pseudocode:
if (live server has changed state) {
local server tells live server to export and downloads export file;
local server imports file;
local server deletes the downloaded file;
else if (local server has changed state) {
local server exports to live server;
live server imports file;
live server deletes uploaded file;
}
local server resets the changed.txt files on both servers;

In the case that both servers have changed state, the algorithm prefers the state of the live server.

My problem is that I know how to run a template with a bash script, but I think this algorithm will have some logic that I don't know how to do in bash and that I would like to do in PHP instead. Is it possible to run templates in a PHP script?
  1. more than a month ago
  2. RO CSVI
  3. # 7
Accepted Answer Pending Moderation
Hello,
My problem is that I know how to run a template with a bash script, but I think this algorithm will have some logic that I don't know how to do in bash and that I would like to do in PHP instead. Is it possible to run templates in a PHP script?

You cannot run template directly using PHP Script. You can create a template as a Frontend import/export template and call this URL using Curl using PHP script.
Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory
  1. more than a month ago
  2. RO CSVI
  3. # 8
Accepted Answer Pending Moderation
Hello Tharuna, I am succeeding in running export templates using curl, with the following PHP code:
$cSession = curl_init();
curl_setopt($cSession, CURLOPT_URL, <template_url>;);
curl_setopt($cSession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cSession, CURLOPT_HEADER, true);
$result = curl_exec($cSession);
curl_close($cSession);
if ($result === false) {
echo 'Curl error: ' . curl_error($cSession) . "\n";
return false;
}
echo $result;


However, I'm getting an error when running an import template. I can get the template to work by visiting the link in a browser, but when I run the above code or try to curl from Terminal I get the following response:
<html><head><title>Error 406 - Not Acceptable</title><head><body><h1>Error 406 - Not Acceptable</h1><p>Generally a 406 error is caused because a request has been blocked by Mod Security. If you believe that your request has been blocked by mistake please contact the web site owner.</p></body></html>

I have administrator access to the site and most of the server, but I don't know how to fix this problem. What do I have to do to make my request acceptable?

I attached one of the log files from the attempted import and the xml for the template
Attachments (2)
  1. more than a month ago
  2. RO CSVI
  3. # 9
Accepted Answer Pending Moderation
Hello,
The log file attached is empty so nothing to check in there. Mod security is the firewall installed on your site by your host to avoid vulnerabilities. From the error message it looks like this firewall is blocking CSVI import. You may check with your hosting provider on this issue.
Kind regards,

Tharuna

=========================
If you use our extensions, please post a rating and a review at the Joomla! Extension Directory
  1. more than a month ago
  2. RO CSVI
  3. # 10
  • Page :
  • 1


There are no replies made for this post yet.
Be one of the first to reply to this post!