Skip to content

Instantly share code, notes, and snippets.

@vgrish
Created January 3, 2016 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrish/3709825b74188cf618be to your computer and use it in GitHub Desktop.
Save vgrish/3709825b74188cf618be to your computer and use it in GitHub Desktop.
<?php
$msop2 = $modx->getService('msop2', 'msop2', $modx->getOption('msop2_core_path', null, $modx->getOption('core_path') . 'components/msop2/') . 'model/msop2/');
if (!($msop2 instanceof msop2)) return '';
/* массив опций продуктов */
$data = array(
'class_key' => 'msProduct',
'context_key' => 'web',
'size' => array(
'100',
'200',
'300',
'400',
'500',
'600',
'700',
'800',
'900',
'1000'
)
);
/* массив опций и цен */
$options = array(
'100' => 10,
'200' => 20,
'300' => 30,
'400' => 40,
'500' => 50,
'600' => 60,
'700' => 70,
'800' => 80,
'900' => 90,
'1000' => '10'
);
$q = $modx->newQuery('msProduct');
$q->where(array('class_key' => 'msProduct'));
$q->select('id');
if ($q->prepare() && $q->stmt->execute()) {
$ids = $q->stmt->fetchAll(PDO::FETCH_COLUMN);
}
foreach($ids as $id) {
$data['id'] = $id;
$modx->error->reset();
$response = $modx->runProcessor('resource/update', $data);
if ($response->isError()) {
print_r($response->getAllErrors());
continue;
}
foreach ($options as $value => $price) {
$msop = array(
'product_id' => $id,
'operation' => 1, // операция
'option' => 1, // опция size
'value' => $value
);
if (!$msop2Price = $modx->getObject('msop2Price', $msop)) {
$msop2Price = $modx->newObject('msop2Price');
$msop2Price->fromArray($msop);
}
$msop2Price->set('price', $price);
$msop2Price->save();
}
}
@vgrish
Copy link
Author

vgrish commented Jan 4, 2016

$q = $modx->newQuery('msProduct');
$q->innerJoin('msProductData', 'msProductData', 'msProductData.id = msProduct.id');
$q->where(array('msProduct.class_key' => 'msProduct'));
$q->select('msProduct.id,msProductData.ploshad');
if ($q->prepare() && $q->stmt->execute()) {
    $ids = $q->stmt->fetchAll(PDO::FETCH_ASSOC);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment