Created
February 20, 2019 11:57
-
-
Save jimains/48b6179cd6a5dbfdb0e70c9719526b2d 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 | |
require_once '../abstract.php'; | |
class Namespace_ProductExport extends Mage_Shell_Abstract | |
{ | |
protected $_io; | |
protected $_folder = 'exports'; | |
protected $_name = 'ProductExport.csv'; | |
protected $_delimiter = ','; | |
protected $_attributeMap = array( | |
'ProductSku' => 'sku', // 1 | |
'ChildProductSku' => 'children', //2 | |
'SupplierRef' => 'supplier', // 3 | |
'ProductImage' => 'image', // 4 | |
'Brand' => 'brand_category', // 5 | |
'ProductName' => 'name', // 6 | |
'Description' => 'description', // 7 | |
'Size' => 'size', // 8 | |
'Category' => 'category_ids', //9 | |
'Colour' => 'colour', // 10 | |
'Gender' => 'gender', // 11 | |
'Quantity' => 'qty' // 12 | |
); | |
protected function _construct() | |
{ | |
$this->_io = new Varien_Io_File(); | |
$this->_io->setAllowCreateFolders(true); | |
parent::_construct(); | |
} | |
public function run() | |
{ | |
$productsCollection = Mage::getModel('catalog/product')->getCollection() | |
->addAttributeToSelect('*'); | |
$productsCollection->setPageSize(100)->setCurPage(1); | |
$pages = $productsCollection->getLastPageNumber(); | |
$currentPage = 1; | |
$this->_io->open(array('path' => $this->_folder)); | |
$this->_io->streamOpen($this->_name); | |
$this->_io->streamWrite($this->_convertArrayToDelimitedString(array_keys($this->_attributeMap)) . "\r\n"); | |
do { | |
$productsCollection->setCurPage($currentPage); | |
foreach ($productsCollection as $_product) { | |
$mappedValues = $this->_getMappedValues($_product); | |
print_r($mappedValues); | |
die('1 record'); | |
if (!empty($mappedValues)) { | |
$this->_io->streamWrite($this->_convertArrayToDelimitedString($mappedValues) . "\r\n"); | |
} | |
} | |
$currentPage++; | |
$productsCollection->clear(); | |
} while ($currentPage <= $pages); | |
$this->_io->streamClose(); | |
} | |
protected function _convertArrayToDelimitedString($data) | |
{ | |
return implode($this->_delimiter, $data); | |
} | |
protected function _getMappedValues($product) | |
{ | |
$data = array(); | |
foreach ($this->_attributeMap as $column => $attribute) { | |
$data[] = $product->getData($attribute); | |
} | |
return $data; | |
} | |
} | |
// Create a new instance of our class and run it. | |
$shell = new Namespace_ProductExport(); | |
$shell->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment