コード例 #1
0
 function execute()
 {
     global $osC_Session, $osC_ShoppingCart, $osC_Product, $osC_Language, $messageStack, $toC_Customization_Fields;
     if (!isset($osC_Product)) {
         $id = false;
         foreach ($_GET as $key => $value) {
             if ((ereg('^[0-9]+(_?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && $key != $osC_Session->getName()) {
                 $id = $key;
             }
             break;
         }
         if (strpos($id, '_') !== false) {
             $id = str_replace('_', '#', $id);
         }
         if ($id !== false && osC_Product::checkEntry($id)) {
             $osC_Product = new osC_Product($id);
         }
     }
     if (isset($osC_Product)) {
         //customization fields check
         if ($osC_Product->hasRequiredCustomizationFields()) {
             if (!$toC_Customization_Fields->exists($osC_Product->getID())) {
                 $osC_Language->load('products');
                 $messageStack->add_session('products', $osC_Language->get('error_customization_fields_missing'), 'error');
                 osc_redirect(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getID()));
             }
         }
         $variants = null;
         if (isset($_POST['variants']) && is_array($_POST['variants'])) {
             $variants = $_POST['variants'];
         } else {
             if (isset($_GET['variants']) && !empty($_GET['variants'])) {
                 $variants = osc_parse_variants_string($_GET['variants']);
             }
         }
         $gift_certificate_data = null;
         if ($osC_Product->isGiftCertificate() && isset($_POST['senders_name']) && isset($_POST['recipients_name']) && isset($_POST['message'])) {
             if ($osC_Product->isEmailGiftCertificate()) {
                 $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'senders_email' => $_POST['senders_email'], 'recipients_name' => $_POST['recipients_name'], 'recipients_email' => $_POST['recipients_email'], 'message' => $_POST['message']);
             } else {
                 $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'recipients_name' => $_POST['recipients_name'], 'message' => $_POST['message']);
             }
             if ($osC_Product->isOpenAmountGiftCertificate()) {
                 $gift_certificate_data['price'] = $_POST['gift_certificate_amount'];
             }
             $gift_certificate_data['type'] = $osC_Product->getGiftCertificateType();
         }
         $quantity = null;
         if (isset($_POST['quantity']) && is_numeric($_POST['quantity'])) {
             $quantity = $_POST['quantity'];
         }
         if ($osC_Product->isGiftCertificate() && $gift_certificate_data == null) {
             osc_redirect(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getID()));
             return false;
         } else {
             $osC_ShoppingCart->add($osC_Product->getID(), $variants, $quantity, $gift_certificate_data);
         }
     }
     osc_redirect(osc_href_link(FILENAME_CHECKOUT));
 }
コード例 #2
0
ファイル: cart_add.php プロジェクト: Doluci/tomatocart
 function execute()
 {
     global $osC_Session, $osC_ShoppingCart, $osC_Product;
     if (!isset($osC_Product)) {
         $id = false;
         foreach ($_GET as $key => $value) {
             if ((ereg('^[0-9]+(#?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && $key != $osC_Session->getName()) {
                 $id = $key;
             }
             break;
         }
         if ($id !== false && osC_Product::checkEntry($id)) {
             $osC_Product = new osC_Product($id);
         }
     }
     if (isset($osC_Product)) {
         $variants = null;
         if (isset($_POST['variants']) && is_array($_POST['variants'])) {
             $variants = $_POST['variants'];
         } else {
             if (isset($_GET['variants']) && !empty($_GET['variants'])) {
                 $variants = osc_parse_variants_string($_GET['variants']);
             }
         }
         $gift_certificate_data = null;
         if ($osC_Product->isGiftCertificate() && isset($_POST['senders_name']) && isset($_POST['recipients_name']) && isset($_POST['message'])) {
             if ($osC_Product->isEmailGiftCertificate()) {
                 $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'senders_email' => $_POST['senders_email'], 'recipients_name' => $_POST['recipients_name'], 'recipients_email' => $_POST['recipients_email'], 'message' => $_POST['message']);
             } else {
                 $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'recipients_name' => $_POST['recipients_name'], 'message' => $_POST['message']);
             }
             if ($osC_Product->isOpenAmountGiftCertificate()) {
                 $gift_certificate_data['price'] = $_POST['gift_certificate_amount'];
             }
             $gift_certificate_data['type'] = $osC_Product->getGiftCertificateType();
         }
         $quantity = null;
         if (isset($_POST['quantity']) && is_numeric($_POST['quantity'])) {
             $quantity = $_POST['quantity'];
         }
         if ($osC_Product->hasVariants() && empty($variants) || $osC_Product->isGiftCertificate() && $gift_certificate_data == null) {
             osc_redirect(osc_href_link(FILENAME_PRODUCTS, $osC_Product->getID()));
             return false;
         } else {
             $osC_ShoppingCart->add($osC_Product->getID(), $variants, $quantity, $gift_certificate_data);
         }
     }
     osc_redirect(osc_href_link(FILENAME_CHECKOUT));
 }
