Jump to content

Complicated question


OLSA
 Share

Recommended Posts

Hello for all,

sorry for this topic title but let me try to explain.
Website has product items, where sometimes products go to "Outlet" (actions/discounts).
Main part here is that in "action" status:
a) product can have new price and go alone to discount
OR
b) product is in group with other products ("collection", and new price is only valid in case when customer buy full collection).

First problem was how to get this :

Product items:

A on action
B on action in group with "D"
C  on action
D on action in group with "B"
---------------------------------------------------

Outlet list page need to show 3 items:

1. item (A)
2. item (B, D) (eg. item image is "TV+sofa")
3. item (C)

First what I done, was that I created Outlet "category" with children, where children page has fields: title, group image and page select field (to select products from another page tree). But that was wrong and dirty (few foreach, pagination..., etc. that was bad concept).

Than I decided to place page select field on product item, and from product item select it's group (single select field). And that was ok, and I like it also because administration in any variant need to go to product to set new price. Right now, administration first create group page with some title and with some image. After that, go to product item, check field "action", write new price, and - if - product is part of group - add - it to group.

There is part of code on "Outlet" list page:

// outlet-list.php

// $items: single items
// outlet: page field, it's parent is "Outlet" list page
$items = $pages->find('template=product-item, action=1, outlet.count=0'); // outlet=0 or outlet=''...
$group_items = $pages->find('template=product-item, action=1, outlet.count>0');

// group items ("merge")
foreach( $page->children() as $group ){	                             // go through Outlet children ("group id pages")
	if($group_items->has("outlet=$group->id")){                     // if in array are items with that group id  
		$group->singles = $group_items->find("outlet=$group->id");  // append to page "group" new attribute and fill it
        $items->add($group);		                                // now go back and append to "items" new type of "item"
	}	
}
// pagination
$pagination = $items->renderPager();

After it in rendering process I get basic product items, and "group" items together inside list page.

Here is the problem:

When I go and set some of Group page as "unpublished", I expect, after it, to get that group subitems shows as alone (singles) inside Outlet. But not.
They doesn't shows!?
In that case outlet.count return null, but real "singles" return false. I try more options with selector (and different page select field types) but can't get what expect to be. 

// selector to return singles
'template=product-item, action=1, outlet.count=0' // tried options outlet=0, outlet='', outlet=0|"", outlet.count<1 etc...

Sorry for this long, long topic. If someone has some idea what and where... I would be grateful :)
Best regards! 

p.s. if all this is confused, last sleeping was... can't remember :)

Link to comment
Share on other sites

4 hours ago, OLSA said:

When I go and set some of Group page as "unpublished", I expect, after it, to get that group subitems shows as alone (singles) inside Outlet.

You can do this...

$items = $pages->find('template=product-item, action=1, !outlet=[status=published]');
$group_items = $pages->find('template=product-item, action=1, outlet=[status=published]');

...but I don't think unpublishing Group pages is a good strategy, because unpublished pages do not appear as an option in a Page Reference inputfield. So it means that in Page Edit you cannot distinguish between a product that has no Group selected, and a product that does have a Group selected but the Group has been unpublished.

What I would probably do is create a new Page Reference field "group_status" with selectable pages "Active" and "Inactive", and set the "Active" page to be the default value. Add this to the Group template. Then in the Outlet field, include the group_status field in a custom format for "Label field" so you can see the status of each group in the Outlet inputfield.

 

4 hours ago, OLSA said:

First what I done, was that I created Outlet "category" with children where children page has only 2 fields: group image and page select field (to select products from another page tree).

4 hours ago, OLSA said:

Than I decided to place page select field on product item, and from product item select it's group (single select field).

You can have both if you use the ConnectPageFields module.

 

  • Like 5
Link to comment
Share on other sites

Thank you Robin S! "status=published" solved my problem.
I was sure that eg. outlet=0 or outlet='' will work and didn't think that there might be some new selectors (need to read this).
 

11 hours ago, Robin S said:

..but I don't think unpublishing Group pages is a good strategy, because unpublished pages do not appear as an option in a Page Reference inputfield. So it means that in Page Edit you cannot distinguish between a product that has no Group selected, and a product that does have a Group selected but the Group has been unpublished.

No everything need to be simple as possible. If in edit procedure product doesn't  have visible group - it's not in a group.

Group is "virtual" product item (can change...), not like "TV" or "sofa", and because of that administration can do with group what they like (eg. update: change image and append new product to group). Probably, after they sell "group item", they will delete group page. Here is more important to delete real products (if no products, no group) .

11 hours ago, Robin S said:

You can have both if you use the ConnectPageFields module.

 

Ok, very interesting, will try it. Thanks Robin S.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...