Skip to content

Instantly share code, notes, and snippets.

@kphretiq
Last active April 21, 2016 20:52
Show Gist options
  • Save kphretiq/ccc66465a8db660ee5ececed1aaafa31 to your computer and use it in GitHub Desktop.
Save kphretiq/ccc66465a8db660ee5ececed1aaafa31 to your computer and use it in GitHub Desktop.
def products_ordered(self, sku, quantity, price):
"""
Requires populated sku_reference dictionary. Catch Key Error on fail.
accepts
sku str
quantity str (D.DDDD)
ex. "1.0000" _must_ have a decimal followed by four
place values.
return a string formated in one of three ways for "products_ordered"
field, that matches magento's order import format (a "csv" file in
which EVERY. SINGLE. FIELD. is surrounded by double-quotes, regardless
of type.) A format obviously old-world crafted by griefer macaques for
stoned koala bears.
# default format, simple colon-delimited list of four values
QF-LUXE:1.0000:45.0000:Quisling Foetus PLUS 3 ounce
^ ^ ^ ^
| | | +- "name"
| | +- "price"
| +- "quantity"
+- "sku"
# "configurable" combines a single variant value and price into
# a caret-delimited "configurable".
DRKRTCH:1.0000:configurable:Cherry^35.0000^Absolut Dementia Nekro Draught
^ ^ ^ ^ ^ ^
| | | | | +-"name"
| | | | +-"price"
| | | +- "variant"
| | +- "configurable" tag/delimiter/skidmark
| +- "quantity"
+- "sku"
# "wtff configurable" combines more than one variant value into another
# colon-delimited tuple (sweet baby Jesus, why?) and then into a
# caret-delimited "configurable". I think. Maybe it's a "configurable-
# delimited reverse-polish hash". I don't ******* know, and neither do
# they.
EIGEN-DUH-18:1.0000:configurable:18mg:Menthol^8.5000^Frust-O-Fap
^ ^ ^ ^ ^ ^ ^
| | | | | | +-"name"
| | | | | +-"price"
| | | \ |
| | | +-combined "variant"
| | +- "configurable" thingy
| +- "quantity"
+- "sku"
yaml? json? xm-effing-l? "serialize" was in php4 in 1998. Magento was
first released in 2007. Ponder for a moment, the code for which this
format is "the easy way". Considering MAGE's roughly 1.5 record per
second import rate, it ain't an optimization for speed.
This is obviously something that should be provided for natively in
PHP 8, since Magento is so very important to "e-commerce solutions"
world-wide. I suggest adding to "array" and "hash" the type "puple",
for "purple tuple made of poop".
"""
try:
product = self.sku_reference[sku]
except KeyError:
message = "No sku reference for %s."%sku
warnings.warn(message, UserWarning)
return False
if "variant" in product:
# trust "variant" list in products_order_lookup.json
variant = ":".join(product["variant"])
hair_metal = "^".join([variant, price, product["name"],])
return ":".join([sku, quantity, "configurable", hair_metal,])
return ":".join([sku, quantity, price, product["name"],])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment