-
-
Save lukeholder/664c4a37ebefc9e053eec3c53bec2ee1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace modules\productexporter\elements\exporters; | |
use Craft; | |
use craft\base\ElementExporter; | |
use craft\elements\db\ElementQueryInterface; | |
/** | |
* Products Exporter element exporter | |
*/ | |
class ProductsExport extends ElementExporter | |
{ | |
public static function displayName(): string | |
{ | |
return 'J&C Custom Export'; | |
} | |
function export(ElementQueryInterface $query): mixed | |
{ | |
$data = []; | |
foreach ($query->each() as $product) { | |
$data[] = [ | |
'SKU' => $product->defaultSku ?? '', | |
'Title' => $product->title ?? '', | |
'Description' => strip_tags($product->description), | |
'Price' => $product->defaultPrice ?? '', | |
'Stock' => $product->hasUnlimitedStock ? 'Unlimited' : $product->getTotalStock() ?? '', | |
'SalePrice' => $product->jcSalePrice ?? '', | |
'Enabled' => $product->enabled ? 'Enabled' : 'Disabled', | |
'Status' => ucfirst($product->status), | |
'Weight' => $product->defaultWeight ?? '', | |
'FinanceAvailable' => $product->financeAvailable ? 'Yes' : 'No', | |
'CanBeReserved' => $product->canBeReserved ? 'Yes' : 'No', | |
'CanBeEngraved' => $product->canBeEngraved ? 'Yes' : 'No', | |
'RingSizeRequired' => $product->ringSizeRequired ? 'Yes' : 'No', | |
'Clearance' => $product->clearance ? 'Yes' : 'No', | |
'URL' => $product->getUrl(), | |
]; | |
} | |
return $data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment