Magento의 모든 주문 목록을 선택하고 싶습니다.Magento 주문 목록 쿼리
현재 제가 작업중인 다른 PHP 응용 프로그램에서 magento의 모든 주문 목록을 표시하려면이 기능이 필요합니다.
또한 어떤 하나 젠토에게 1.4.2 버전을 사용하는 등Mage::
임로 나에게 젠토 규칙을 사용하여 코드를 작성할 수 있습니다.
감사합니다,
마크
Magento의 모든 주문 목록을 선택하고 싶습니다.Magento 주문 목록 쿼리
현재 제가 작업중인 다른 PHP 응용 프로그램에서 magento의 모든 주문 목록을 표시하려면이 기능이 필요합니다.
또한 어떤 하나 젠토에게 1.4.2 버전을 사용하는 등Mage::
임로 나에게 젠토 규칙을 사용하여 코드를 작성할 수 있습니다.
감사합니다,
마크
이 코드는 "Magento way"를 사용하고 모델 구조를 통해 데이터에 액세스하여 테이블 구조의 변경을 방지합니다. (예 : 평면 대 EAV). Magento 설치의 루트에이 뼈대 코드를 포함하는 새로운 PHP 파일을 만듭니다 (다른 곳에서 첫 번째 require
문에 대한 경로를 업데이트하는 경우).
여기에는 컬렉션에 속성을 추가하는 방법에 대한 몇 가지 예가 나와 있으므로 필요에 따라 예제를 따라 추가 할 수 있습니다. 속성별로 필터링하고 속성별로 정렬하는 방법을 보여줍니다. 필요한 필드를 반향 출력하는 예제입니다.
HTH,
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;
이 시도 :
헤더 수준의 정보입니다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를 사용하고 있습니다. 1.4.2.wehn "Table 'pigi_magento.sales_order'가 존재하지 않는 상위 2 개 쿼리를 실행합니다. –
업데이트보기 - 새 플랫 테이블 모델을 사용 중입니다. – philwinkle
감사합니다. Magento의 데이터베이스 구조를 reg로 배울 수 있습니다. 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
}
}
?>
누군가를 돕는 희망!
지금까지 해보신 것은 무엇입니까? 또한 이전 질문에 대한 몇 가지 대답을 수락하면 답을 얻는 데 더 많은 행운을 얻게 될 것입니다. –