/** * Get list of shop urls * * @param bool $id_shop * @return PrestaShopCollection Collection of ShopUrl */ public static function getShopUrls($id_shop = false) { $urls = new PrestaShopCollection('ShopUrl'); if ($id_shop) { $urls->where('id_shop', '=', $id_shop); } return $urls; }
public static function getAllThemes($excluded_ids = false) { $themes = new PrestaShopCollection('Theme'); if (is_array($excluded_ids) && !empty($excluded_ids)) { $themes->where('id_theme', 'notin', $excluded_ids); } $themes->orderBy('name'); return $themes; }
public static function getShopGroups($active = true) { $groups = new PrestaShopCollection('ShopGroup'); $groups->where('deleted', '=', false); if ($active) { $groups->where('active', '=', true); } return $groups; }
/** * Get Order Payments By Invoice ID * * @param int $id_invoice Invoice ID * @return PrestaShopCollection Collection of OrderPayment */ public static function getByInvoiceId($id_invoice) { $payments = Db::getInstance()->executeS('SELECT id_order_payment FROM `' . _DB_PREFIX_ . 'order_invoice_payment` WHERE id_order_invoice = ' . (int) $id_invoice); if (!$payments) { return array(); } $payment_list = array(); foreach ($payments as $payment) { $payment_list[] = $payment['id_order_payment']; } $payments = new PrestaShopCollection('OrderPayment'); $payments->where('id_order_payment', 'IN', $payment_list); return $payments; }
/** * Get a collection of shops * * @param bool $active * @param int $id_shop_group * @return PrestaShopCollection Collection of Shop */ public static function getShopsCollection($active = true, $id_shop_group = null) { $shops = new PrestaShopCollection('Shop'); if ($active) { $shops->where('active', '=', 1); } if ($id_shop_group) { $shops->where('id_shop_group', '=', (int) $id_shop_group); } return $shops; }
/** * Return collection of order invoice object linked to the payments of the current order invoice object * * @since 1.5.0.14 * @return PrestaShopCollection|array Collection of OrderInvoice or empty array */ public function getSibling() { $query = new DbQuery(); $query->select('oip2.id_order_invoice'); $query->from('order_invoice_payment', 'oip1'); $query->innerJoin('order_invoice_payment', 'oip2', 'oip2.id_order_payment = oip1.id_order_payment AND oip2.id_order_invoice <> oip1.id_order_invoice'); $query->where('oip1.id_order_invoice = ' . $this->id); $invoices = Db::getInstance()->executeS($query); if (!$invoices) { return array(); } $invoice_list = array(); foreach ($invoices as $invoice) { $invoice_list[] = $invoice['id_order_invoice']; } $payments = new PrestaShopCollection('OrderInvoice'); $payments->where('id_order_invoice', 'IN', $invoice_list); return $payments; }
/** * Get all other orders with the same reference * * @since 1.5.0.13 */ public function getBrother() { $collection = new PrestaShopCollection('order'); $collection->where('reference', '=', $this->reference); $collection->where('id_order', '<>', $this->id); return $collection; }
/** * Return an array of all parents of the current category * * @param int $id_lang * @return PrestaShopCollection Collection of Category */ public function getAllParents($id_lang = null) { if (is_null($id_lang)) { $id_lang = Context::getContext()->language->id; } $categories = new PrestaShopCollection('Category', $id_lang); $categories->where('nleft', '<', $this->nleft); $categories->where('nright', '>', $this->nright); return $categories; }
/** * Get collection from module name * @static * @param $module string Module name * @param null $id_lang integer Language ID * @return array|Collection Collection of tabs (or empty array) */ public static function getCollectionFromModule($module, $id_lang = null) { if (is_null($id_lang)) { $id_lang = Context::getContext()->language->id; } if (!Validate::isModuleName($module)) { return array(); } $tabs = new PrestaShopCollection('Tab', (int) $id_lang); $tabs->where('module', '=', $module); return $tabs; }
/** * Assigns template vars related to order tracking information * * @param PrestaShopCollection $order_collection * * @throws PrestaShopException */ protected function assignOrderTracking($order_collection) { $customer = new Customer((int) $order_collection->getFirst()->id_customer); $order_collection = $order_collection->getAll(); $order_list = array(); foreach ($order_collection as $order) { $order_list[] = $order; } foreach ($order_list as &$order) { /** @var Order $order */ $order->id_order_state = (int) $order->getCurrentState(); $order->invoice = OrderState::invoiceAvailable((int) $order->id_order_state) && $order->invoice_number; $order->order_history = $order->getHistory((int) $this->context->language->id, false, true); $order->carrier = new Carrier((int) $order->id_carrier, (int) $order->id_lang); $order->address_invoice = new Address((int) $order->id_address_invoice); $order->address_delivery = new Address((int) $order->id_address_delivery); $order->inv_adr_fields = AddressFormat::getOrderedAddressFields($order->address_invoice->id_country); $order->dlv_adr_fields = AddressFormat::getOrderedAddressFields($order->address_delivery->id_country); $order->invoiceAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($order->address_invoice, $order->inv_adr_fields); $order->deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($order->address_delivery, $order->dlv_adr_fields); $order->currency = new Currency($order->id_currency); $order->discounts = $order->getCartRules(); $order->invoiceState = Validate::isLoadedObject($order->address_invoice) && $order->address_invoice->id_state ? new State((int) $order->address_invoice->id_state) : false; $order->deliveryState = Validate::isLoadedObject($order->address_delivery) && $order->address_delivery->id_state ? new State((int) $order->address_delivery->id_state) : false; $order->products = $order->getProducts(); $order->customizedDatas = Product::getAllCustomizedDatas((int) $order->id_cart); Product::addCustomizationPrice($order->products, $order->customizedDatas); $order->total_old = $order->total_discounts > 0 ? (double) $order->total_paid - (double) $order->total_discounts : false; if ($order->carrier->url && $order->shipping_number) { $order->followup = str_replace('@', $order->shipping_number, $order->carrier->url); } $order->hook_orderdetaildisplayed = Hook::exec('displayOrderDetail', array('order' => $order)); Hook::exec('actionOrderDetail', array('carrier' => $order->carrier, 'order' => $order)); } $this->context->smarty->assign(array('shop_name' => Configuration::get('PS_SHOP_NAME'), 'order_collection' => $order_list, 'return_allowed' => false, 'invoiceAllowed' => (int) Configuration::get('PS_INVOICE'), 'is_guest' => true, 'group_use_tax' => Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC, 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'use_tax' => Configuration::get('PS_TAX'))); }
/** * For a given product, gets its warehouses * * @param int $id_product * @return PrestaShopCollection The type of the collection is WarehouseProductLocation */ public static function getCollection($id_product) { $collection = new PrestaShopCollection('WarehouseProductLocation'); $collection->where('id_product', '=', (int) $id_product); return $collection; }
/** * @static * @param $id_customer * @return bool */ public static function deleteByIdCustomer($id_customer) { $return = true; $cart_rules = new PrestaShopCollection('CartRule'); $cart_rules->where('id_customer', '=', $id_customer); foreach ($cart_rules as $cart_rule) { $return &= $cart_rule->delete(); } return $return; }
/** * Exports CSV */ protected function renderCSV() { // exports orders if (Tools::isSubmit('csv_orders')) { $ids = array(); foreach ($this->_list as $entry) { $ids[] = $entry['id_supply_order']; } if (count($ids) <= 0) { return; } $id_lang = Context::getContext()->language->id; $orders = new PrestaShopCollection('SupplyOrder', $id_lang); $orders->where('is_template', '=', false); $orders->where('id_supply_order', 'in', $ids); $id_warehouse = $this->getCurrentWarehouse(); if ($id_warehouse != -1) { $orders->where('id_warehouse', '=', $id_warehouse); } $orders->getAll(); $csv = new CSV($orders, $this->l('supply_orders')); $csv->export(); } elseif (Tools::isSubmit('csv_orders_details')) { // header header('Content-type: text/csv'); header('Content-Type: application/force-download; charset=UTF-8'); header('Cache-Control: no-store, no-cache'); header('Content-disposition: attachment; filename="' . $this->l('supply_orders_details') . '.csv"'); // echoes details $ids = array(); foreach ($this->_list as $entry) { $ids[] = $entry['id_supply_order']; } if (count($ids) <= 0) { return; } // for each supply order $keys = array('id_product', 'id_product_attribute', 'reference', 'supplier_reference', 'ean13', 'upc', 'name', 'unit_price_te', 'quantity_expected', 'quantity_received', 'price_te', 'discount_rate', 'discount_value_te', 'price_with_discount_te', 'tax_rate', 'tax_value', 'price_ti', 'tax_value_with_order_discount', 'price_with_order_discount_te', 'id_supply_order'); echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $keys))); // overrides keys (in order to add FORMAT calls) $keys = array('sod.id_product', 'sod.id_product_attribute', 'sod.reference', 'sod.supplier_reference', 'sod.ean13', 'sod.upc', 'sod.name', 'FORMAT(sod.unit_price_te, 2)', 'sod.quantity_expected', 'sod.quantity_received', 'FORMAT(sod.price_te, 2)', 'FORMAT(sod.discount_rate, 2)', 'FORMAT(sod.discount_value_te, 2)', 'FORMAT(sod.price_with_discount_te, 2)', 'FORMAT(sod.tax_rate, 2)', 'FORMAT(sod.tax_value, 2)', 'FORMAT(sod.price_ti, 2)', 'FORMAT(sod.tax_value_with_order_discount, 2)', 'FORMAT(sod.price_with_order_discount_te, 2)', 'sod.id_supply_order'); foreach ($ids as $id) { $query = new DbQuery(); $query->select(implode(', ', $keys)); $query->from('supply_order_detail', 'sod'); $query->leftJoin('supply_order', 'so', 'so.id_supply_order = sod.id_supply_order'); $id_warehouse = $this->getCurrentWarehouse(); if ($id_warehouse != -1) { $query->where('so.id_warehouse = ' . (int) $id_warehouse); } $query->where('sod.id_supply_order = ' . (int) $id); $query->orderBy('sod.id_supply_order_detail DESC'); $resource = Db::getInstance()->query($query); // gets details while ($row = Db::getInstance()->nextRow($resource)) { echo sprintf("%s\n", implode(';', array_map(array('CSVCore', 'wrap'), $row))); } } } elseif (Tools::isSubmit('csv_order_details') && Tools::getValue('id_supply_order')) { $supply_order = new SupplyOrder((int) Tools::getValue('id_supply_order')); if (Validate::isLoadedObject($supply_order)) { $details = $supply_order->getEntriesCollection(); $details->getAll(); $csv = new CSV($details, $this->l('supply_order') . '_' . $supply_order->reference . '_details'); $csv->export(); } } }
/** * Remove all downloadable files for product and its attributes * * @return bool */ public function deleteDownload() { $result = true; $collection_download = new PrestaShopCollection('ProductDownload'); $collection_download->where('id_product', '=', $this->id); foreach ($collection_download as $product_download) { /** @var ProductDownload $product_download */ $result &= $product_download->delete($product_download->checkFile()); } return $result; }
/** * For a given product, retrieves its suppliers * * @param int $id_product * @param int $group_by_supplier * @return Collection */ public static function getSupplierCollection($id_product, $group_by_supplier = true) { $suppliers = new PrestaShopCollection('ProductSupplier'); $suppliers->where('id_product', '=', (int) $id_product); if ($group_by_supplier) { $suppliers->groupBy('id_supplier'); } return $suppliers; }
/** * For a given product, retrieves the stock collection * * @param int $id_product * @param int $id_product_attribute * @param int $id_warehouse Optional * @param int $price_te Optional * @return PrestaShopCollection Collection of Stock */ protected function getStockCollection($id_product, $id_product_attribute, $id_warehouse = null, $price_te = null) { $stocks = new PrestaShopCollection('Stock'); $stocks->where('id_product', '=', $id_product); $stocks->where('id_product_attribute', '=', $id_product_attribute); if ($id_warehouse) { $stocks->where('id_warehouse', '=', $id_warehouse); } if ($price_te) { $stocks->where('price_te', '=', $price_te); } return $stocks; }
/** * Retrieves the details entries (i.e. products) collection for the current order * * @return PrestaShopCollection Collection of SupplyOrderDetail */ public function getEntriesCollection() { $details = new PrestaShopCollection('SupplyOrderDetail'); $details->where('id_supply_order', '=', $this->id); return $details; }
public static function getThemes() { $themes = new PrestaShopCollection('Theme'); $themes->orderBy('name'); return $themes; }