コード例 #3
0
 function execute()
 {
     global $osC_Session, $toC_Wishlist, $osC_Product;
     $id = false;
     foreach ($_GET as $key => $value) {
         if ((ereg('^[0-9]+(_?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$', $key) || ereg('^[a-zA-Z0-9 -_]*$', $key)) && $key != $osC_Session->getName()) {
             $id = $key;
         }
         break;
     }
     //change the variants in the product info page, then attach the wid param to represent the variant product
     if (isset($_GET['wid']) && preg_match('/^[0-9]+(_?([0-9]+:?[0-9]+)+(;?([0-9]+:?[0-9]+)+)*)*$/', $_GET['wid'])) {
         $id = $_GET['wid'];
     }
     if (strpos($id, '_') !== false) {
         $id = str_replace('_', '#', $id);
     }
     if ($id !== false && osC_Product::checkEntry($id)) {
         $osC_Product = new osC_Product($id);
     }
     if (isset($osC_Product)) {
         $variants = null;
         if (isset($_POST['variants']) && is_array($_POST['variants'])) {
             $variants = $_POST['variants'];
         } else {
             if (isset($_GET['variants']) && !empty($_GET['variants'])) {
                 $variants = osc_parse_variants_string($_GET['variants']);
             } else {
                 if (strpos($id, '#') !== false) {
                     $variants = osc_parse_variants_from_id_string($id);
                 }
             }
         }
         if (!osc_empty($variants)) {
             $toC_Wishlist->add($osC_Product->getID(), $variants);
         } else {
             $toC_Wishlist->add($osC_Product->getID());
         }
     }
     osc_redirect(osc_href_link(FILENAME_ACCOUNT, 'wishlist'));
 }
コード例 #4
0
 function addProduct()
 {
     global $osC_ShoppingCart, $toC_Json, $osC_Language, $toC_Customization_Fields;
     $osC_Language->load('products');
     if (is_numeric($_REQUEST['pID']) && osC_Product::checkEntry($_REQUEST['pID'])) {
         $osC_ShoppingCart->resetShippingMethod();
         $osC_Product = new osC_Product($_REQUEST['pID']);
         //gift certificate check
         if ($osC_Product->isGiftCertificate() && !isset($_POST['senders_name'])) {
             $response = array('success' => false, 'feedback' => $osC_Language->get('error_gift_certificate_data_missing'));
         } else {
             if ($osC_Product->hasRequiredCustomizationFields() && !$toC_Customization_Fields->exists($osC_Product->getID())) {
                 $response = array('success' => false, 'feedback' => $osC_Language->get('error_customization_fields_missing'));
             } else {
                 $variants = null;
                 if (isset($_REQUEST['variants']) && !empty($_REQUEST['variants'])) {
                     $variants = osc_parse_variants_string($_REQUEST['variants']);
                 }
                 $gift_certificate_data = null;
                 if ($osC_Product->isGiftCertificate() && isset($_POST['senders_name']) && isset($_POST['recipients_name']) && isset($_POST['message'])) {
                     if ($osC_Product->isEmailGiftCertificate()) {
                         $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'senders_email' => $_POST['senders_email'], 'recipients_name' => $_POST['recipients_name'], 'recipients_email' => $_POST['recipients_email'], 'message' => $_POST['message']);
                     } else {
                         $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'recipients_name' => $_POST['recipients_name'], 'message' => $_POST['message']);
                     }
                     if ($osC_Product->isOpenAmountGiftCertificate()) {
                         $gift_certificate_data['price'] = $_POST['gift_certificate_amount'];
                     }
                     $gift_certificate_data['type'] = $osC_Product->getGiftCertificateType();
                 }
                 $osC_ShoppingCart->add($_REQUEST['pID'], $variants, $_REQUEST['pQty'], $gift_certificate_data);
                 $content = self::_getShoppingCart();
                 $response = array('success' => true, 'content' => $content);
             }
         }
     } else {
         $response = array('success' => false);
     }
     echo $toC_Json->encode($response);
 }
