If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / Code Collaboration / how is this beta addon idea?

how is this beta addon idea?

Started by bumba000 on 21 Dec 2014, 11:53 PM · Views: 15,799

Results 21 to 27 of 27
22 Dec 2014, 7:33 AM
#21
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
862
Plugin Contributions:
0

Post #21 by bumba000

also, where I use if(!$listing->EOF && $_GET['main_page'] == 'index'){ in the modules/sideboxes file does work if your side box is a left box which appears before the product listing happens.

I'm guessing that you activated as right box?

On second thought that doesn't sound quite right. I'm just grabbing at straws here trying to understand why that statement wouldn't work for you and your statements don't work for me.

22 Dec 2014, 3:53 PM
#22
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #22 by drbyte

bumba000:

also, where I use if(!$listing->EOF && $_GET['main_page'] == 'index'){ in the modules/sideboxes file does work if your side box is a left box which appears before the product listing happens.

I'm guessing that you activated as right box?
Yes, I did activate it as a right-sidebox, which does explain why EOF is reached.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

23 Dec 2014, 6:45 PM
#23
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
862
Plugin Contributions:
0

Post #23 by bumba000

Need a hand with this query please. I am trying to join up the pa table where the product is priced by attributes. However, no products that are priced by attributes are being returned. I have no errors and warnings.

        $listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, p.products_priced_by_attribute, pd.products_description, pd.products_special_data, 
        IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, 
        IF(p.products_priced_by_attribute = 1, pa.options_values_price,
            IF(s.status = 1, s.specials_new_products_price, p.products_price)
        ) as final_price, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
          from " . TABLE_PRODUCTS . " p 
          left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id           
          left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa on p.products_id = pa.products_id, " . 
          TABLE_PRODUCTS_DESCRIPTION . " pd, " .
          TABLE_MANUFACTURERS . " m, " .
          TABLE_PRODUCTS_TO_CATEGORIES . " p2c
          where p.products_status = 1
            and p.manufacturers_id = m.manufacturers_id
            " . $and . "
            and p.products_id = p2c.products_id
            and pd.products_id = p2c.products_id
            and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
            and p2c.categories_id = '" . (int)$current_category_id . "'" .
            $alpha_sort;
23 Dec 2014, 7:26 PM
#24
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Post #24 by mc12345678

What is in the variable $and that is included in the where clause?

And when inspecting the result of running the query, p.products_priced_by_attribute is always set to 0?

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

23 Dec 2014, 7:38 PM
#25
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
862
Plugin Contributions:
0

Post #25 by bumba000

No, the p.products_priced_by_attribute is either 0 or 1.

The $and...
$and = '';
$and .= " and p.products_price >= ".$loHiParts[0];
$and .= " and p.products_price <= ".$highPrice;
$and .= " and m.manufacturers_id IN (". implode(',', $manu_arr_flt) . ")";

Which I think helps explain the problem as I see what might be happening.

First I'm running some IF's to set up the $and. Then build the query dropping the $and in near the end. So how then can I make " and p.products_price ..." change from " and p.products_price " to " and pa.options_value " ?

23 Dec 2014, 7:45 PM
#26
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
862
Plugin Contributions:
0

Post #26 by bumba000

That Did IT!!

 if (isset($_GET['jfilter']) && zen_not_null($_GET['jfilter'])) {
            
        $and = '';
        $orderby = '';
        if(isset($_GET['jpricelohi']) && zen_not_null($_GET['jpricelohi'])){
            $loHiParts = explode('_',$_GET['jpricelohi']);
            if(isset($loHiParts[0]) && zen_not_null($loHiParts[0])){
                $highPrice = $loHiParts[1] + 1;
                $and .= " and if(p.products_priced_by_attribute, pa.options_values_price, p.products_price) >= ".$loHiParts[0];
            }
            if(isset($loHiParts[1]) && zen_not_null($loHiParts[1])){
            //incase the orig price has cents and we are using dollar amount
            //need to adjust 
                $highPrice = $loHiParts[1] + 1;
                $and .= " and if(p.products_priced_by_attribute, pa.options_values_price, p.products_price) <= ".$highPrice;
            }
        }
        if(isset($cleanJpManus) && zen_not_null($cleanJpManus)){
        /*    $manu_id_string = '';
            foreach($cleanJpManus as $manu_arr_flt){
            
            $manu_id_string .= $manu_arr_flt.',';
            }
            $manu_id_string = rtrim($manu_id_string, ',');
            $and .= " and m.manufacturers_id IN (".$manu_id_string . ")";
        */
            $manu_arr_flt = array();
            foreach($_GET as $key => $value){
                if(preg_match('/^jparam_manu/', $key)){
                    $manu = preg_replace('/[^0-9]/', '', $value);
                    if ($manu != '')
                    {
                        $manu_arr_flt[] = $manu;
                    }
                }
            }
            if (sizeof($manu_arr_flt)) {
                $and .= " and m.manufacturers_id IN (". implode(',', $manu_arr_flt) . ")";
            }
        }
        
        //set $_GET['sort'] 7a or 7d for Price sort
        
        
    // We are asked to show only specific category
         $listing_sql = "select " . $select_column_list . " p.products_id, p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, p.products_priced_by_attribute, pd.products_description, pd.products_special_data, 
        IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, 
        IF(p.products_priced_by_attribute = 1, pa.options_values_price,
            IF(s.status = 1, s.specials_new_products_price, p.products_price)
        ) as final_price, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
          from " . TABLE_PRODUCTS . " p 
          left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id           
          left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa on p.products_id = pa.products_id, " . 
          TABLE_PRODUCTS_DESCRIPTION . " pd, " .
          TABLE_MANUFACTURERS . " m, " .
          TABLE_PRODUCTS_TO_CATEGORIES . " p2c
          where p.products_status = 1
            and p.manufacturers_id = m.manufacturers_id
            " . $and . "
            and p.products_id = p2c.products_id
            and pd.products_id = p2c.products_id
            and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
            and p2c.categories_id = '" . (int)$current_category_id . "'" .
            $alpha_sort;

Now to figure out how to stop it from returning more than one result for products that have multiple options prices!!! =0)

23 Dec 2014, 8:55 PM
#27
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
862
Plugin Contributions:
0

Post #27 by bumba000

It looks like adding GROUP BY p.products_id did the trick. Not a rock solid on that yet, but it appears to be working.