Skip to content

Instantly share code, notes, and snippets.

@sashabeep
Last active March 16, 2023 06:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sashabeep/4b6c920a0910cded5c622d7c119be704 to your computer and use it in GitHub Desktop.
Save sashabeep/4b6c920a0910cded5c622d7c119be704 to your computer and use it in GitHub Desktop.
MultiTV line as single cart item for Commerce
switch ($modx->event->name) {
case 'OnBeforeCartItemAdding': {
$offset = intval($params['item']['options']['variant'])-1;
$itemid = intval($params['item']['id']);
$myitemfields = json_decode($modx->runSnippet("multiTV",Array('tvName'=>'variant','toJson'=>1,'display'=>1,'offset'=>$offset,'docid'=>$itemid)),TRUE)[0];
$params['item']['price'] = $myitemfields['price'];
$params['item']['name'] = $myitemfields['title'];
}
}
[!multiTv? &tvName=`variant` &display=`all`!]
<?php
$settings['display'] = 'horizontal';
$settings['fields'] = array(
'title' => array(
'caption' => 'Наименование',
'type' => 'text'
),
'weight' => array(
'caption' => 'Вес',
'type' => 'text'
),
'price' => array(
'caption' => 'Цена',
'type' => 'text'
)
);
$settings['templates'] = array(
'outerTpl' => '<div class="variants">[+wrapper+]</div>',
'rowTpl' => '
<form action="#" data-commerce-action="add">
<table class="table">
<tr>
<td>[+title+]</td>
<td><input type="text" name="count" value="1"></td>
<td><input type="submit" value="Add"></td>
</tr>
</table>
<input type="hidden" name="id" value="[*id*]">
<input type="hidden" name="options[name]" value="[+title+]">
<input type="hidden" name="options[weight]" value="[+weight+]">
<input type="hidden" name="options[variant]" value="[+row.number+]">
</form>
'
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment