Formation Prestashop intégrateur: Utilisation du JavaScript / La variables globale prestaShop

Vous êtes ici : Accueil / Prestashop intégrateur / Utilisation du JavaScript / La variables globale prestaShop

La variables globale prestaShop

A partir de la version 1.7, une variable 'prestashop' est ajoutée sur toutes les pages du front-office.

Cette variable est utilisée pour passer toutes les informations nécessaire au code JavaScript.

var prestashop = {
  "cart": {
    "products":[],
    "totals": {
      "total": {"type":"total","label":"Total","amount":0,"value":"0,00\u00a0\u20ac"},
      "total_including_tax":{"type":"total","label":"Total TTC","amount":0,"value":"0,00\u00a0\u20ac"},
      "total_excluding_tax":{"type":"total","label":"Total HT :","amount":0,"value":"0,00\u00a0\u20ac"}
    },
    "subtotals":{
      "products":{"type":"products","label":"Sous-total","amount":0,"value":"0,00\u00a0\u20ac"},
      "discounts":null,
      "shipping":{"type":"shipping","label":"Livraison","amount":0,"value":"gratuit"},
      "tax":null
    },
    "products_count":0,
    "summary_string":"0 articles",
    "vouchers":{"allowed":0,"added":[]},
    "discounts":[],
    "minimalPurchase":0,
    "minimalPurchaseRequired":""
  },
  "currency":{"name":"euro","iso_code":"EUR","iso_code_num":"978","sign":"\u20ac"},
  "customer":{"lastname":null,"firstname":null,"email":null,"birthday":null,"newsletter":null,"newsletter_date_add":null,"optin":null,"website":null,"company":null,"siret":null,"ape":null,"is_logged":false,"gender":{"type":null,"name":null},"addresses":[]},
  "language":{"name":"Fran\u00e7ais (French)","iso_code":"fr","locale":"fr-FR","language_code":"fr","is_rtl":"0","date_format_lite":"d\/m\/Y","date_format_full":"d\/m\/Y H:i:s","id":1},
  "page":{"title":"","canonical":null,"meta":{"title":"Presta 1.7.5.x","description":"Boutique propuls\u00e9e par PrestaShop","keywords":"","robots":"index"},"page_name":"index","body_classes":{"lang-fr":true,"lang-rtl":false,"country-FR":true,"currency-EUR":true,"layout-full-width":true,"page-index":true,"tax-display-enabled":true},"admin_notifications":[]},
  "shop":{"name":"Presta 1.7.5.x","logo":"\/img\/logo.png","stores_icon":"\/img\/logo_stores.png","favicon":"\/img\/favicon.ico"},
  "urls":{
    "base_url":"http:....\/",
    "current_url":"http:....\/fr\/",
    "shop_domain_url":"http:....",
    "img_ps_url":"http:....\/img\/",
    "img_cat_url":"http:....\/img\/c\/",
    "img_lang_url":"http:....\/img\/l\/",
    "img_prod_url":"http:....\/img\/p\/",
    "img_manu_url":"http:....\/img\/m\/",
    "img_sup_url":"http:....\/img\/su\/",
    "img_ship_url":"http:....\/img\/s\/",
    "img_store_url":"http:....\/img\/st\/",
    "img_col_url":"http:....\/img\/co\/",
    "img_url":"http:....\/themes\/mychild\/assets\/img\/",
    "css_url":"http:....\/themes\/mychild\/assets\/css\/",
    "js_url":"http:....\/themes\/mychild\/assets\/js\/",
    "pic_url":"http:....\/upload\/",
    "pages":{
      "address":"http:....\/fr\/adresse",
      "addresses":"http:....\/fr\/adresses",
      "authentication":"http:....\/fr\/connexion",
      "cart":"http:....\/fr\/panier",
      "category":"http:....\/fr\/index.php?controller=category",
      "cms":"http:....\/fr\/index.php?controller=cms",
      "contact":"http:....\/fr\/contact",
      "discount":"http:....\/fr\/reduction",
      "guest_tracking":"http:....\/fr\/suivi-commande-invite",
      "history":"http:....\/fr\/historique-commandes",
      "identity":"http:....\/fr\/identite",
      "index":"http:....\/fr\/",
      "my_account":"http:....\/fr\/mon-compte",
      "order_confirmation":"http:....\/fr\/confirmation-commande",
      "order_detail":"http:....\/fr\/index.php?controller=order-detail",
      "order_follow":"http:....\/fr\/suivi-commande",
      "order":"http:....\/fr\/commande",
      "order_return":"http:....\/fr\/index.php?controller=order-return",
      "order_slip":"http:....\/fr\/avoirs",
      "pagenotfound":"http:....\/fr\/page-introuvable",
      "password":"http:....\/fr\/recuperation-mot-de-passe",
      "pdf_invoice":"http:....\/fr\/index.php?controller=pdf-invoice",
      "pdf_order_return":"http:....\/fr\/index.php?controller=pdf-order-return",
      "pdf_order_slip":"http:....\/fr\/index.php?controller=pdf-order-slip",
      "prices_drop":"http:....\/fr\/promotions",
      "product":"http:....\/fr\/index.php?controller=product",
      "search":"http:....\/fr\/recherche",
      "sitemap":"http:....\/fr\/sitemap",
      "stores":"http:....\/fr\/magasins",
      "supplier":"http:....\/fr\/fournisseur",
      "register":"http:....\/fr\/connexion?create_account=1",
      "order_login":"http:....\/fr\/commande?login=1"
    },
    "alternative_langs":{
      "fr":"http:....\/fr\/",
      "ca-es":"http:....\/ca\/"
    },
    "theme_assets":"\/themes\/mychild\/assets\/",
    "actions":{
      "logout":"http:....\/fr\/?mylogout="
    },
    "no_picture_image":{
      "bySize":{
        "small_default":{
          "url":"http:....\/img\/p\/fr-default-small_default.jpg",
          "width":98,
          "height":98
        },
        "cart_default":{
          "url":"http:....\/img\/p\/fr-default-cart_default.jpg",
          "width":125,
          "height":125
        },
        "home_default":{
          "url":"http:....\/img\/p\/fr-default-home_default.jpg",
          "width":250,
          "height":250
        },
        "medium_default":{
          "url":"http:....\/img\/p\/fr-default-medium_default.jpg",
          "width":452,
          "height":452
        },
        "large_default":{
          "url":"http:....\/img\/p\/fr-default-large_default.jpg",
          "width":800,
          "height":800
        }
      },
      "small":{
        "url":"http:....\/img\/p\/fr-default-small_default.jpg",
        "width":98,
        "height":98
      },
      "medium":{
        "url":"http:....\/img\/p\/fr-default-home_default.jpg",
        "width":250,
        "height":250
      },
      "large":{
        "url":"http:....\/img\/p\/fr-default-large_default.jpg",
        "width":800,
        "height":800
      },
      "legend":""
    }
  },
  "configuration":{
    "display_taxes_label":true,
    "is_catalog":false,
    "show_prices":true,
    "opt_in":{
      "partner":true
    },
    "quantity_discount":{
      "type":"discount",
      "label":"Remise"
    },
    "voucher_enabled":0,
    "return_enabled":0
  },
  "field_required":[],
  "breadcrumb":{
    "links":[
      {
        "title":"Accueil",
        "url":"http:....\/fr\/"
      }
    ],
    "count":1
  },
  "link":{
    "protocol_link":"http:\/\/",
    "protocol_content":"http:\/\/"
  },
  "time":1550830938,
  "static_token":"4ff2c507d70d274d410ad3fa3e14c0ec",
  "token":"19ad32640de8ee888cfc705fc5ef0db3"
};

Remarque : Il est possible d'ajouter des informations dans cette variable en utilisant le hook actionBuildFrontEndObject.