SilverCart Forum

We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?

You can help us helping you by providing detailed error messages, screenshots and logfile entries.

SebastianRamon

Page: 1
Topic Exporting/importing graduated prices 2697 Views

Exporting/importing graduated prices

11 February 2013 at 11:34pm

Hi,

I am just starting to experiment with importing CSV files and this is great facility. I have added extra fields to the Product (e.g., BrandingOptions) and have been able to import this information back in via CSV files.

Is there a way of importing graduated prices for a Product from a CSV file? If so, what are the field names/format?

Similarly, how do I associate Variations with a Product when importing a CSV file?

Regards,

Graeme

Re: Exporting/importing graduated prices

14 February 2013 at 9:52am

Hello Graeme,

currently there's no standard way to export graduated prices or product variant information.

You could solve this by using callback fields. Here's a short how to:

1) Configure the product export admin

Assuming your product exporter has the name "MyCustomExport".
Add a callback field with the name "GraduatedPrice".

2) Adjust the code

In the folder "silvercart/code/product/exporters/" there's a file called "SilvercartProductExporter_Froogle.php"; duplicate that file and call it "SilvercartProductExporter_MyCustomExport.php" (naming scheme is always "SilvercartProductExporter_{ExporterName}.php").

Edit the file and change it's class name to "SilvercartProductExporter_MyCustomExport".

Add the method "GraduatedPrice" to the class:

public function GraduatedPrice($record) {
$silvercartProduct = DataObject::get_by_id('SilvercartProduct', $record['ID']);
$graduatedPrices = $silvercartProduct->SilvercartGraduatedPrices();

// Format the graduated prices as string as you need and return it
}

The callback field you defined in the admin area will call this method. So you can format the graduated prices as needed and return them as a string.

Remember to do a "dev/build?flush=all", so the new class gets registered.
For the variant informations you could add another callback field and appropriate method.

I hope this helps a bit :)

All the best,
Sascha

Re: Exporting/importing graduated prices

18 March 2013 at 8:37am

Hi Sascha,

Sorry for taking so long to reply to this.I have got the export working, but I am having difficulty getting the graduated prices formatted as a string. I can get the graduatedPrice output using print_r but this includes a lot more information than I need.

Ideally I really only need the minumumQuantity and the Price associated. No doubt it is relatively straightforward but it is more than my limited PHP can handle.

Any pointers would be appreciated.

Regards,

Graeme

Re: Exporting/importing graduated prices

19 March 2013 at 9:35am

Hello Graeme,

to get that information you could do the following:

public function GraduatedPrice($record) {
$silvercartProduct = DataObject::get_by_id('SilvercartProduct', $record['ID']);
$graduatedPrices = $silvercartProduct->SilvercartGraduatedPrices();
$priceStr = '';

if ($graduatedPrices) {
foreach ($graduatedPrices as $graduatedPrice) {
$priceStr .= $graduatedPrice->minimumQuantity.' -> '.$graduatedPrice->price->Nice().'#';
}
}

return $priceStr;
}

This should give you the graduated prices for a product in the format

{MinimumQuantity} -> {Price}#{MinimumQuantity} -> {Price}#{MinimumQuantity} -> {Price}#...

I hope this helps a bit :)

Greetings,
Sascha

Re: Exporting/importing graduated prices

19 March 2013 at 10:09pm

Hi Sascha,

Works perfectly—thanks.

Do I need to write a custom CSV import function to bring the Graduated Price information back in once I change it?

Regards

Graeme

Re: Exporting/importing graduated prices

20 March 2013 at 2:40pm

Hi Graeme,

yes you'll need a custom import function for that.

Greetings,
Sascha