lat9 / dbio

Database Input/Output for Zen Cart
GNU General Public License v3.0
3 stars 1 forks source link

Handler ProductsOptionsValue: Import of new Product Option Values #174

Closed torvista closed 3 years ago

torvista commented 4 years ago

I would have expected a import csv to need the product option id and the values texts and sort orders. I surmise that at present it is only possible to update the existing option values as the import demands the option value id, no import of new values?

lat9 commented 4 years ago

From the comments for the DbIoProductsOptionsValuesHandler:

For the import, the CSV must contain both the products_options_values_id and language_id fields, since those are used as the table's key-pair. An entry is updated if a database record is found that matches both fields; otherwise, the record is inserted using the specified language_id and a products_options_values_id that is calculated as the current table's maximum value (+1).

Usage Notes:

  1. When importing new records for a multi-language store, the import should be run once per language value. Otherwise, the products_options_id will get "out-of-sync" between the multiple languages.
  2. On an import: a. See if the products_options_values_id is 0. If so, force the import to be an insert. b. See if the associated language_id is, in fact, valid for the store. If not, the record's import will be denied.

Thus, to create a new option-value, simply set the v_products_options_values_id to 0 with a valid v_language_id. The option-values get 'bound' to their associated option via the ProductsAttribsBasic or ProductsAttribsRaw handlers' imports.

torvista commented 4 years ago

From the comments for the DbIoProductsOptionsValuesHandler:

Where is that?

lat9 commented 4 years ago

/YOUR_ADMIN/includes/classes/dbio/DbIoProductsOptionsValuesHandler.php

torvista commented 4 years ago

If I do an import for lang 1 and then an import for lang 2, they are loaded into the table sequentially: the products_options_values id for the first entry of lang2 is the next id after the last entry of lang1, instead of the same id as the first entry of lang1. If I do a single import of the two langs, they are sequential too.

lat9 commented 4 years ago

Arggh, languages! This gets complicated. You'll need to import (using v_products_options_values_id set to 0) an initial set so that the values' ids are created for one of the store's languages. Once the _ids are set, you'll use that now-assigned non-zero _id with an additional language_id for that next language.

torvista commented 4 years ago

ok, once I understood/read properly, I got the values into the table.

Now I would have thought there should be a step to associate those values with an id in the table products_options_values_to_products_options

But, from your description, I understood that this gets done on the import for a product. So I tried to import a ProductsAttribsRaw to a single product using the v_products_options_name as the option name and v_products_options_values_name as a list of the values:

GPX-A01^GPX-A02^GPX-A03^GPX-A04^GPX-A05^GPX-A06^GPX-A07^GPX-A08^GPX-A09^GPX-A10^GPX-A11^GPX-A12^GPX-A13^GPX-A14^GPX-A15^GPX-A16^GPX-A17^GPX-A18^GPX-A19^GPX-A20^GPX-A21^GPX-A22^GPX-A23^GPX-A24^GPX-A25^GPX-A26^GPX-A27^GPX-A28

thinking that would tie the option name and the values together.

But I got the error

Attributes not inserted at line number 2; one or more option-values.....were either not present in the default language or are not associated with the products_options_id of 16

Implying that there should be a prior association of option name to value?

torvista commented 4 years ago

Works. I note that on the import of the ProductsAttribsRaw csv, to add product attributes and create the Name-Value associations, if any of the three columns associated with downloads are present, (even though they are empty as from the export), empty entries are created in the products_attributes_download table, leading to these orphan displays:

Clipboard01

lat9 commented 3 years ago

I'll document the original 'conversation' for the ProductsOptionsValuesHandler and open a new issue to track the changes associated with that unwanted filename insertion.