2

Magento 自動作成注文スクリプトを作成しました。支払い方法を注文書に設定すると問題なく動作しますが、クレジット カードを使用しようとすると注文が作成されません。

私は以下のようにcc情報を使用しますが、今は動作します

 $orderPayment = Mage::getModel('sales/order_payment')
      ->setStoreId($storeId)
      ->setCustomerPaymentId(0)
      ->setMethod('ccsave')
      ->setCcNumber('6011111111111117')
      ->setCcOwner('ooooo')
      ->setCcType('Discover')
      ->setCcExpMonth('9')
      ->setCcExpYear('2014')
      ->setCcLast4(substr('6011111111111117',-4));

以下のように注文書を使用すると機能します

 $orderPayment = Mage::getModel('sales/order_payment')
          ->setStoreId($storeId)
          ->setCustomerPaymentId(0)
          ->setMethod('purchaseorder')
          ->setPo_number(' - ');

私はたくさん試しましたが、誰か助けてください、ここに私の完全なコードがあります

<?php
    //run the reminders

    require_once '../app/Mage.php';
    $app = Mage::app();


    }
    //$products = array('35' => array('qty' => 1));
    $products;
    $order = Mage::getModel('sales/order')->load(50);
    $items = $order->getAllItems();
    $itemcount=count($items);
    foreach ($items as $itemId => $item)
    {
        //echo $item->getName().'<br/>';
       // echo $item->getPrice();
       // echo $item->getSku();
       $idx=$item->getProductId();
        $products[$idx]=array('qty'=>$item->getQtyToInvoice());
       // $products[]= $item->getQtyToInvoice().'<br/>';
    }
    //Mage::getSingleton('customer/session')->logout();

    print_r($products);

    //}      




      $customer = Mage::getModel('customer/customer')->load(16);
      /*$customerId is the id of the customer who is placing the order, it can be passed as an argument to the function place()*/

      $transaction = Mage::getModel('core/resource_transaction');
      $storeId = $customer->getStoreId();
      $reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);

      $order = Mage::getModel('sales/order')
      ->setIncrementId($reservedOrderId)
      ->setStoreId($storeId)
      ->setQuoteId(0)
      ->setGlobal_currency_code('GBP')
      ->setBase_currency_code('GBP')
      ->setStore_currency_code('GBP')
      ->setOrder_currency_code('GBP');

      // set Customer data
      $order->setCustomer_email($customer->getEmail())
      ->setCustomerFirstname($customer->getFirstname())
      ->setCustomerLastname($customer->getLastname())
      ->setCustomerGroupId($customer->getGroupId())
      ->setCustomer_is_guest(0)
      ->setCustomer($customer);

      // set Billing Address
      $billing = $customer->getDefaultBillingAddress();
      $billingAddress = Mage::getModel('sales/order_address')
      ->setStoreId($storeId)
      ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
      ->setCustomerId($customer->getId())
      ->setCustomerAddressId($customer->getDefaultBilling())
      ->setCustomer_address_id($billing->getEntityId())
      ->setPrefix($billing->getPrefix())
      ->setFirstname($billing->getFirstname())
      ->setMiddlename($billing->getMiddlename())
      ->setLastname($billing->getLastname())
      ->setSuffix($billing->getSuffix())
      ->setCompany($billing->getCompany())
      ->setStreet($billing->getStreet())
      ->setCity($billing->getCity())
      ->setCountry_id($billing->getCountryId())
      ->setRegion($billing->getRegion())
      ->setRegion_id($billing->getRegionId())
      ->setPostcode($billing->getPostcode())
      ->setTelephone($billing->getTelephone())
      ->setFax($billing->getFax());
      $order->setBillingAddress($billingAddress);

      $shipping = $customer->getDefaultShippingAddress();
      $shippingAddress = Mage::getModel('sales/order_address')
      ->setStoreId($storeId)
      ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
      ->setCustomerId($customer->getId())
      ->setCustomerAddressId($customer->getDefaultShipping())
      ->setCustomer_address_id($shipping->getEntityId())
      ->setPrefix($shipping->getPrefix())
      ->setFirstname($shipping->getFirstname())
      ->setMiddlename($shipping->getMiddlename())
      ->setLastname($shipping->getLastname())
      ->setSuffix($shipping->getSuffix())
      ->setCompany($shipping->getCompany())
      ->setStreet($shipping->getStreet())
      ->setCity($shipping->getCity())
      ->setCountry_id($shipping->getCountryId())
      ->setRegion($shipping->getRegion())
      ->setRegion_id($shipping->getRegionId())
      ->setPostcode($shipping->getPostcode())
      ->setTelephone($shipping->getTelephone())
      ->setFax($shipping->getFax());

      $order->setShippingAddress($shippingAddress)
      ->setShipping_method('flatrate_flatrate')
      ->setShippingDescription('flatrate');

      $orderPayment = Mage::getModel('sales/order_payment')
      ->setStoreId($storeId)
      ->setCustomerPaymentId(0)
      ->setMethod('ccsave')
      ->setCcNumber('6011111111111117')
      ->setCcOwner('ooooo')
      ->setCcType('Discover')
      ->setCcExpMonth('9')
      ->setCcExpYear('2014')
      ->setCcLast4(substr('6011111111111117',-4));


      /*
      ->setPo_number(' - ');


      ->setCustomerPaymentId(3)
      ->setMethod('ccsave')
      ->setCcNumber('6011111111111117')
      ->setCcOwner('ooooo')
      ->setCcType('Discover')
      ->setCcExpMonth('9');
      ->setCcExpYear('2014');
      ->setCcLast4(substr('6011111111111117',-4));
      */
      $order->setPayment($orderPayment);
    //,'36'=>array('qty' => 1)
      // let say, we have 2 products
      $subTotal = 0;
     // $products = array('35' => array('qty' => 1));
      foreach ($products as $productId=>$product) {
      echo $product['qty'];
      $_product = Mage::getModel('catalog/product')->load($productId);
      $rowTotal = $_product->getPrice() * $product['qty'];
      $orderItem = Mage::getModel('sales/order_item')
      ->setStoreId($storeId)
      ->setQuoteItemId(0)
      ->setQuoteParentItemId(NULL)
      ->setProductId($productId)
      ->setProductType($_product->getTypeId())
      ->setQtyBackordered(NULL)
      ->setTotalQtyOrdered($product['rqty'])
      ->setQtyOrdered($product['qty'])
      ->setName($_product->getName())
      ->setSku($_product->getSku())
      ->setPrice($_product->getPrice())
      ->setBasePrice($_product->getPrice())
      ->setOriginalPrice($_product->getPrice())
      ->setRowTotal($rowTotal)
      ->setBaseRowTotal($rowTotal);

       $subTotal += $rowTotal;
      $order->addItem($orderItem);
      }
    echo $subTotal;
      $order->setSubtotal($subTotal)
      ->setBaseSubtotal($subTotal)
      ->setGrandTotal($subTotal)
      ->setBaseGrandTotal($subTotal);

      $transaction->addObject($order);
      $transaction->addCommitCallback(array($order, 'place'));
      $transaction->addCommitCallback(array($order, 'save'));
      $transaction->save(); 

      $order->sendNewOrderEmail();
    ?>
4

2 に答える 2

0

これは、クレジットカード(保存済み)を使用してプログラムで注文を作成する場合の注文支払いのコードです。

$orderPayment = Mage::getModel('sales/order_payment')
->setStoreId($store_id)
->setCustomerPaymentId(0)
->setMethod($method)
->setCcNumber($cc_number)
->setCcNumberEnc(Mage::getSingleton('payment/info')->encrypt($cc_number)
->setCcOwner($cc_owner)
->setCcType($cc_type)
->setCcExpMonth($cc_exp_month)
->setCcExpYear($cc_exp_year)
->setCcLast4(substr($cc_number,-4));
于 2013-06-27T07:00:54.963 に答える
0

->setCcType('Discover') を間違った方法で使用しています。ここで cc タイプのコードを指定する必要があります。たとえば、Visaの場合は使用する必要があります

->setCcType('VI')

于 2014-08-26T06:59:09.637 に答える