WBCE CMS Forum

WBCE CMS – Way Better Content Editing.

You are not logged in.

#1 29.08.2021 05:00:19

losttrip
Member

One For All Anyitems

I would be happy to share links to live pages privately.

I have a One For All section used as a store.
One of the fields types is a "Switch On/Off" and the on/of data is "Currently Out of Stock,In Stock"
All works well on the main OFA pages.

I just installs oneforall_anyitems because I wanted to feature a few items from each child shop page on the parent "Shop" page

I used this code:

oneforall_anyitems(88, $num_of_items = 20, $order = false);

And added my styles to the incude.php file.  Everything looks and functions EXCEPT the "Stock" data is not displayed correctly.  Nothing is displayed for those items with are "In Stock" and only the number "1" is displayed for those items which are "Currently Out of Stock"

Upon troubleshooting I see that the switch on/off value is store in the database as either:
In Stock:
a:1:{i:0;s:0:"";}
or
Currently Out of Stock:
a:2:{i:0;s:0:"";i:1;s:1:"1";}

Sorry if I am not being clear.  But I am wondering if there is a way to show th in_stock text "Currently Out of Stock,In Stock" using the one for all helper files on a different page than an ofa page.

Online

#2 29.08.2021 08:06:49

florian
Administrator

Re: One For All Anyitems

in the include.php, insert after

// For media add WB_URL to the link
if ($types[$field_id] == 'media' && !empty($values[$field_id])) {
$values[$field_id] = WB_URL.MEDIA_DIRECTORY.$values[$field_id];
}

the following (rather odd) code:

if ($types[$field_id] == 'switch')	{
	$tempvals = explode(':',$values[$field_id]);								
	$switchvals = explode(',',$extra[$field_id]);											
	if ($tempvals[1] == "2") {
		$values[$field_id] = $switchvals[0];																
	} else {
		$values[$field_id] = $switchvals[1];
	}
}

and change the line

if ($unserialized !== false || $values[$field_id] == 'b:0;') {

to

if ($types[$field_id] != 'switch' && ($unserialized !== false || $values[$field_id] == 'b:0;')) {

Code allein macht nicht glücklich. Jetzt spenden!

Online

Liked by:

losttrip

#3 29.08.2021 15:42:04

losttrip
Member

Re: One For All Anyitems

Thank you so much for the working solution.

I always want to come away understanding (somewhat) the changes I have to make, or the reason for the changes made.  Is there a basic explanation for why the switch (and now I realize also radio buttons, select, etc.) does not work with oneforall_anyitems

I am going to analyze your code and work out how to fix oneforall_anyitems to allow radio buttons and others as well.  I assume I can keep adding if/else statements below the switch one you provided.  Is that correct?  Or is it more difficult than that?

Online

#4 30.08.2021 08:25:20

florian
Administrator

Re: One For All Anyitems

I'm not sure, but I think there are some issues with the unserialize function, which does not work as expected (at least at PHP8). I did not want to change the OfA main module functions, because on usual OfA pages the output does work.
I'm neither the creator of the module nor a real programmer, so it's always try and error.
Regarding the output of checkboxes, radio buttons, select lists: it should work similiar to the switch output, since the data is stored in that serialized format as well, but it needs to be customized, and it becomes more difficult due to the other fields can have more than just two options. So the quick & dirty simple soltion with exploding the actual serialized term and checking the value if the one hard coded array value defintively won't work in all cases.

I have to dig deeper into this, also for your other wishes to the OfA helper snippets.


Code allein macht nicht glücklich. Jetzt spenden!

Online

Liked by:

losttrip

Board footer

up