magento 检测 订单号, 是否真的存在/ sales/order_item 表进行查找 里面所有字段

来源:互联网 发布:linux系统安装软件 编辑:程序博客网 时间:2024/06/06 13:57
/* $order = Core::getModel('sales/order');$orderItems = $order->getItemsCollection()->addAttributeToSelect('*')->addAttributeToFilter('product_type', array('eq'=>'simple'));print_r($orderItems);die; */  这是对   sales/order_item  表进行查找 里面所有字段$orderItems = Core::getModel('sales/order_item')->getCollection()->addAttributeToSelect('*')->addAttributeToFilter('product_type', array('eq'=>'simple'));//print_r($orderItems);die;foreach($orderItems as $sItem) {    if($sItem->getProductType() == "simple")    {        //print_r($sItem);die();        //echo "\n*********************************\nCore Order #: ".$OrderNumber."\n";        //Simple Item Info from Order        echo "<pre>";        echo "Type: ".$sItem->getProductType()."\n";        echo "Order Id: ".$sItem->getOrderId()."\n";        echo "Product Id: ".$sItem->getProductId()."\n";        echo "Item Id: ".$sItem->getId()."\n";        echo "Item Name: ".$sItem->getName()."\n";        echo "Item Sku: ".$sItem->getSku()."\n";        echo "Item Price: ".$sItem->getPrice()."\n";        $pItemId = $sItem->getParentItemId();        echo "Parent Item Id: ".$pItemId."\n";        echo "\n*****\n";        //Get Parent Item Information        $item = Core::getModel('sales/order_item')->load("$pItemId"); //use an item_id here        //Testing, want to see whats inside the parent/configurable item?        //print_r($item->toArray());        echo "Parent Type: ".$item->getProductType()."\n";        echo "Parent Order Id: ".$item->getOrderId()."\n";        echo "Product Id: ".$item->getProductId()."\n";        echo "Item Id: ".$item->getId()."\n";        echo "Parent Item Price: ".$item->getPrice()."\n";        echo "Qty: ".$qty = intval($item->getQtyOrdered())."\n";        //get Active Product Data        $nProduct = Core::getModel('catalog/product')->load($sItem->getProductId());        $nSku = $nProduct->getSku();        echo "new Product UPC:".$nUpc = $nProduct->getUpc() . "\n";        echo "new Product Price:".$nPrice = $nProduct->getPrice(). "\n";        echo '......................................................................';    }}以下是做个简单测试,,检测  订单号, 是否真的存在。。。。<pre style="" class="default prettyprint prettyprinted"><code><span class="pln">$collection </span><span class="pun">=</span><span class="pln"> </span><span class="typ">Mage</span><span class="pun">::</span><span class="pln">getModel</span><span class="pun">(</span><span class="str">'sales/order'</span><span class="pun">)-></span><span class="pln">getCollection</span><span class="pun">()-></span><span class="pln">addFieldToFilter</span><span class="pun">(</span><span class="str">'increment_id'</span><span class="pun">,</span><span class="pln"> $reservedOrderId</span><span class="pun">);</span><span class="pln"></span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">$collection</span><span class="pun">-></span><span class="pln">count</span><span class="pun">())</span><span class="pln"> </span><span class="pun">{</span><span class="pln">    </span><span class="com">// order already exists</span><span class="pln"></span><span class="pun">}</span></code>


$increment_id   = '100000002';$order          = Mage::getModel('sales/order')->loadByIncrementId($increment_id);if($order->getIncrementId() == $increment_id){    var_dump("Increment IDs match, that means there's an order");}else{    var_dump("Increment IDs don't match, that means there's no order");}



$increment_id   = '100000002';$order          = Mage::getModel('sales/order')->loadByIncrementId($increment_id);if($order->getData()){    var_dump("Data array means there's an order");}else{    var_dump("Empty data array means there's no order");}



$increment_id   =   '100000002';$c              =   Mage::getModel('sales/order')->getCollection()                    ->addFieldToFilter('increment_id',$increment_id);        if(count($c) > 0){    var_dump("A collection with more than zero items means the order exists");}else{    var_dump("An empty collection means it does not");}



0 0
原创粉丝点击