MC/website/ops/oscommerce/install-sash-rules.py
2026-11-27 23:43:05 +00:00

20 lines
1.6 KiB
Python

from pathlib import Path
import subprocess
app=Path('/home/dunerealms/apps/oscommerce')
p=app/'lib/frontend/components/CartFactory.php';s=p.read_text()
needle=' public static function work() {'
if 'DuneProductRules::validateCartRequest' not in s:
s=s.replace(needle,needle+"\n require_once __DIR__.'/DuneProductRules.php';\n DuneProductRules::validateCartRequest();",1)
s=s.replace(' DuneProductRules::validateCartRequest();',' \\frontend\\components\\DuneProductRules::validateCartRequest();')
p.write_text(s)
p=app/'lib/frontend/themes/basic/boxes/product/attributes/select.tpl';s=p.read_text()
needle='name="attr_text[{$item.id}]"'
if 'maxlength="80"' not in s:
s=s.replace(needle,needle+'{if $item.title == \'Preferred name\'} required maxlength="80" aria-label="Preferred name for embroidery (required)" placeholder="Enter the name to embroider"{/if}',1)
if 'dune-option-label' not in s:
s=s.replace(' <select class="select"'," {if !(count($item.options) == 1 && $item.options[0].type > 0)}<span class=\"attr-title dune-option-label\">{$item.title|escape:'html'}</span>{/if}\n <select class=\"select\"",1)
p.write_text(s)
for f in [app/'lib/frontend/components/CartFactory.php',app/'lib/frontend/components/DuneProductRules.php']:
subprocess.run(['php','-l',str(f)],check=True)
subprocess.run(['chown','dunerealms:dunerealms',str(p),str(app/'lib/frontend/components/CartFactory.php'),str(app/'lib/frontend/components/DuneProductRules.php')],check=True)
print('Native embroidery text attribute is required; server rejects missing names and preview purchases.')