コード例 #1
0
	function setupPremium($item,$customer,$order,$data)
	{
		/*
		 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
		`customer_id` int(10) unsigned NOT NULL,
		`product_id` int(10) unsigned NOT NULL,
		`order_item_id` int(10) unsigned DEFAULT NULL,
		`order_number` varchar(255) DEFAULT NULL,
		`product_name` varchar(255) DEFAULT NULL,
		`sku` varchar(255) DEFAULT NULL,
		`expiration` datetime DEFAULT NULL,
		`emails_sent` int(10) unsigned NOT NULL DEFAULT '0',
		`seats_total` int(6) DEFAULT NULL,
		`registered` int(1) DEFAULT NULL,
		`notes` text,
		`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		`created_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
		*/
		//echo "\n\n\n\n";



		$product = Mage::getModel('catalog/product');
		$product -> load($product -> getIdBySku($item->getSku()));

		//die;

		$data = array_pop($this->premiums[$item->getSku()]);
		print_r($data);
			
		if(!$this->conn)
		{
			$this->setupDb();
		}
		$q = "INSERT INTO `ecodes_premium_subs`
		(`customer_id`,`product_id`,`order_item_id`,`order_number`,`product_name`,`sku`,
		`expiration`,`emails_sent`,`seats_total`,`registered`,`notes`)
		VALUES
		('".$customer->getEntityId()."',
		'".$product->getId()."',
		'".$item->getId()."',
		'".$order->getId()."',
		'".$item->getName()."',
		'".$product->getSku()."',
		'".date("Y-m-d H:i:s",strtotime($data['subscription_end_date']))."',
		'3',
		'".$data['subscription_num_users']."',
		'1',
		'Historical Import')";
		echo "Historical import\n";
		echo $q;
		$res2 = mysql_query($q,$this->conn);
		if(!$res2)
		{
			echo mysql_error();
			die;
		}
		$c = new ICC_Customer_Model_Customer();
		$c -> load($customer -> getEntityId());
		$c -> createEcodesMasterAccount($data['subscription_master_user_name'], $data['subscription_master_password'], $data['subscription_master_password']);


	}
コード例 #2
0
	function addPremiumData($data, $_customer) {
		//echo "--------------------\n\n\n\n";
		//print_r($data);
		//die;
		$c = new ICC_Customer_Model_Customer();
		$c -> load($_customer -> getId());
		$c -> createEcodesMasterAccount($data['subscription_master_user_name'], $data['subscription_master_password'], $data['subscription_master_password']);

	}
