F
F
foxayb2020-05-28 14:55:40
WordPress
foxayb, 2020-05-28 14:55:40

How to download product characteristics for further filtering?

There is an xml-file with the product name, price and characteristics. Massively using the wp all import plugin , I load the characteristics as attributes, but in the end, not all are created.

The problem is that some property names contain more than 28 characters and the import plugin limits and gives an error. The option is to remove these restrictions in the plugin through the code, it does not fit, it starts to duplicate attributes.

Tell me, are there any other options? All this is necessary to further filter the characteristics.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
foxayb, 2020-06-10
@foxayb

Who cares - I implemented the following solution
: the plugin " WP All import " must be used in conjunction with another plugin " WooCommerce Add-On Pro ", respectively, it is responsible for loading the attributes and limits them to 28 cm. in the slug, then in the /wp-content/plugins/wpai-woocommerce-add-on/libraries/services/XmlImportWooTaxonomyService.php file, in the public function createTaxonomy($attr_name, $prefix = 1) (72 line) you need to write the following :

spoiler
/**
     *
     * Create new taxonomy.
     *
     * @param $attr_name
     * @param int $prefix
     * @return string
     */
    public function createTaxonomy($attr_name, $prefix = 1) {
    $attr_name_fix = $attr_name; //зафиксил
    $attr_name = substr($attr_name, 0, 27);  //обрезал имя
        $attr_name_real = $prefix > 1 ? $attr_name . " " . $prefix : $attr_name;
        $attribute_name = wc_sanitize_taxonomy_name( stripslashes( (string) $attr_name_real ) );
    
  //	$bsk = rand(10,999);
    $attribute_name = substr($attribute_name, 0, 27);  //обрезал url
    
        $args = array(
            'attribute_label'   => stripslashes( (string) $attr_name_fix ), //применил фикс к лейблу
            'attribute_name'    => $attribute_name,
            'attribute_type'    => 'select',
            'attribute_orderby' => 'menu_order',
            'attribute_public'  => 1
        );


        if ( ! taxonomy_exists( wc_attribute_taxonomy_name( $attr_name_real ) ) ) {
            if ( in_array( wc_sanitize_taxonomy_name( stripslashes( (string) $attr_name_real)), $this->reserved_terms ) ) {
                $prefix++;
                return $this->createTaxonomy($attr_name, $prefix);
            }
            else {
                // Register the taxonomy now so that the import works!
                $domain = wc_attribute_taxonomy_name( $attribute_name );
                if (strlen($domain) < 31){
                    register_taxonomy( $domain,
                        apply_filters( 'woocommerce_taxonomy_objects_' . $domain, array('product') ),
                        apply_filters( 'woocommerce_taxonomy_args_' . $domain, array(
                            'hierarchical' => true,
                            'show_ui' => false,
                            'query_var' => true,
                            'rewrite' => false,
                        ) )
                    );
                    $this->createWooCommerceAttribute($args);
                    $this->getLogger() and call_user_func($this->getLogger(), sprintf(__('- <b>CREATED</b>: Taxonomy attribute “%s” have been successfully created.', \PMWI_Plugin::TEXT_DOMAIN), wc_attribute_taxonomy_name( $attribute_name )));
                }
                else {     				
          $this->getLogger() and call_user_func($this->getLogger(), sprintf(__('- <b>WARNING</b>: Taxonomy “%s” name is more than 28 characters. Change it, please.', \PMWI_Plugin::TEXT_DOMAIN), $attr_name));
        }
            }
        }
        else {
            if ( in_array( wc_sanitize_taxonomy_name( stripslashes( (string) $attr_name_real)), $this->reserved_terms ) ) {
                $prefix++;
                return $this->createTaxonomy($attr_name, $prefix);
            }
        }

        if (!wc_attribute_taxonomy_id_by_name($attr_name_real) && strlen($attribute_name) < 31) {
           $this->createWooCommerceAttribute($args);
        }

        return $attr_name_real;
    }

at the output, we will get the following effect: when importing, all attributes that have a name of more than 27 characters will be cut off in the slug (url), which will allow everything to be successfully imported, and the names will retain their length.

W
WP Panda, 2020-05-28
@wppanda5

No way, in the base there is a limit of 32 characters, taking into account the prefix added by WooCommerce, it turns out like 29 characters in general, but in woo they set a limit of 28

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question