Source for file PriceLoader.class.php
Documentation is available at PriceLoader.class.php
* Содержит класс PriceLoader
* @copyright ColoCall 2006
//require_once('core/modules/share/components/DataSet.class.php');
//require_once('core/ext/excel/reader.php');
* Класс для загрузки прайса
* @param Document $document
public function __construct($name, $module, Document $document, array $params = null) {
parent::__construct($name, $module, $document, $params);
* Переопределен параметр active
protected function main() {
$this->setType(self::COMPONENT_TYPE_FORM_ADD);
$fieldName = (string) $this->config->getMethodConfig(self::DEFAULT_ACTION_NAME)->fields->field[0]['name'];
$newFilename = $this->document->getSiteRoot(). '/tmp/'. date('YmdHis');
if (empty($_FILES) || !isset ($_FILES[$fieldName]) || !empty($_FILES[$fieldName]['error']) || !is_readable($_FILES[$fieldName]['tmp_name']) || !is_uploaded_file($_FILES[$fieldName]['tmp_name']) || !move_uploaded_file($_FILES[$fieldName]['tmp_name'], $newFilename)) {
chmod($newFilename, 0666);
$this->document->componentManager->getComponentByName('breadCrumbs')->addCrumb();
$resultField = new Field('price_loader_result');
$resultField->setData($resultMessage);
$data->addField($resultField);
$data = new Spreadsheet_Excel_Reader();
$data->setRowColOffset(0);
$data->setUTFEncoder('mb');
$data->setOutputEncoding('UTF8');
$this->dbh->beginTransaction();
$resultMessage = $this->translate('MSG_IMPORT_SUCCESS');
//$this->dbh->modify(QAL::UPDATE , 'shop_products', array('product_is_available'=>'0'));
$this->dbh->modify(QAL::DELETE , 'shop_product_external_properties');
$rowCount = $data->sheets[0]['numRows'];
for ($rowNum = 0; $rowNum < $rowCount; $rowNum++ ) {
if (isset ($data->sheets[0]['cells'][$rowNum])) {
$code = trim($data->sheets[0]['cells'][$rowNum][0]);
$price = $data->sheets[0]['cells'][$rowNum][1];
$productID = simplifyDBResult($this->dbh->select('shop_products', array('product_id'), array('product_code'=> $code)), 'product_id', true);
$this->dbh->modify(QAL::INSERT , 'shop_product_external_properties', array('product_code'=> $code, 'product_price'=> $price));
//$this->dbh->modify(QAL::UPDATE , 'shop_products', array('product_is_available'=>1), array('product_id'=>$productID));
$resultMessage = $this->translate('MSG_IMPORT_FAILED'). ': '. $e->getMessage();
|