Magento获取订单支付方式详细说明:
require_once 'app/Mage.php'; Mage::app ( 'default' ); $orderid = "0000001"; $order = Mage::getModel ( 'sales/order' )->loadByIncrementId ($orderid); echo Mage::helper('payment')->getInfoBlock($order->getPayment())->toHtml();
Magento获取已激活的支付方式清单
此代码类会获取所有活动的Magento支付模块。下面这个例子返回一个数组,你可以用它来创建下拉菜单或东西在Magento的前端或其他地方
class Inchoo_Vendor_Model_Activpayment { public function getActivPaymentMethods() { $payments = Mage::getSingleton('payment/config')->getActiveMethods(); $methods = array(array('value'=>'', 'label'=>Mage::helper('adminhtml')->__('--Please Select--'))); foreach ($payments as $paymentCode=>$paymentModel) { $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title'); $methods[$paymentCode] = array( 'label' => $paymentTitle, 'value' => $paymentCode, ); //print_r($paymentModel->getData()); //echo $paymentCode; } return $methods; } } $cc=Core::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingRatesCollection()->getData(); print_r($cc);
Magento 得到一些相关属性数据的操作
// Let's load the category Model and grab the product collection of that category $product_collection = Mage::getModel('catalog/category')->load($categoryId)->getProductCollection(); // Now let's loop through the product collection and print the ID of every product in the collection foreach($product_collection as $product) { // Get the product ID $product_id = $product->getId(); // Load the full product model based on the product ID $full_product = Mage::getModel('catalog/product')->load($product_id); // Now that we loaded the full product model, let's access all of it's data // Let's get the Product Name $product_name = $full_product->getName(); // Let's get the Product URL path $product_url = $full_product->getProductUrl(); // Let's get the Product Image URL $product_image_url = $full_product->getImageUrl(); // Let's print the product information we gathered and continue onto the next one echo'<a href="'.$product_url.'">'.$product_name.'</a>'; echo '<img src="'.$product_image_url.'"/>';
Magento 得到购物车里的值
$totalQuantity = Core::getModel('checkout/cart')->getQuote()->getCollection()->getData(); //得到Quote 购物车的数据。 $totalQuantity = Core::getModel('checkout/cart')->getQuote()->getItemsQty(); $totalItems = Core::getModel('checkout/cart')->getQuote()->getItemsCount(); print_r($totalQuantity);die;
Magento 获取所有的配送方式:如EMS SF……
$methods = Core::getSingleton('shipping/config')->getActiveCarriers(); $options = array(); foreach($methods as $_code => $_method) { if(!$_title = Core::getStoreConfig("carriers/$_code/title")) $_title = $_code; $options[] = array('value' => $_code, 'label' => $_title . " ($_code)"); } echo "<xmp>"; print_r($options); echo "</xmp>";
获取当前订单的第一个值 。
$order = Core::getModel('sales/order')->loadByIncrementId($orderId); // 100011448 $shippingTitle = $order->getCollection()->getFirstItem()->getEntityId(); print_r($shippingTitle);
Magento根据产品(Product)获取类别(Category)名字及URL
$_categoryIds = $_product->getCategoryIds(); foreach ($_categoryIds as $_categoryId) { $_category = Mage::getModel('catalog/category')->load($_categoryId); $_category_name = $_category->getName(); $_category_url = $_category->getUrlPath(); break; }
Magento 获取原价格和打折价格 get Special price or Regular Price in magento
<?php $product= Mage::getModel('catalog/product')->load(product_id); $price = $product->getPrice(); $webprice = $product->getwebprice(); $specialprice = $product->getFinalPrice(); if($specialprice==$price) {?> <span>$<?php echo number_format($price,2);?> </span> <?php } else { ?> <div> <span>Regular Price:</span> <span>$ <?php echo number_format($price,2); ?> </span> </div> <div> <span>Web Special:</span> <span>$ <?php echo number_format($specialprice,2); ?> </span> </div> <?php } ?>
magento 获取国家的名称
Core::getModel("cms/storelocator")->getAllRegion(); //获取所有的信息。 城市 $customer = Mage::getSingleton('customer/session')->getCustomer();//获取顾客的信息 $countryCode = $customer->getDefaultBillingAddress()->getCountry();//获取顾客国家的信息,这里一般获取到的都是缩写,例如:US $country = Mage::getModel('directory/country')->loadByCode($countryCode);//获取国家对象 echo $country->getName(); //获取到国家名称
这样就获取到了。如果你直接有”country_id”,那就可以直接从第三步开始,把$countryCode换成”country_id”就行了
Magento 最近一个订单
$_customer = Mage::getModel('customer/customer'); $_customer->loadByEmail('someemail@somewhere.co.uk'); // get the customers last order $orders = Mage::getResourceModel('sales/order_collection') ->addFieldToSelect('*') ->addFieldToFilter('customer_id', $_customer->getId()) ->addAttributeToSort('created_at', 'DESC') ->setPageSize(1); echo $orders->getFirstItem()->getId(); $order = $observer->getEvent()->getOrder(); // or where ever the order is located in your observer event echo $order->getShippingDescription(); $shipping = $order->getShippingAddress()->getShippingMethod(); var_dump($shipping->getData());
Magento获取当前购物车产品总数量和总价格
// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems(); $items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems(); foreach($items as $item) { echo 'ID: '.$item->getProductId().'<br />'; echo 'Name: '.$item->getName().'<br />'; echo 'Sku: '.$item->getSku().'<br />'; echo 'Quantity: '.$item->getQty().'<br />'; echo 'Price: '.$item->getPrice().'<br />'; echo "<br />"; } Get total items and total quantity in cart $totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount(); $totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty(); Get subtotal and grand total price of cart $subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal(); $grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
Magento获取指定分类下的所有子分类信息
/** * 输入:某一个分类的ID数字 * 返回: 该分类下所有子分类的ID组成的数组 * 可用于: 模板文件中可以直接使用,也可以用于action等文件类内部 * 实现思路:使用队列的方法实现非递归,对树从上往下遍历 **/ function getAllChildrenOfCategory($cateid){ $resArr = array();//结果数组 $queueArr = array();//队列数组 array_push($queueArr,$cateid); while($currentcid = array_pop($queueArr)){ array_push($resArr,$currentcid); //处理当前节点的孩子节点 $_category = Mage::getModel('catalog/category')->load($currentcid); $subcats = $_category->getChildren(); $idarrs = explode(',',$subcats); foreach($idarrs as $subCatid){ if(!$subCatid) continue; $_subcategory = Mage::getModel('catalog/category')->load($subCatid); if($_subcategory->getIsActive()) { array_push($queueArr,$subCatid); } } reset($queueArr); } return $resArr; } //测试一下 $allProducerIds = getAllChildrenOfCategory(1); $allDesignedIds = getAllChildrenOfCategory(16);
更多的方法
Magento 通过SKU 或 属性获取产品和目录
Magento 通过订单号获取订单所有信息
转载请注明:(●--●) Hello.My Weicot » magento 获取支付 配送 属性 价格及购物车信息等方法