Last active
June 26, 2024 07:43
-
-
Save sashabeep/4b6c920a0910cded5c622d7c119be704 to your computer and use it in GitHub Desktop.
MultiTV line as single cart item for Commerce
This file contains 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
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']; | |
} | |
} |
This file contains 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
[!multiTv? &tvName=`variant` &display=`all`!] |
This file contains 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 | |
$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