Ejemplo n.º 1
0
/**
 * sets up the sales container
 */
function sendContainer($sales, $deletePDF)
{
    // loops through all selected sales
    foreach ($sales as $sale) {
        // skips "non existent" sales (dev issue: was: deprecated)
        if (null === ($customer = Mage::getModel("customer/customer")->load($sale->getCustomerId()))) {
            continue;
        }
        // skips "premium" orders
        $cgid = $customer->getGroupId();
        $code = Mage::getSingleton("customer/group")->load($cgid)->getCustomerGroupCode();
        if ("General" != $code) {
            print $code . PHP_EOL;
            print $cgid . PHP_EOL;
            continue;
        }
        // Gerdt Vladimir @ Karli (and fills)
        //
        $shipaddr = $sale->getShippingAddress();
        //
        $firstName = $shipaddr->getFirstname();
        $lastName = $shipaddr->getLastname();
        $email = $shipaddr->getEmail();
        $telephone = $shipaddr->getTelephone();
        $street = implode(" ", $shipaddr->getStreet());
        $country = $shipaddr->getCountry();
        $city = $shipaddr->getCity();
        $postcode = $shipaddr->getPostcode();
        ///////
        $kvg_arr_order = array();
        $kvg_lfdnr = getTransactionId($customer, $sale);
        // Eindeutige Auftragsnummer
        /////// Kopfdaten
        $kvg_arr_order[$kvg_lfdnr]['key'] = $kvg_lfdnr;
        // Eindeutige Auftragsnummer
        $kvg_arr_order[$kvg_lfdnr]['order_number'] = $sale->getIncrementId();
        // Bestellnummer, optional
        $kvg_arr_order[$kvg_lfdnr]['customer_note'] = $sale->getCustomerNote();
        // Kommentar zum Auftrag max. 200 Zeichen, optional
        $d = DateTime::createFromFormat("Y-m-d H:i:s", $sale->getCreatedAt());
        $createdAt = $d->format("Y-m-d H:i");
        $createdAtDate = $d->format("Y-m-d");
        $createdAtTime = $d->format("H:i");
        $kvg_arr_order[$kvg_lfdnr]['order_date'] = $createdAtDate;
        // Auftragsdatum
        $kvg_arr_order[$kvg_lfdnr]['order_time'] = $createdAtTime;
        // Auftragszeit
        /////// Kundendaten
        $kvg_arr_order[$kvg_lfdnr]['customer_first_name'] = $firstName;
        // Vorname
        $kvg_arr_order[$kvg_lfdnr]['customer_last_name'] = $lastName;
        // Nachname
        $kvg_arr_order[$kvg_lfdnr]['customer_county'] = $country;
        // Land
        $kvg_arr_order[$kvg_lfdnr]['customer_city'] = $city;
        // Stadt
        $kvg_arr_order[$kvg_lfdnr]['customer_postal_code'] = $postcode;
        // Postleitzahl
        $kvg_arr_order[$kvg_lfdnr]['customer_street'] = $street;
        // Strasse
        $kvg_arr_order[$kvg_lfdnr]['customer_phone'] = $telephone;
        // Telefon
        $kvg_arr_order[$kvg_lfdnr]['customer_mobile'] = $mobile;
        // Mobile Telefon
        $kvg_arr_order[$kvg_lfdnr]['customer_fax'] = $fax;
        // Fax
        $kvg_arr_order[$kvg_lfdnr]['customer_email'] = $email;
        // Email
        /////// Produkte
        foreach ($sale->getAllItems() as $item) {
            $articleID = $item->getSku();
            $kvg_arr_order[$kvg_lfdnr]['position'][$articleID]['article_number'] = $articleID;
            // Artikelnummer
            $kvg_arr_order[$kvg_lfdnr]['position'][$articleID]['amount'] = $item->getQtyOrdered();
            // Menge
            $kvg_arr_order[$kvg_lfdnr]['position'][$articleID]['price'] = $item->getPrice();
            // Preis
            $i++;
        }
        // -->
        //////
        // writes the invoice PDF document
        exec(ExportInvoiceCommand . $sale->getIncrementId());
        // writes the retoure PDF document
        exec(ExportRetoureCommand . $sale->getIncrementId());
        //
        $invoicePDF = PDFPath . $kvg_lfdnr . "_invoice.pdf";
        $retourePDF = PDFPath . $kvg_lfdnr . "_retoure.pdf";
        // checks invoice PDF; skips the sale without an invoice
        if (!file_exists($invoicePDF)) {
            // logs the fail
            logger("No Invoice. Will not send the order: " . $kvg_lfdnr);
            // fills up CRON notification email (administrative issue)
            EmailNotification::add("<span style='color:red'>Bestellung {$kvg_lfdnr} konnte wegen der fehlenden Quittung nicht zu Karlie gesandt werden.</span>");
            // skips the sale
            continue;
        }
        // sends the order to karlie
        if ("true" === sendOrder($kvg_arr_order, $invoicePDF, $retourePDF)) {
            // writes DB record (order is referred to karlie)
            $sale->setKarlieOrderId($kvg_lfdnr);
            $sale->setState("processing", true, "Die Bestellung ist zu Karlie weitergeleitet. " . $sale->getKarlieOrderId());
            $sale->setStatus("referred_to_karlie");
            $sale->save();
            // logs the CRON success
            logger("Order sent to Karlie");
            // fills up CRON notification email (administrative issue)
            EmailNotification::add("<span class='green'>Bestellung {$kvg_lfdnr} ist zu Karlie gesandt worden.</span>");
            // sends customer notification email
            foreach ($sale->getInvoiceCollection() as $invoice) {
                try {
                    $invoice->sendEmail();
                } catch (Exception $e) {
                    logger("Could not sent Customer Notification Email: " . $e);
                }
            }
        } else {
            // logs send fail
            logger("Could not send the order");
            // fills up CRON notification email (administrative issue)
            EmailNotification::add("<span class='red'>Bestellung {$kvg_lfdnr} konnte nicht zu Karlie gesandt werden.</span>");
        }
    }
}
Ejemplo n.º 2
0
foreach ($sales as $sale) {
    // loads the sale
    $sale = $sale->load($sale->getId());
    // loads order id of current sale
    $orderID = $sale->getIncrementId();
    // loads customer id of the current sale
    $customerID = $sale->getCustomerId();
    // customer of current sale might be a guest
    if (null === $customerID) {
        $customerID = "guest";
    }
    // loads parcel id of the sale (from karlie)
    $message = exec(GetParcelIDCommand . $customerID . "_" . $orderID);
    // fills up CRON notification email
    $color = "green";
    switch ($message) {
        case "":
        case "null":
        case "parcelID: null":
        case null:
            $color = "red";
            break;
    }
    EmailNotification::add("<span style='color:{$color}'>Bestellung: " . $customerID . "_" . $orderID . " {$message}</span>");
}
// sends CRON notification email
EmailNotification::add("<span style='color:black'>Der CRON Job Check Parcel ID endet.</span>");
EmailNotification::send();
// logs done message
logger("Done: mygassi-check-parcels");
exit(1);
Ejemplo n.º 3
0
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    $res = file_get_contents(RetMridPath . $sale->getIncrementId());
    unlink(RetMridPath . $sale->getIncrementId());
    switch ($res) {
        case null:
        case "":
        case "null":
        case "[]":
            continue;
    }
    $arry = json_decode($res);
    $obj = $arry[0];
    $sale = Mage::getModel("sales/order")->loadByIncrementId($obj->bestellnr);
    $sale = $sale->load($sale->getId());
    $flag = $sale->getStatus();
    if (null !== $sale->getID()) {
        print "sale: " . $sale->getId() . " : " . $flag . "\n";
        print "status:" . $sale->getStatus() . "\n";
        print "state:" . $sale->getState() . "\n";
        $sale->setStatus("retoure")->save();
        $sale->setState("processing", true, "Die Bestellung wird zurückgesendet." . $sale->getKarlieOrderId());
        logger("Die Bestellung:" . $sale->getKarlieOrderId() . " wird zurückgesendet");
        EmailNotification::add("<span style='color:green'>Die Bestellung " . $sale->getKarlieOrderId() . " wird zurückgesendet</span>");
    }
}
EmailNotification::add("<span style='color:black'>Der Retoure CRON Prozess endet.</span>");
EmailNotification::send();
logger("Done mygassi-retoure.php");
exit(1);