Jump to content

PS 1.7 - Shipping Cost mass set from value


Tintai
 Share

Recommended Posts

Hello everyone!

I'm in progress to open my e-shop, and got stuck in the shipping cost in products details.

So I'm using XML Importer Module to import my products, and one field is missing in the importer - additional shipping costs. Can't import this value from file. I'm working in dropshipping so it's an important value for me.

Anyway, I've got idea that I can import value of ship. cost to some other field in product and then replace value from that field to ship. costs field.

I'm using CRON few times daily so that switch operation must be done after CRON import my products updates.

How can I mass change value "additional_shipping_cost" from value "width"(they are not using in my shop so) .

I was thinking about a little php script added to CRON or maybe js. Was doing something before in C#, Python so not a beginner. Just need some help with example code or show me a good direction :)

 

Will be glad for help

Tintai

 

@Edit:

I've imported my shipping cost as "product_supplier_price_te". Now need to mass copy that to "additional_shipping_cost" field. But it seems to not appear in the shop when I put some value here. Also where is quantity of products in db? In ps_product and quantity tag is 0 for all products. But in backoffice every product has a stock.

Edited by Tintai (see edit history)

Share this post


Link to post
Share on other sites

11 hours ago, Tintai said:

Hello everyone!

I'm in progress to open my e-shop, and got stuck in the shipping cost in products details.

So I'm using XML Importer Module to import my products, and one field is missing in the importer - additional shipping costs. Can't import this value from file. I'm working in dropshipping so it's an important value for me.

Anyway, I've got idea that I can import value of ship. cost to some other field in product and then replace value from that field to ship. costs field.

I'm using CRON few times daily so that switch operation must be done after CRON import my products updates.

How can I mass change value "additional_shipping_cost" from value "width"(they are not using in my shop so) .

I was thinking about a little php script added to CRON or maybe js. Was doing something before in C#, Python so not a beginner. Just need some help with example code or show me a good direction :)

 

Will be glad for help

Tintai

 

@Edit:

I've imported my shipping cost as "product_supplier_price_te". Now need to mass copy that to "additional_shipping_cost" field. But it seems to not appear in the shop when I put some value here. Also where is quantity of products in db? In ps_product and quantity tag is 0 for all products. But in backoffice every product has a stock.

Hi,

additional_shipping_cost is in two tables:
ps_product and ps_product_shop.
The amount of product is in ps_stock_available.

The script for the Cron task is simple.
But you have to know how the products are imported, how they are paired.
Product code in XML = product reference in eshop?

What is the exact structure of XML?
Can you make the structure of one XML product available?

How big is XML in MB?
How many products are there?

Do you think it would not be better to modify the module?

Daniel

 

Edited by Guest (see edit history)

Share this post


Link to post
Share on other sites

Prestashop includes features for updating as needed.

Example:

$xml_reference = '123ABC456'; /* reference code in XML */
$xml_quantity = '777'; /* quantity in XML */
$xml_additional_shipping_cost = '24.85'; /* additional_shipping_cost in XML */

/* find product by reference */
$get_id_product = Db::getInstance()->getValue('SELECT id_product FROM '._DB_PREFIX_.'product WHERE reference = '.pSQL($xml_reference));

/* if product exists by reference */
if ($get_id_product) {
  $product = new Product((int)$get_id_product);
  $product->additional_shipping_cost = $xml_additional_shipping_cost;
  
  /* if no error update product and quantity in stock without attribute and shop id*/
  if ($product->update()) {
    Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'stock_available SET quantity = '.pSQL($xml_quantity).' WHERE id_product = '.$get_id_product.' AND id_product_attribute = 0');
  }

}

 

Share this post


Link to post
Share on other sites

5 hours ago, Guest said:

Product code in XML = product reference in eshop?

What is the exact structure of XML?
Can you make the structure of one XML product available?

How big is XML in MB?
How many products are there?

Thank you for replay.
XML i about 9MB and ~4000 products, so I would prefer to do this without XML. I have this data already at "ps_product_supplier\product_supplier_price_te"

 

