WordPress.org

Ready to get started?Download WordPress

Forums

Store Locator Plus
Adding extra fields in Locations (2 posts)

  1. stalvatero
    Member
    Posted 1 year ago #

    Hi,
    please i need an help.
    i'm triyng to add some extra fieds in Locations made by simple input text and checkboxes.

    I now that is not suggested to change core files, but i need to personalized SLP.

    Managed to modify the files:
    add_location_address.php
    edit_location_address.php
    and of course adding my desired field in MySql Table store_locator

    i've inserted my own text input fields with no problem, and i'm ablle to add and edit data.

    My problems comes with checkboxes as '0' and '1' values. No problem to INSERT or UPDATE db values when i check the box to write '1' in db. But if i uncheck a box in edit mode, i cannot write '0' in db, so i cannot uncheck value.

    i tryed with something like:

    $query = sprintf("UPDATE " . $wpdb->prefix ."store_locator " . "SET sl_r_accinf = '0' WHERE sl_id NOT IN ()";

    but nothig happen.
    Can you help me solving this MY problem?
    Thanks in advance.

    http://wordpress.org/extend/plugins/store-locator-le/

  2. Charleston Software Associates
    Member
    Plugin Author

    Posted 1 year ago #

    I suggest you use the hooks & filters that do just this, available since version 3.5. This way you can create your own plugin in a separate directory that will not be overwritten when upgrading and still interacts with SLP. Enhanced Search is a small version of a plugin that does just this. Tagalong is a more extensive plugin that uses a lot of the tricks you will want to mimic. It should be out later this month.

    http://www.charlestonsw.com/support/documentation/technical-documentation/store-locator-plus/add-on-packs-roll-your-own/

    Store the data in a serialized named array in sl_option_value (a new field since 3.5) using the data filter and setting the sl_option_value similar to this:

    // Manage Locations Interface
                //
                add_filter('slp_manage_location_columns',
                        array($this, 'add_categories_column')
                        );
    
                add_filter('slp_column_data',
                        array($this, 'render_categories_column'),
                        90,
                        3
                        );
                add_filter('slp_edit_location_right_column',
                        array($this,'location_edit_category')
                        );
                add_filter('slp_update_location_data',
                        array($this,'location_update_data'),
                        90,
                        2
                        );
    
            /**
             * Attach our category data to the update string.
             *
             * Put it in the sl_option_value field as a seralized string.
             *
             * @param string $sqlSetStr - the original SQL set syntax
             * @return string - the modified SQL set syntax
             */
            function location_update_data($sqlSetStr,$locationID) {
                if (isset($_POST['tax_input'])) {
                    $originalOptionArray = slp_deserialize_to_array($_POST['option_value-'.$locationID]);
                    $newOptionArray =
                        array_merge($originalOptionArray,
                                    array(
                                        'store_categories' => $_POST['tax_input']
                                    )
                        );
               }
                $sqlSetStr = preg_replace("/, sl_option_value='(.*?)'/",'',$sqlSetStr);
                return $sqlSetStr.", sl_option_value='".maybe_serialize($newOptionArray)."'" ;
            }
    
            /**
             * Add the category editor/selector on the manage/edit location form.
             *
             * @param string $theForm - the original HTML form for the manage locations edit (right side)
             * @return string - the modified HTML form
             */
            function location_edit_category($theForm) {
                ob_start();
                wp_terms_checklist(
                            0,
                            array(
                                'checked_ontop' => false,
                                'taxonomy' => 'stores',
                            )
                        );
                $checkList = ob_get_contents();
                ob_end_clean();
    
                $theForm .= '<div id="slp_tagalong_categories"><strong>Tagalong</strong>'.
                        $checkList .
                        '</div>';
                return $theForm;
            }
    
            /**
             * Add the categories column to the manage locations table.
             *
             * @param named array $currentCols - column name + column label for existing items
             * @return named array - column name + column labels, extended with our categories data
             */
            function add_categories_column($currentCols) {
                return array_merge($currentCols,
                        array(
                            'sl_option_value'       => __('Categories'        ,SLPLUS_PREFIX)
                        )
                    );
    
            }
    
            /**
             * Render the categories column in the view locations table.
             *
             * @param string $theData  - the option_value field data from the database
             * @param string $theField - the name of the field from the database (should be sl_option_value)
             * @param string $theLabel - the column label for this column (should be 'Categories')
             * @return type
             */
            function render_categories_column($theData,$theField,$theLabel) {
                if (
                    ($theField === 'sl_option_value') &&
                    ($theLabel === __('Categories'        ,SLPLUS_PREFIX))
                   ) {
    
                    // No Category selected
                    //
                    if ($theData != '') {
                        $OptionArray = slp_deserialize_to_array($theData);
                        if (isset($OptionArray['store_categories']['stores'])){
                            $theData = '';
                            foreach ($OptionArray['store_categories']['stores'] as $optVal) {
                                $theCat = get_term($optVal,'stores');
                                $tagalongData = get_option(SLPLUS_PREFIX.'-TAGALONG-category_'.$theCat->term_id);
                                $theData .= '<div class="tagalong_entry">'.$theCat->name;
                                if (isset($tagalongData['map-marker']) && ($tagalongData['map-marker']!='')) {
                                    $theData .=
                                        '<img src="'.$tagalongData['map-marker'].'" '.
                                            'id="slp_map_marker_'.$theCat->slug.'" '.
                                            'class="slp_map_marker" '.
                                            'alt="'.$theCat->slug.'" '.
                                            'title="'.$theCat->slug.'"/>'
                                        ;
                                }
                                $theData .= '</div>';
    
                                //$theData .= '<pre>'.print_r($theCat,true).'</pre>';
                                //$theData .= '<pre>'.print_r($tagalongData,true).'</pre>';
                            }
                        }
                    }
                }
                return $theData;
            }

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.