Retrieve product_image with pdoResources?

Greetings -

I’m trying to get SimpleCart’s product_image using pdoResources, but the show_log indicates that it isn’t retrieved. I know it’s not an actual ModX TV, but the same essential call using getResources works as long as includeContent=1:

[[!getResources?
 &parents=`7`
 &where=`{"template:=":3}`
 &includeTVs=`images_homepageInclude,product_image,images_imageFile-thumb,images_fileName,images_imageCategory`
 &tvFilters=`images_homepageInclude==1`
 &processTVs=`1`
 &includeContent=`1`
 &tpl=`home_mainImage`
 &limit=`1`
 &sortby=`RAND()`
]]

Here’s the pdoResources call:

[[!pdoResources?
   &parents=`7`
   &where=`{"template:=":3}`
   &includeTVs=`images_homepageInclude,product_image,images_imageFile-thumb,images_fileName,images_imageCategory`
   &tvFilters=`images_homepageInclude==1`
   &processTVs=`1`
   &includeContent=`1`
   &tpl=`home_mainImage`
   &limit=`1`
   &sortby=`RAND()`
   &showLog=`1`
 ]]

Any ideas on how to get pdoResources to bring in SimpleCart’s product_image? It has the &select parameter – I’m just not sure (1) if it is used in conjunction with, or instead of, &where and (2) how to retrieve the value if they are used together.

I’m having a similar problem - I need to retrieve all SimpleCart product meta fields for chunk output.

I found the following sample - which needs to be modified to work with SimpleCart product meta (currently built for ms2gallery):

[[!pdoResources?
        &parents=`0`
        &class=`modResource`
        &loadModels=`ms2gallery`
        &leftJoin=`{
            "Image": {
                "class": "msResourceFile",
                "on": "modResource.id = Image.resource_id AND Image.parent = 0"
            },
            "Thumb": {
                "class": "msResourceFile",
                "on": "Image.id = Thumb.parent AND Thumb.path LIKE '%120x90%'"
            }
        }`
        &select=`{
            "modResource": "*",
            "Image": "Image.url as image",
            "Thumb": "Thumb.url as thumb"
        }`
        &showLog=`1`
        &sortby=`id`
        &sortdir=`ASC`
    ]]

If anyone is able to rewrite this until it works, I’ll be very thankful!

Here’s what the code I came up with was:

            [[pdoResources?
            &class=`modResource`
            &loadModels=`simplecart`
            &leftJoin=`{
                "Meta":{
                    "class":"scProductMeta",
                    "on":"modResource.id = Meta.resource"
                }
            }`
            &select=`{
                "modResource":"*",
                "Meta": "Meta.code AS product_code, Meta.price AS product_price, Meta.image AS product_image"
            }`
            &tpl=`scProductOverviewItem` 
            &includeContent=`1`
            &sortby=`menuindex`
            &sortdir=`ASC`
            &showLog=`1`
            ]]
1 Like

Hi @matdave,

Using &loadModels=simplecartresource, don’t have this error in the modx log?

(ERROR @ /home/lucefaidate/public_html/core/xpdo/xpdo.class.php : 503) Path specified for package simplecartresource is not a valid or accessible directory: /home/…/public_html/core/components/simplecartresource/model/

@PMedusa sorry for the late reply, but for future visitors try

loadModels=`simplecart` 

Anyone got this to work with retrieving the product_image?

Mat’s code sample includes the product image as well, does that not work for you?

No i’ve not got this working.
I have 2 chunks:

[[$getGalleryItems]]

    [[pdoResources?
 &class=`modResource`
 &loadModels=`simplecart`
 &parents=`6`
 &includeTVs=`product_image`
 &processTVs=`1`
 &tpl=`galleryItem`
 &includeContent=`1` 
 &limit=`0`
 &showLog=`1`
]]

[[$galleryImage]]

<div class="gallery_product three columns filter [[+pagetitle]]">
  <img class="img-responsive" src="[[+product_image]]" alt="[[+pagetitle]]">
</div>

It does seem to work using getResources though like this…

[[getResources?
&parents=`6`
&includeTVs=`product_image`
&processTVs=`1`
&tpl=`galleryItem`
&includeContent=`1` 
&limit=`0`]]

it would be good to get it working with pdoResources if anyone can help.

By providing &includeContent on getResources, that is going through the standard model APIs which SimpleCart has extended to automatically add additional information like the product price.

For pdoResources, which achieves a performance benefit by going around models, you need to manually join and select the appropriate fields.

From Mat’s earlier post:

        [[pdoResources?
            &class=`modResource`
            &loadModels=`simplecart`
            &leftJoin=`{
                "Meta":{
                    "class":"scProductMeta",
                    "on":"modResource.id = Meta.resource"
                }
            }`
            &select=`{
                "modResource":"*",
                "Meta": "Meta.code AS product_code, Meta.price AS product_price, Meta.image AS product_image"
            }`
            &tpl=`scProductOverviewItem` 
            &includeContent=`1`
            &sortby=`menuindex`
            &sortdir=`ASC`
            &showLog=`1`
        ]]

