Intereting Posts
Как использовать PATCH для обновления простого поля базы данных? Как загрузить файл с SFTP-сервера с помощью PHP Лучший способ загрузить php-классы в EC2 – InstanceStore, EBS или S3? Проблемы с маршрутизацией URI для модулей в Zend Framework 404 при отправке формы отображать дату / время на базе сайта на компьютерном времени пользователя в разных странах Автоматически генерируемый порядковый номер, начиная с 001 (ТОЛЬКО ДЛЯ 3 ЦИФРОВ) – PHP / MYSQL Передача переменных PHP в MySQL Как получить стоимость акций RealTime, используя финансирование yahoo Как переопределить метод CActiveDataProvider, чтобы показать CGridview в порядке убывания по умолчанию в Yii Создать базу данных в Shell Script – конвертировать из PHP Yii2: получить выбранные данные строк из столбцов столбца gridView в контроллер вычислить разницу между двумя временными метками в php Twitter json API иностранные символы Существуют ли какие-либо компиляторы XSLT для C ++?

Запрос списка заказов magento

Я хочу выбрать список всех заказов в Magento.

Мне необходимо показать список всех заказов от magento в другом приложении PHP, в котором я сейчас работаю.

Также может кто-нибудь написать мне код, используя соглашения Magento, такие как Mage::

Im с использованием версии Magento 1.4.2.

Благодаря,
отметка

Этот код использует «путь Magento» и получает доступ к данным через слой модели, который изолирует вас от изменений в структуре таблицы (например, flat vs EAV). Создайте новый PHP-файл, содержащий этот код скелета, в корневой папке вашей установки Magento (если в другом месте обновляется путь к первому require ).

Это дает вам несколько примеров того, как добавлять атрибуты в коллекцию, вы должны следовать примерам, чтобы добавить больше, если это необходимо. Он показывает, как фильтровать по атрибутам и сортировать по атрибутам. Примеры также для выделения полей, которые вам нужны.

НТН,
JD

 require_once 'app/Mage.php'; umask(0); Mage::app('default'); $orders = Mage::getResourceModel('sales/order_collection') ->addAttributeToSelect('*') ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left') ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left') ->joinAttribute('billing_street', 'order_address/street', 'billing_address_id', null, 'left') ->joinAttribute('billing_company', 'order_address/company', 'billing_address_id', null, 'left') ->joinAttribute('billing_city', 'order_address/city', 'billing_address_id', null, 'left') ->joinAttribute('billing_region', 'order_address/region', 'billing_address_id', null, 'left') ->joinAttribute('billing_country', 'order_address/country_id', 'billing_address_id', null, 'left') ->joinAttribute('billing_postcode', 'order_address/postcode', 'billing_address_id', null, 'left') ->joinAttribute('billing_telephone', 'order_address/telephone', 'billing_address_id', null, 'left') ->joinAttribute('billing_fax', 'order_address/fax', 'billing_address_id', null, 'left') ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_street', 'order_address/street', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_company', 'order_address/company', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_city', 'order_address/city', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_region', 'order_address/region', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_country', 'order_address/country_id', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_postcode', 'order_address/postcode', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_telephone', 'order_address/telephone', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_fax', 'order_address/fax', 'shipping_address_id', null, 'left') ->addFieldToFilter('status', array("in" => array( 'complete', 'closed') )) ->addAttributeToFilter('store_id', Mage::app()->getStore()->getId()) ->addAttributeToSort('created_at', 'asc') ->load(); foreach($orders as $order): echo $order->getIncrementId().'<br/>'; echo $order->getShippingTelephone().'<br/>'; endforeach; по require_once 'app/Mage.php'; umask(0); Mage::app('default'); $orders = Mage::getResourceModel('sales/order_collection') ->addAttributeToSelect('*') ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left') ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left') ->joinAttribute('billing_street', 'order_address/street', 'billing_address_id', null, 'left') ->joinAttribute('billing_company', 'order_address/company', 'billing_address_id', null, 'left') ->joinAttribute('billing_city', 'order_address/city', 'billing_address_id', null, 'left') ->joinAttribute('billing_region', 'order_address/region', 'billing_address_id', null, 'left') ->joinAttribute('billing_country', 'order_address/country_id', 'billing_address_id', null, 'left') ->joinAttribute('billing_postcode', 'order_address/postcode', 'billing_address_id', null, 'left') ->joinAttribute('billing_telephone', 'order_address/telephone', 'billing_address_id', null, 'left') ->joinAttribute('billing_fax', 'order_address/fax', 'billing_address_id', null, 'left') ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_street', 'order_address/street', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_company', 'order_address/company', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_city', 'order_address/city', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_region', 'order_address/region', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_country', 'order_address/country_id', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_postcode', 'order_address/postcode', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_telephone', 'order_address/telephone', 'shipping_address_id', null, 'left') ->joinAttribute('shipping_fax', 'order_address/fax', 'shipping_address_id', null, 'left') ->addFieldToFilter('status', array("in" => array( 'complete', 'closed') )) ->addAttributeToFilter('store_id', Mage::app()->getStore()->getId()) ->addAttributeToSort('created_at', 'asc') ->load(); foreach($orders as $order): echo $order->getIncrementId().'<br/>'; echo $order->getShippingTelephone().'<br/>'; endforeach; 

Попробуй это:

 select * from sales_flat_order; 

Это информация уровня заголовка. Если вам нужна информация о позиции или более глубокая информация, вы можете использовать что-то вроде следующего соединения:

 select e.*,sfoi.* from sales_flat_order e left join sales_flat_order_item sfoi on (e.entity_id=sfoi.order_id) 

Теперь это будет дублировать (декартово произведение) всю информацию заголовка вместе с информацией о позиции. Если вам требуется что-то еще, дайте мне знать, я владелец Magento EAV SQL 🙂

