Zen Cart Logo
Forums / General Questions / Porting OsC mod

Porting OsC mod

Views: 1,728

Results 1 to 8 of 8
18 Jun 2013, 12:42 PM
#1
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Porting OsC mod

Getting a little deep in this mod for a client who simply wants her old inventory update mod.

Easy enough to change tep to zen and to put in replace if bits but I have foreach situation and I need help resolving this. This is the section I'm converting. I know the foreach line does not work due to the array_keys

	$categories = array();

	// Consolidate the below into a join, so we can alphabetise, among other things.

	$categories = $db->Execute("SELECT c.categories_id, c.parent_id, cd.categories_name FROM categories AS c, categories_description AS cd WHERE c.parent_id > 0 AND cd.categories_id = c.categories_id ORDER BY cd.categories_name ASC");


	// Buffer the categories.

	while($categories->EOF) {

		$categories[] = array('id' => $category['categories_id'],
				      'parent_id' => $category['parent_id'],
				      'name' => $category['categories_name']);
$categories->MoveNext();
	}

	echo zen_draw_form('products_update', 'riu.php', 'action=process');

	foreach(array_keys($categories) as $category) {

		$categories_products_query = $db->Execute("SELECT products_id FROM products_to_categories WHERE categories_id = " . $categories[$category]['id']);

		if($categories_products_query->RecordCount()) {

The error message is array_keys() expects parameter 1 to be array, object given in...

I've seen some examples of how to change this but just not sure and what I've tried hasn't worked. Could be due to how the section is set up before we get that far - I just don't know.

Would someone check the php for this to push me in the right direction? Any help would be appreciated.

18 Jun 2013, 5:21 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: Porting OsC mod

delia:

$categories = $db->Execute("SELECT c.categories_id, c.parent_id, cd.categories_name FROM categories AS c, categories_description AS cd WHERE c.parent_id > 0 AND cd.categories_id = c.categories_id ORDER BY cd.categories_name ASC");

// Buffer the categories. 

while($categories->EOF) { 

    $categories[] = array('id' => $category['categories_id'], 
                  'parent_id' => $category['parent_id'], 
                  'name' => $category['categories_name']); 

$categories->MoveNextCOLOR=#007700;
}
[/COLOR]

You are using $categories for three things there, and $category for nothing.
Change that to this:```
$[B]result[/B] = $db->Execute("SELECT c.categories_id, c.parent_id, cd.categories_name FROM categories AS c, categories_description AS cd WHERE c.parent_id > 0 AND cd.categories_id = c.categories_id ORDER BY cd.categories_name ASC"); 
    // Buffer the categories. 

    while($[B]result[/B]->EOF) { 

        $categories[] = array('id' => $[B]result[/B]['categories_id'], 
                      'parent_id' => $[B]result[/B]['parent_id'], 
                      'name' => $[B]result[/B]['categories_name']); 
        $[B]result[/B]->MoveNext(); 
    } 
18 Jun 2013, 5:38 PM
#3
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Porting OsC mod

Thought my eyes were crossing for some reason! So that fixed the error - mod still doesn't display product list but has no errors and trying to convince client to use apsona instead.

She does have a interesting point though - being able to update quantities in very easy manner - would be nice to have for some folks. Be glad to turn these files over to anyone who would like to give it a try.

Oh, and thanks, Dr Byte, much appreciated!

18 Jun 2013, 7:09 PM
#4
drbyte avatar

drbyte

Sensei

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

Re: Porting OsC mod

DrByte:

    $categories[] = array('id' => $[B]result[/B]['categories_id'], 
                  'parent_id' => $[B]result[/B]['parent_id'], 
                  'name' => $[B]result[/B]['categories_name']); 
Oops, those should have been $result**->fields**
18 Jun 2013, 7:25 PM
#5
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Porting OsC mod

ah, I don't understand. Yes, the rows are not printing out.

And yeah, now she says she really wants this done.

Methinks I'm going to recognize it when I see it done right....

I do usually go find a like mod or file and can figure out from there. Suggestion? I don't mind puzzling it out if I got solid code to follow or utilize.

18 Jun 2013, 8:30 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Porting OsC mod

These:

        $categories[] = array('id' => $result['categories_id'], 
                      'parent_id' => $result['parent_id'], 
                      'name' => $result['categories_name']);

need to be written:

        $categories[] = array('id' => $result[B]->fields[/B]['categories_id'], 
                      'parent_id' => $result[B]->fields[/B]['parent_id'], 
                      'name' => $result[B]->fields[/B]['categories_name']);
18 Jun 2013, 9:05 PM
#7
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Porting OsC mod

Okay, that looks right!

Then I got a foreach for the categories and a while statement for the products and they obviously aren't correct.

I have to start fresh in the morning - my brain has quit and I don't want to rely on your brain(s) completely as that's just not fair!

I thank you for your time today.

19 Jun 2013, 4:31 PM
#8
delia avatar

delia

Totally Zenned

Join Date:
May 2006
Location:
Gardiner, Maine
Posts:
2,383
Plugin Contributions:
7

Re: Porting OsC mod

Looks like I've only one more hurdle to at least get the page to print out correctly. So the array inside the category array is the problem.

I can get all the categories to display but only one product for each category so this is not running thru the array:

$products_query = $db->Execute("SELECT p.products_id, pd.products_name, p.products_quantity, DATE_FORMAT(p.products_date_available, '%m-%d-%Y') AS products_date_available "
							.      "FROM products AS p, products_description AS pd WHERE p.products_id = pd.products_id AND p.products_id = " . $categories_products_query->fields['products_id']);

while(!$products_query->EOF) {	

				

					echo "        <tr>\n"
					.    "          <td valign=\"top\" align=\"left\" width=\"50%\" class=\"dataTableContent\">\n"
					. $products_query->fields['products_name']
					.    "          </td>\n"
					.    "		<td valign=\"top\" align=\"right\" width=\"20%\" class=\"dataTableContent\">\n"
					. zen_draw_input_field('product_qty_' . $products_query->fields['products_id'], $products_query->fields['products_quantity'], 'maxlength=10, size=7', false, $type = 'text', false)
					.    "	        </td>\n"
					.    "	        <td valign=\"top\" align=\"right\" width=\"30%\" class=\"dataTableContent\">\n"
					. zen_draw_input_field('product_date_available_' . $products_query->fields['products_id'], 
							isset($products_query->fields['products_date_available']) ? 
							   $products_query->fields['products_date_available'] : "now",
							'maxlength=15, size=10', false, $type = 'text', false)
					.    "		</td>\n"
					.    "        </tr>\n";
					
// this marks the end of the movement thru the while statement.					
$products_query->MoveNext();