6 hours ago, Guest said:

Do you think it would not be better to modify the module?

I bought this module and I have some update support so maybe yes, but when support time expires.

 

Anyway I'm try to do something like this and put in the CORN:

Can you help me with that code?

<?php

	$con=mysqli_connect("myhost","user","","pass") or die(mysqli_error());
	foreach ()// I need something here to look for all lines in ps_product_supplier
	{
        //Here I need to set new value for all my products. ID of products are same in all my tables but I need to match them, yes?
      
		//INSERT INTO ps_product (additional_shipping_cost)
      	//INSERT INTO ps_product_shop (additional_shipping_cost)
		//SELECT product_supplier_price_te
		//FROM ps_product_supplier
	}
?>
	

 

Many Thanks
Tinatai

Share this post


Link to post
Share on other sites

😁😉

I need to know where you will have the php file stored.

In the import module folder?

Share this post


Link to post
Share on other sites

Save this text eg as cron-weight.php and save it in the folder of your module.

./modules/my-import-module/cron-weight.php

Cron URL: https://my-shop.com/modules/my-import-module/cron-weight.php

<?php

    include_once('../../../config/config.inc.php');

    $get_supplier_product = Db::getInstance()->executeS('SELECT id_product, product_supplier_price_te FROM '._DB_PREFIX_.'product_supplier ORDER BY id_product');

    foreach ($get_supplier_product as $data) {
        $product = new Product ((int) $data['id_product']);
        $product->additional_shipping_cost = $data['product_supplier_price_te'];
        $product->update();
    } 


}

 

Share this post


Link to post
Share on other sites

52 minutes ago, Guest said:

😁😉

I need to know where you will have the php file stored.

In the import module folder?

All my CRON jobs are in "public_html/prestashop/presta/..."
cron-08.php with import jobs.
cron-0805.php for shipping cost update.

 

I put your code in my module folder and run through the web and nothing change. White page,.

Where is this "config.inc.php" file?

 

Thanks, you're a very helpfull 😋
Tintai

 

Share this post


Link to post
Share on other sites

Guys, this is perhaps a dream and very scary.
Read what I wrote you!
Put the file in the modules folder and the subfolder of the import module.
Enter the URL to the file in the Cron job on your hosting.
Done and without problems.
You do something and you put it somewhere it doesn't belong.
Give the information to your dev, or hire someone for the job.
Your problem would be solved in a few minutes.
My free time is not unlimited.

Share this post


Link to post
Share on other sites

My cron-weight.php is where you said.
Full path to this is file is: public_html/installer/presta/modules/importer/cron-weight.php

My server allows CRON by putting them only in public_html directory like:
cron-1805.php so at 18:05.

Inside it is:

<?php system('wget --delete-after --no-check-certificate http://myshop.eu/modules/importer/cron-weight.php'); ?>

 

And CRON jobs for importing products are working very well.

Thank you for your time. I'm grateful of every you second you help me.
Tintai

 

@Edit:

All my CRON jobs have a &token=xxxxx or &securekey=xxxx after link.

@Edit2:

Code is executing only to "$get_supplier_product = ...."
echo("test") before that is working but after is not.

Edited by Tintai (see edit history)

Share this post


Link to post
Share on other sites

Show errors in script:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

 

Share this post


Link to post
Share on other sites

Whatever I put in script is not executing.
At FireFox I see blank white page and Chrome throw "HTTP ERROR 500".

CRON is not executing too. I was trying wget and curl and still no change.

Maybe there is something wrong with my permissions but Config is 755 and config.inc.php - 644, corn-weight.php is also 644.
Was trying 777 and still no luck.

I will do a fresh start tomorrow.

Oh and there is no php.ini file in my server. Maybe this is the issue. I will search for that.

And thanks for your patience Guest, it's a new environment for me and things was going right until now where I'm stuck and have no idea where the problem is 🤔
Tintai

Share this post


Link to post
Share on other sites

You should have sent me access to the PM and everything would work for you 😄

Daniel

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More