opencart是PHP框架吗,如何成为OpenCart大师?

这篇博客详细介绍了Opencart框架中的一些核心全局库函数,包括缓存管理、购物车操作、设置获取、货币格式化、顾客登录注销等。这些函数在控制器、模型和视图中都可调用,对于理解和操作Opencart商城系统至关重要。
摘要由CSDN通过智能技术生成

全局库方法:基本的opencart库函数及其功能,其中大多数可以从目录中的任何位置或管理文件夹(控制器,模型,视图)中调用CACHE

$this->cache->delete($key) - Deletes cache [product, category, country, zone, language, currency,manufacturer]CART

$this->cart->getProducts() Gets all products currently in the cart including options, discounted prices, etc.$this->cart->add( $product_id, $qty = 1, $options = array()) - Allows you to add a product to the cart

$this->cart->remove( $key ) - Allows you to remove a product from the cart

$this->cart->clear() - Allows you to remove all products from the cart

$this->cart->getWeight() - Sum of the weight of all products in the cart that have require shipping set to Yes$this->cart->getSubTotal() - returns the subtotal of all products added together before tax

$this->cart->getTotal() - returns the total of all products added together after tax

$this->cart->countProducts() - returns the count of all product in the cart

$this->cart->hasProducts() - returns true if there is at least one item in the cart

$this->cart->hasStock() - returns false if there is at least one item in the cart that is out of stock

$this->cart->hasShipping() - returns true if there is at least one item in the cart that requires shipping

$this->cart->hasDownload() - returns true if there is at least one item in the cart that has a download

associated

CONFIG

$this->config->get($key) - returns setting value by keyname based on application (catalog or admin)$this->config->set($key, $value) - set the value to override the setting value. DOES NOT SAVE TO DATABASE

CURRENCY

$this->currency->set($currency) - set or override the currency code to be used in the session

$this->currency->format($number, $currency = '', $value = '', $format = TRUE) - format the currency

$this->currency->convert($value, $from, $to) - convert a value from one currency to another. Currencies must

exist

$this->currency->getId() - get the database entry id for the current currency (1, 2, 3, 4)$this->currency->getCode() - get the 3-letter iso code for the current currency (USD, EUR, GBP, AUD, etc)$this->currency->getValue($currency) - get the current exchange rate from the database for the specified

currency.$this->currency->has(currency) - Check if a currency exists in the opencart currency list

CUSTOMER

$this->customer->login($email, $password) - Log a customer in$this->customer->logout() - Log a customer out$this->customer->isLogged() - check if customer is logged in$this->customer->getId() - get the database entry id for the current customer (integer)$this->customer->getFirstName() - get customer first name

$this->customer->getLastName() - get customer last name

$this->customer->getEmail() - get customer email

$this->customer->getTelephone() - get customer telephone number

$this->customer->getFax() - get customer fax number

$this->customer->getNewsletter() - get customer newsletter status

$this->customer->getCustomerGroupId() - get customer group id

$this->customer->getAddressId() - get customer default address id (maps to the address database field)DATABASE

$this->db->query($sql) - Execute the specified sql statement. Returns row data and rowcount.$this->db->escape($value) - Escape/clean data before entering it into database

$this->db->countAffected($sql) - Returns count of affected rows from most recent query execution

$this->db->getLastId($sql) - Returns last auto-increment id from more recent query execution 4DOCUMENT (*Called from controller only before renderer)$this->document->setTitle($title) - Set page title

$this->document->getTitle()- Get page title

$this->document->setDescription($description) - Set meta description

$this->document->getDescription()- Get meta description

$this->document->setKeywords()- Set meta keywords

$this->document->getKeywords()- Get meta keywords

$this->document->setBase($base) - Set page base$this->document->getBase() - Get page base$this->document->setCharset($charset) - Set page charset

$this->document->getCharset() - Get page charset

$this->document->setLanguage($language) - Set page language

$this->document->getLanguage()- Get page language

$this->document->setDirection($direction) - Set page direction (rtl/ltr)$this->document->getDirection()- Get page direction (rtl/ltr)$this->document->addLink( $href, $rel ) – Add dynamic  tag

$this->document->getLinks()- Get page link tags

$this->document->addStyle( $href, $rel = 'stylesheet', $media = 'screen' ) – Add dynamic style

$this->document->getStyles()- Get page styles

$this->document->addScript( $script ) - Add dynamic script

$this->document->getScripts()- Get page scripts

$this->document->addBreadcrumb($text, $href, $separator = ' > ') – Add breadcrumb

$this->document->getBreadcrumbs()- Get BreadcrumbsENCRYPT

$this->encryption->encrypt($value) - Encrypt data based on key in admin settings

$this->encryption->decrypt($value) - Decrypt data based on key in admin settings

IMAGE

$this->image->resize($width = 0, $height = 0)JSON

$this->json->encode( $data )$this->json->decode( $data , $assoc = FALSE)LANGUAGE

$this->language->load($filename);LENGTH

$this->length->convert($value, $from, $to) - convert a length to another. units must exist

$this->length->format($value, $unit, $decimal_point = '.', $thousand_point = ',') - format the length to useunit

LOG

$this->log->write($message) - Writes to the system error log

REQUEST

$this->request->clean($data) - Cleans the data coming in to prevent XSS

$this->request->get['x'] - Same as $_GET['x']$this->request->post['x'] - Same as $_POST['x']RESPONSE

$this->response->addHeader($header) - additional php header tags can be defined here

$this->response->redirect($url) - redirects to the url specified

TAX

$this->tax->setZone($country_id, $zone_id) - Set the country and zone id for taxing (integer)$this->tax->calculate($value, $tax_class_id, $calculate = TRUE) - Calculate all taxes to be added to the total

$this->tax->getRate($tax_class_id) - Get the rates of a tax class id

$this->tax->getDescription($tax_class_id) - Get the description of a tax class id

$this->tax->has($tax_class_id) - Check if a tax class id exists in opencart

SESSION

$this->session->data['x'] - Same as $_SESSION['x']

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值