コード例 #5
0
ファイル: popup_cart.php プロジェクト: ellipsonic/tomato_app
 function addProduct()
 {
     global $osC_ShoppingCart, $toC_Json, $osC_Language, $toC_Customization_Fields, $osC_Image, $osC_Currencies;
     $osC_Language->load('products');
     if (is_numeric($_POST['pID']) && osC_Product::checkEntry($_POST['pID'])) {
         $osC_ShoppingCart->resetShippingMethod();
         $osC_Product = new osC_Product($_POST['pID']);
         //gift certificate check
         if ($osC_Product->isGiftCertificate() && !isset($_POST['senders_name'])) {
             $response = array('success' => false, 'feedback' => $osC_Language->get('error_gift_certificate_data_missing'));
         } else {
             if ($osC_Product->hasRequiredCustomizationFields() && !$toC_Customization_Fields->exists($osC_Product->getID())) {
                 $response = array('success' => false, 'feedback' => $osC_Language->get('error_customization_fields_missing'));
             } else {
                 $variants = null;
                 if (isset($_POST['variants']) && !empty($_POST['variants'])) {
                     $variants = osc_parse_variants_string($_POST['variants']);
                 }
                 $gift_certificate_data = null;
                 if ($osC_Product->isGiftCertificate() && isset($_POST['senders_name']) && isset($_POST['recipients_name']) && isset($_POST['message'])) {
                     if ($osC_Product->isEmailGiftCertificate()) {
                         $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'senders_email' => $_POST['senders_email'], 'recipients_name' => $_POST['recipients_name'], 'recipients_email' => $_POST['recipients_email'], 'message' => $_POST['message']);
                     } else {
                         $gift_certificate_data = array('senders_name' => $_POST['senders_name'], 'recipients_name' => $_POST['recipients_name'], 'message' => $_POST['message']);
                     }
                     if ($osC_Product->isOpenAmountGiftCertificate()) {
                         $gift_certificate_data['price'] = $_POST['gift_certificate_amount'];
                     }
                     $gift_certificate_data['type'] = $osC_Product->getGiftCertificateType();
                 }
                 $osC_ShoppingCart->add($_POST['pID'], $variants, $_POST['pQty'], $gift_certificate_data);
                 $items = 0;
                 foreach ($osC_ShoppingCart->getProducts() as $products_id => $data) {
                     $items += $data['quantity'];
                 }
                 //build the content of the confirmation dialog
                 $product_id_string = osc_get_product_id_string($_POST['pID'], $variants);
                 //find the added product
                 $added_product = null;
                 foreach ($osC_ShoppingCart->getProducts() as $id_string => $product) {
                     if ($product_id_string == $id_string) {
                         $added_product = $product;
                         break;
                     }
                 }
                 //build the dialog
                 $confirm_dialog = null;
                 if ($added_product !== null) {
                     $confirm_dialog .= '<div class="dlgConfirm">' . '<div class="itemImage">' . $osC_Image->show($added_product['image'], $added_product['name'], '', 'thumbnail') . '</div>' . '<div class="itemDetail"><p>' . sprintf($osC_Language->get('add_to_cart_confirmation'), $added_product['quantity'] . ' x ' . osc_link_object(osc_href_link(FILENAME_CHECKOUT, null, 'SSL'), $added_product['name']));
                     //gift certificates
                     if ($added_product['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                         $confirm_dialog .= '<br />- ' . $osC_Language->get('senders_name') . ': ' . $product['gc_data']['senders_name'];
                         if ($added_product['gc_data']['type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                             $confirm_dialog .= '<br />- ' . $osC_Language->get('senders_email') . ': ' . $product['gc_data']['senders_email'];
                         }
                         $confirm_dialog .= '<br />- ' . $osC_Language->get('recipients_name') . ': ' . $product['gc_data']['recipients_name'];
                         if ($added_product['gc_data']['type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                             $confirm_dialog .= '<br />- ' . $osC_Language->get('recipients_email') . ': ' . $product['gc_data']['recipients_email'];
                         }
                         $confirm_dialog .= '<br />- ' . $osC_Language->get('message') . ': ' . $product['gc_data']['message'];
                     }
                     $confirm_dialog .= '</p>';
                     //variants products
                     if ($osC_ShoppingCart->hasVariants($product['id'])) {
                         foreach ($osC_ShoppingCart->getVariants($product['id']) as $variants) {
                             $confirm_dialog .= '<div>';
                             $confirm_dialog .= '<strong>' . $variants['groups_name'] . ' - </strong><strong>' . $variants['values_name'] . '</strong></tr>';
                             $confirm_dialog .= '</div>';
                         }
                     }
                     $confirm_dialog .= '</div>';
                     //cart total
                     $confirm_dialog .= '<p><strong>' . $osC_ShoppingCart->numberOfItems() . ' ' . $osC_Language->get('text_items') . '</strong> - <strong>' . $osC_Currencies->format($osC_ShoppingCart->getTotal()) . '</strong></p>';
                     //bottom buttons
                     $confirm_dialog .= '<div class="btns">' . osc_link_object(osc_href_link(FILENAME_CHECKOUT, 'checkout', 'SSL'), osc_draw_image_button('button_checkout.gif', $osC_Language->get('button_checkout'))) . osc_link_object(osc_href_link(FILENAME_CHECKOUT, 'cart', 'SSL'), osc_draw_image_button('button_ajax_cart.png')) . osc_link_object(osc_href_link(FILENAME_DEFAULT), osc_draw_image_button('button_continue.gif'), 'id="btnContinue"') . '</div>';
                     $confirm_dialog .= '</div>';
                 }
                 $response = array('success' => true, 'items' => $items, 'confirm_dialog' => $confirm_dialog);
             }
         }
     } else {
         $response = array('success' => false);
     }
     echo $toC_Json->encode($response);
 }
コード例 #6
0
ファイル: general.php プロジェクト: sajad1441/TomatoShop-v1
/**
 * Parse a variants string into variant array
 *
 * @param string $id the product variants string
 * @access public
 * @author zheng.lei
 */
function osc_parse_variants_from_id_string($products_id_string)
{
    $variants = array();
    if (!is_numeric($products_id_string)) {
        $tmp = explode('#', $products_id_string);
        if (isset($tmp[1])) {
            $variants = osc_parse_variants_string($tmp[1]);
        }
    }
    return $variants;
}