Created
July 19, 2024 10:39
-
-
Save sunscreem/6b24da52073e4b17f57a9ee73af35f9a to your computer and use it in GitHub Desktop.
This file contains hidden or 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