magento如何获取已激活的支付方式清单 获取所有的配送方式

magento获取订单支付方式详细说明
    
require_once 'app/Mage.php';  
    Mage::app ( 'default' );  
    $orderid = $_GET["orderId"];  
      
    $order = Mage::getModel ( 'sales/order' )->loadByIncrementId ($orderid);  
    echo Mage::helper('payment')->getInfoBlock($order->getPayment())->toHtml();  



magento如何获取已激活的支付方式清单
http://www.magentolog.com/category/%E5%89%8D%E6%AE%B5%E7%AC%94%E8%AE%B0/%E5%BC%80%E5%8F%91%E7%AC%94%E8%AE%B0/


此代码类会获取所有活动的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);

得到一些这样的信息:
    [rate_id] => 14
            [address_id] => 2
            [created_at] => 2014-08-11 11:24:31
            [updated_at] => 2014-10-22 00:27:18
            [carrier] => ems
            [carrier_title] => EMS
            [code] => ems_ems
            [method] => ems
            [method_description] =>
            [price] => 10.0000
            [error_message] =>
            [method_title] => EMS

*********************************************************************************************


 得到一些相关属性数据的操作:、 这是网址:http://wabism.com/magento-product-collections/

// 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.'"/>';




得到购物车里的值 :::::

$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;




获取所有的配送方式:如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"就行了,希望对大家有所帮助



2. 最近一个订单
$_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());



php提取字符串中的数字


 第一种方法,使用正则表达式:

    
function findNum($str=''){
    $str=trim($str);
    if(empty($str)){return '';}
    $reg='/(\d{3}(\.\d+)?)/is';//匹配数字的正则表达式
    preg_match_all($reg,$str,$result);
    if(is_array($result)&&!empty($result)&&!empty($result[1])&&!empty($result[1][0])){
        return $result[1][0];
    }
    return '';
}

第二种方法,使用in_array方法:

    
function findNum($str=''){
    $str=trim($str);
    if(empty($str)){return '';}
    $temp=array('1','2','3','4','5','6','7','8','9','0');
    $result='';
    for($i=0;$i<strlen($str);$i++){
        if(in_array($str[$i],$temp)){
            $result.=$str[$i];
        }
    }
    return $result;
}
第三种方法,使用is_numeric函数:


    
function findNum($str=''){
    $str=trim($str);
    if(empty($str)){return '';}
    $result='';
    for($i=0;$i<strlen($str);$i++){
        if(is_numeric($str[$i])){
            $result.=$str[$i];
        }
    }
    return $result;
}






 
 Magento获取当前购物车产品总数量和总价格
//http://my.oschina.net/liufeng815/blog?catalog=323958

    // $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(19);
$allDesignedIds = getAllChildrenOfCategory(18);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值