コード例 #3
0
    function createOrder($data, $_customer) {
        echo "creating order\n";

        try {

            $time = strtotime($data['order_datetime']);

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

            $order -> setCustomer_email($_customer -> getEmail()) -> setCustomerFirstname($_customer -> getFirstname()) -> setCustomerLastname($_customer -> getLastname()) -> setCustomerGroupId($_customer -> getGroupId()) -> setCustomer_is_guest(0) -> setCustomer($_customer);

            $customer_address = $_customer -> checkAddress($data);
            //  $regionModel = Mage::getModel('directory/region') -> loadByCode($data['bill_state'], $data['bill_country']);
            //  $regionId = $regionModel -> getId();

            try {

                $customAddress = Mage::getModel('sales/order_address');
                $customAddress -> setData($customer_address -> getData()) -> setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING) -> setCustomerId($_customer -> getId()) -> setIsDefaultBilling('1') -> setIsDefaultShipping('1') -> setSaveInAddressBook('1');

                $order -> setBillingAddress($this -> processBillingAddress($customer_address, $_customer));

                $customAddress = Mage::getModel('sales/order_address');
                $customAddress -> setData($customer_address -> getData()) -> setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING) -> setCustomerId($_customer -> getId()) -> setIsDefaultBilling('1') -> setIsDefaultShipping('1') -> setSaveInAddressBook('1');
                $order -> setShippingAddress($this -> processShippingAddress($customer_address, $_customer));
            } catch(Exception $e) {
                echo "-------------\n";
            }

            //you can set your payment method name here as per your need
            $orderPayment = Mage::getModel('sales/order_payment') -> setStoreId($storeId) -> setCustomerPaymentId(0) -> setMethod('checkmo');

            $order -> setPayment($orderPayment);

            $subTotal = 0;

            foreach ($data['products'] as $_product) {

                $product = Mage::getModel('catalog/product');

                print_r($_product);

                $this -> log("Added Product " . $_product['eCodes_ID']);
                $product -> load($product -> getIdBySku($_product['eCodes_ID']));

                if (!$product -> getSku()) {
                    echo "cannot find product " . $_product['eCodes_ID'] . "\n";
                    // die ;
                }
                $qty = $_product['product_qty'];

                if ($_product['product_qty'] == 0 || $_product['product_qty'] == 'n/a') {
                    $qty = 1;
                }

                $links = Mage::getModel('downloadable/product_type') -> getLinks($product);

                $price = $_product['line_item_total'] / $qty;

                $rowTotal = $_product['line_item_total'];

                $price = $_product['line_item_total'] / $qty;

                $orderItem = Mage::getModel('sales/order_item') -> setStoreId($storeId) -> setQuoteItemId(0) -> setQuoteParentItemId(NULL) -> setProductId($product -> getId()) -> setProductType($product -> getTypeId()) -> setQtyBackordered(NULL) -> setTotalQtyOrdered($qty) -> setQtyOrdered($qty) -> setName($product -> getName()) -> setSku($product -> getSku()) -> setPrice($price) -> setBasePrice($price) -> setOriginalPrice($price) -> setRowTotal($rowTotal) -> setBaseRowTotal($rowTotal) -> setProductOptions(array($options));
                echo "Adding item\n";
                $subTotal += $rowTotal;
                $order -> addItem($orderItem);
                echo "item added\n";

            }

            $order -> setSubtotal($subTotal) -> setBaseSubtotal($subTotal) -> setGrandTotal($subTotal) -> setBaseGrandTotal($subTotal);

            $transaction -> addObject($order);

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

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

            $order -> save();

            $order -> load();
            // echo $order -> getIncrementId();

            try {
                $invoice = Mage::getModel('sales/service_order', $order) -> prepareInvoice();
                $invoice -> setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
                $invoice -> register();

                $transaction = Mage::getModel('core/resource_transaction') -> addObject($invoice) -> addObject($invoice -> getOrder());

                $transaction -> save();
            } catch(Exception $e) {

                echo "\n error : " . $e -> getMessage();
                print_r($data);
                die ;
            }

            $order -> setOldOrderIdA($data['old_order_id_a']);
            $order -> setOldOrderIdA($data['old_order_id_a']);
            if ($data['old_order_id_b'] != "NULL")
                $order -> setOldOrderIdB($data['old_order_id_b']);

            $date = Mage::getModel('core/date') -> timestamp($time);
            $order -> setCreatedAt($date);

            $this -> log("Saving order");

            try {
                $order -> setStatus('complete');
                $order -> addStatusToHistory($order -> getStatus(), 'Historicical order completed', false);
                $order -> save();
            } catch(Exception $e) {
                echo "Error : " . $e -> getMessage();
                print_r($data);
                die ;
            }

            $this -> log("setting user pass to " . $data['subscription_master_user_name'] . " " . $data['subscription_master_password']);

            //$_customer -> createEcodesMasterAccount($data['subscription_master_user_name'], $data['subscription_master_password'], $data['subscription_master_password']);
            // $customer -> setData('ecodes_master_user ',$data['subscription_master_user_name']);
            // $customer -> setData('ecodes_master_pass',$data['subscription_master_password']);
            // $_customer -> save();
            $c = new ICC_Customer_Model_Customer();
            $c -> load($_customer -> getId());
            $c -> createEcodesMasterAccount($data['subscription_master_user_name'], $data['subscription_master_password'], $data['subscription_master_password']);

            $c -> save();
        } catch(Exception $e) {
            echo "Final Error " . $e -> getMessage() . "\n";
            print_r($data);
            die ;
        }

        echo "\ndone\n";
        return $this;

    }