Note the &loadModels, &leftJoin and &select properties. Those are crucial.

Thanks very much for posting.
I have to admit though that i don’t get it:-/
That code doesn’t work in my situation where I want to retrieve product_image and display on a different resource.
Is there any documentation that references the &leftJoin and &select properties relevant to SimpleCart?

Those are pdoResources features to connect different tables, not SimpleCart features, and besides this topic I don’t think we have specific documentation about that.

Thanks for posting.
Sadly nothing specific on the pdoResources website (https://docs.modx.pro/en/components/pdotools/snippets/pdoresources).
It must just be the following properties that i have wrong.

 &leftJoin=`{
                "Meta":{
                    "class":"scProductMeta",
                    "on":"modResource.id = Meta.resource"
                }
            }`
            &select=`{
                "modResource":"*",
                "Meta": "Meta.code AS product_code, Meta.price AS product_price, Meta.image AS product_image"
            }`

Apart from having the product_image in the &select field i have no idea what to put in the rest. The example above references the meta which i don’t need.
Could someone explain the two properties above so i can work out what i need to add?
Thanks for any help

For the first time i do have a log displayed:

0.0000391: Loaded model "simplecart" from "/core/components/simplecart/model/"
0.0001330: pdoTools loaded
0.0000510: xPDO query object created
0.0037110: leftJoined product-image as Meta
0.0003481: Added selection of modResource: `id`, `type`, `contentType`, `pagetitle`, `longtitle`, `description`, `alias`, `alias_visible`, `link_attributes`, `published`, `pub_date`, `unpub_date`, `parent`, `isfolder`, `introtext`, `content`, `richtext`, `template`, `menuindex`, `searchable`, `cacheable`, `createdby`, `createdon`, `editedby`, `editedon`, `deleted`, `deletedon`, `deletedby`, `publishedon`, `publishedby`, `menutitle`, `donthit`, `privateweb`, `privatemgr`, `content_dispo`, `hidemenu`, `class_key`, `context_key`, `content_type`, `uri`, `uri_override`, `hide_children_in_tree`, `show_in_tree`, `properties`
0.0000370: Added selection of product-image: Meta.image AS product_image
0.0009110: Processed additional conditions
0.0012670: Added where condition: modResource.parent:IN(51), modResource.published=1, modResource.deleted=0
0.0001490: Sorted by modResource.menuindex, ASC
0.0000072: Limited to 10, offset 0
0.0003779: SQL prepared "SELECT `modResource`.`id`, `modResource`.`type`, `modResource`.`contentType`, `modResource`.`pagetitle`, `modResource`.`longtitle`, `modResource`.`description`, `modResource`.`alias`, `modResource`.`alias_visible`, `modResource`.`link_attributes`, `modResource`.`published`, `modResource`.`pub_date`, `modResource`.`unpub_date`, `modResource`.`parent`, `modResource`.`isfolder`, `modResource`.`introtext`, `modResource`.`content`, `modResource`.`richtext`, `modResource`.`template`, `modResource`.`menuindex`, `modResource`.`searchable`, `modResource`.`cacheable`, `modResource`.`createdby`, `modResource`.`createdon`, `modResource`.`editedby`, `modResource`.`editedon`, `modResource`.`deleted`, `modResource`.`deletedon`, `modResource`.`deletedby`, `modResource`.`publishedon`, `modResource`.`publishedby`, `modResource`.`menutitle`, `modResource`.`donthit`, `modResource`.`privateweb`, `modResource`.`privatemgr`, `modResource`.`content_dispo`, `modResource`.`hidemenu`, `modResource`.`class_key`, `modResource`.`context_key`, `modResource`.`content_type`, `modResource`.`uri`, `modResource`.`uri_override`, `modResource`.`hide_children_in_tree`, `modResource`.`show_in_tree`, `modResource`.`properties`, Meta.image AS product_image FROM `modxp3_site_content` AS `modResource` WHERE  ( `modResource`.`parent` IN (51) AND `modResource`.`published` = 1 AND `modResource`.`deleted` = 0 )  ORDER BY modResource.menuindex ASC LIMIT 10 "
0.0003872: Could not process query, error #1054: Unknown column 'Meta.image' in 'field list'
0.0067410: Total time
13 893 632: Memory usage

Can anyone shed any light?
Thanks

Well i finally got this to work.
I needed the following properties:

&leftJoin=`{
                "Meta":{
                    "class":"scProductMeta",
                    "on":"modResource.id = Meta.resource"
                }
            }`
            &select=`{
                "modResource":"*",
                "Meta": "Meta.image AS product_image"
            }`
            &parents=`6`