Skip to content
  1. Extras
  2. GoogleSheets
  3. Export
  4. Products

Products (msProduct)

Export fields

All standard resource fields plus custom fields:

FieldName
pricePrice
old_priceOld price
articleSKU
weightWeight
colorColors
sizeSizes
vendorVendor (id)
made_inCountry
tagsTags
newNew
favoriteSpecial
popularPopular
categoriesList of categories (id)
imagesImage list
option.option nameOptions

Field modifiers

FieldName
vendor_nameVendor (name)
categories_nameList of categories (name)

ms2Gallery

NameName
imageslist of images

All image files must be on the server

Export example

Export fields: id,article,pagetitle,template_name,price,color,size,vendor_name

Result:

Result

System events

Class gsProduct fires these events:

php
<?php
switch ($modx->event->name) {
  // fetches the list of products
  case 'gsOnBeforeGetProducts':
    // $query - selection query
    // $range - sheet name, where data will be exported
    break;
  case 'gsOnGetProducts':
    // $products - array of products with all fields
    // $range - sheet name
    break;
}

Examples

  1. Select products with a specific vendor

    1.1 by vendor id:

    php
    <?php
    if ($modx->event->name == 'gsOnBeforeGetProducts') {
      $query->where(array('Data.vendor' => 8)); // Vendor id
    }

    1.2 by vendor name

    php
    <?php
    if ($modx->event->name == 'gsOnBeforeGetProducts') {
      $query->where(array('Vendor.name' => 'Samsung'));
    }
  2. Add 10% to price and store current price as old price.

    php
    <?php
    if ($modx->event->name == 'gsOnGetProducts') {
      $modx->event->params['products'] = array_map(function($product){
          if (isset($product['old_price']) && !empty($product['price'])) {
            $product['old_price'] = $product['price'];
          }
          if (!empty($product['price'])) {
            $product['price'] = $product['price'] * 1.1;
          }
          return $product;
      }, $products);
    }