Немного поздно, но это может быть полезно (протестировано в Magento CE 1.7.0.2). Код очень прокомментирован для руководства.

 <?php // include the core code we are going to use require_once('app/Mage.php'); umask (0); Mage::app('default'); // resources $resource = Mage::getSingleton('core/resource'); // db access $db_read = $resource->getConnection('core_read'); $db_write = $resource->getConnection('core_write'); // support table prefix if one is being used $table_prefix = Mage::getConfig()->getTablePrefix(); // count the orders $order_num = $db_read->fetchOne("SELECT COUNT(*) AS num FROM {$table_prefix}sales_flat_order WHERE status = 'pending'"); // get an array of the orders $orders = $db_read->fetchAll("SELECT sales.* FROM {$table_prefix}sales_flat_order AS sales WHERE sales.status = 'pending'"); // start iterating through the orders for($i=0; $i < intval($order_num); $i++) { // order id $orderid = $orders[$i]['entity_id']; // shipping address $order_details = Mage::getModel('sales/order')->load($orderid); $shippingAddress = $order_details->getShippingAddress(); // use like so $shippingAddress->getPrefix()); $shippingAddress->getFirstname(); $shippingAddress->getLastname(); $shippingAddress->getCompany(); $shippingAddress->getEmail(); $shippingAddress->getTelephone(); $shippingAddress->getStreetFull(); // billing address $order_details = Mage::getModel('sales/order')->load($orderid); $billingAddress = $order_details->getBillingAddress(); // use like so $billingAddress->getPrefix()); $billingAddress->getFirstname(); $billingAddress->getLastname(); $billingAddress->getCompany(); $billingAddress->getEmail(); $billingAddress->getTelephone(); $billingAddress->getStreetFull(); // and if you want order items, do the following $items = $db_read->fetchAll("SELECT items.order_id AS orderid, items.item_id AS itemid, orders.total_item_count AS total_items_in_order, items.quote_item_id AS quoteid, items.created_at AS orderdate, items.product_type, items.sku AS itemcode, items.name AS itemname, items.price_incl_tax AS itemprice, items.tax_amount AS itemtax, items.discount_amount AS discount, items.qty_ordered AS qty_ordered, items.qty_shipped AS qty_shipped, address.email AS email, address.prefix AS title, address.firstname AS firstname, address.lastname AS lastname, address.street AS address, address.city AS city, address.region AS region, address.country_id AS country, address.postcode AS postcode, address.telephone AS telephone FROM {$table_prefix}sales_flat_order AS orders JOIN {$table_prefix}sales_flat_order_item AS items ON items.order_id = orders.entity_id LEFT JOIN {$table_prefix}sales_flat_order_address AS address ON orders.entity_id = address.parent_id WHERE items.order_id = $orderid AND address.address_type = 'shipping' AND orders.status = 'pending' "); foreach ($items AS $item) { echo $item['itemid']; // blah blah blah } } ?> по <?php // include the core code we are going to use require_once('app/Mage.php'); umask (0); Mage::app('default'); // resources $resource = Mage::getSingleton('core/resource'); // db access $db_read = $resource->getConnection('core_read'); $db_write = $resource->getConnection('core_write'); // support table prefix if one is being used $table_prefix = Mage::getConfig()->getTablePrefix(); // count the orders $order_num = $db_read->fetchOne("SELECT COUNT(*) AS num FROM {$table_prefix}sales_flat_order WHERE status = 'pending'"); // get an array of the orders $orders = $db_read->fetchAll("SELECT sales.* FROM {$table_prefix}sales_flat_order AS sales WHERE sales.status = 'pending'"); // start iterating through the orders for($i=0; $i < intval($order_num); $i++) { // order id $orderid = $orders[$i]['entity_id']; // shipping address $order_details = Mage::getModel('sales/order')->load($orderid); $shippingAddress = $order_details->getShippingAddress(); // use like so $shippingAddress->getPrefix()); $shippingAddress->getFirstname(); $shippingAddress->getLastname(); $shippingAddress->getCompany(); $shippingAddress->getEmail(); $shippingAddress->getTelephone(); $shippingAddress->getStreetFull(); // billing address $order_details = Mage::getModel('sales/order')->load($orderid); $billingAddress = $order_details->getBillingAddress(); // use like so $billingAddress->getPrefix()); $billingAddress->getFirstname(); $billingAddress->getLastname(); $billingAddress->getCompany(); $billingAddress->getEmail(); $billingAddress->getTelephone(); $billingAddress->getStreetFull(); // and if you want order items, do the following $items = $db_read->fetchAll("SELECT items.order_id AS orderid, items.item_id AS itemid, orders.total_item_count AS total_items_in_order, items.quote_item_id AS quoteid, items.created_at AS orderdate, items.product_type, items.sku AS itemcode, items.name AS itemname, items.price_incl_tax AS itemprice, items.tax_amount AS itemtax, items.discount_amount AS discount, items.qty_ordered AS qty_ordered, items.qty_shipped AS qty_shipped, address.email AS email, address.prefix AS title, address.firstname AS firstname, address.lastname AS lastname, address.street AS address, address.city AS city, address.region AS region, address.country_id AS country, address.postcode AS postcode, address.telephone AS telephone FROM {$table_prefix}sales_flat_order AS orders JOIN {$table_prefix}sales_flat_order_item AS items ON items.order_id = orders.entity_id LEFT JOIN {$table_prefix}sales_flat_order_address AS address ON orders.entity_id = address.parent_id WHERE items.order_id = $orderid AND address.address_type = 'shipping' AND orders.status = 'pending' "); foreach ($items AS $item) { echo $item['itemid']; // blah blah blah } } ?> 

Надеюсь, что кто-то поможет!