MC/website/ops/oscommerce/final-shop-settings.py
2026-11-27 23:43:05 +00:00

31 lines
3.3 KiB
Python

from pathlib import Path
import subprocess,shutil,re
app=Path('/home/dunerealms/apps/oscommerce');repo=Path('/home/dunerealms/oscommerce-integration/website')
sql="""INSERT INTO products_stock_indication(sort_order,is_default,stock_code,allow_out_of_stock_checkout,allow_out_of_stock_add_to_cart,allow_in_stock_notify,display_price_options)
SELECT 10,0,'made-to-order',0,0,0,0 WHERE NOT EXISTS(SELECT 1 FROM products_stock_indication WHERE stock_code='made-to-order');
INSERT IGNORE INTO products_stock_indication_text(stock_indication_id,language_id,stock_indication_text,stock_indication_short_text)
SELECT stock_indication_id,1,'Made to order','Made to order' FROM products_stock_indication WHERE stock_code='made-to-order';
UPDATE products p JOIN dune_catalog_import d ON d.products_id=p.products_id AND d.kind='sash' SET p.stock_indication_id=(SELECT stock_indication_id FROM products_stock_indication WHERE stock_code='made-to-order' LIMIT 1),p.manual_stock_unlimited=1;
INSERT IGNORE INTO dune_product_requirements SELECT products_id,0,1 FROM dune_catalog_import WHERE kind='rank';
UPDATE meta_tags SET meta_tags_value='The collection' WHERE meta_tags_key='HEAD_H1_TAG_PRODUCTS_ALL' AND language_id=1 AND platform_id=7;
UPDATE meta_tags SET meta_tags_value='New arrivals' WHERE meta_tags_key='HEAD_H1_TAG_WHATS_NEW' AND language_id=1 AND platform_id=7;
UPDATE meta_tags SET meta_tags_value='Featured products' WHERE meta_tags_key='HEAD_H1_TAG_FEATURED' AND language_id=1 AND platform_id=7;
"""
subprocess.run(['mysql','dunerealms_oscommerce'],input=sql,text=True,check=True,capture_output=True)
# Use a visible label for native selectable options as well as the custom-name field.
p=app/'lib/frontend/themes/basic/boxes/product/attributes/select.tpl';s=p.read_text()
needle=' <select class="select"'
if 'dune-option-label' not in s:s=s.replace(needle," {if !(count($item.options) == 1 && $item.options[0].type > 0)}<span class=\"attr-title dune-option-label\">{$item.title|escape:'html'}</span>{/if}\n"+needle,1)
p.write_text(s)
# Replace the remaining sample delivery copy with the actual preview terms.
text='<h3>Made to order</h3><p>Personalised sashes are custom orders. Ordering has not opened yet; production and delivery timings will be confirmed before checkout is enabled.</p><h3>Shipping and returns</h3><p>Planned sash shipping is €20 once per order. No shipping fee is charged during preview. Delivery and return terms will be published before orders open.</p>'
q="UPDATE design_boxes_settings SET setting_value=CONVERT(0x"+text.encode().hex()+" USING utf8mb4) WHERE box_id=110866 AND setting_name='text';"
subprocess.run(['mysql','dunerealms_oscommerce'],input=q,text=True,check=True,capture_output=True)
for f,target in [('DuneProductRules.php','lib/frontend/components/DuneProductRules.php'),('dune-shop-cards.css','dune-shop-cards.css')]:
shutil.copyfile('/tmp/'+f,app/target)
shutil.copyfile('/tmp/'+f,repo/'ops/oscommerce'/f)
for f in ['DuneAccount.php','DuneShopController.php','publish-oscommerce-portal.py']:
shutil.copyfile('/tmp/'+f,repo/'ops/oscommerce'/f)
shutil.copyfile(__file__,repo/'ops/oscommerce/final-shop-settings.py')
subprocess.run(['chown','-R','dunerealms:dunerealms',str(repo/'ops/oscommerce')],check=True)
print('Made-to-order stock indication, donor preview guards, option labels and shop headings configured.')