带有自定义选项的 Mijoshop "Add To Cart"

Mijoshop "Add To Cart" with custom options

我目前正在使用 Joomla 和 Mijoshop,但它们不能满足我的需求,因为我还必须将它们与 jCalPro 集成。这个想法是用户可以在 jCalPro 上创建活动,会员可以注册。

问题是弄清楚如何将 jCalPro 集成到 MijoShop 中,以便会员可以为活动付款并在购买时在订单表中正确跟踪。我们在 Mijoshop 中有针对事件类型的产品以及价格和详细信息。这些产品与我们的 jCalPro 事件大致相关。我需要能够将一个项目放入将添加产品(事件)的 Mijoshop 购物车中,而且还填充一个包含 jCalPro 事件 ID 的选项,以便我可以跟踪它。一旦我有了这个,我就可以编写自定义页面来提取报告数据等。我正在使用我编写的自定义 PHP 并将它们添加到 Joomla 应用程序中。

我知道 MijoShop 有一个 "addToShoppingCart" 函数,正如我在文件中看到的那样:

components/com_mijoshop/assets/js/product.js

问题是我不知道如何将 MijoShop class 加载到页面中以便我可以使用该功能。当我将页面包含在 Joomla 应用程序中时,它会默认加载吗?我正在使用以下代码,它适用于大多数 Joomla 功能:

// Joomla session enable
define( '_JEXEC', 1 );
// define( 'JPATH_BASE', realpath(dirname(__FILE__)));
define( 'JPATH_BASE', '/my/path/' );
require_once ( JPATH_BASE.'/includes/defines.php' );
require_once ( JPATH_BASE.'/includes/framework.php' );
$mainframe  = JFactory::getApplication('site');
$mainframe->initialise();
$user       = JFactory::getUser();
$config     =& JFactory::getConfig();
$session    =& JFactory::getSession();

如您所见,我还有更多障碍需要克服,因为我首先需要访问此功能,然后在使用它时需要它来填充自定义产品选项。

任何帮助将不胜感激,因为我发现关于 MijoShop 的文档很少,关于如何将它与 jCalPro 之类的东西集成的文档更少。

目前我已经找到了大致等同于以下内容的解决方案:

try {
    // Now we add the product to the user's shopping cart
    // First we'll get the product ID of the event in question
    // My JCalPro has a custom field called "Event type" that I have manually populated with the select
    // Mijoshop product ID's and thier associated "Model" into. The easiest way I could see to make them line up.
    // the event ID used here was provided to my script prior to this query
    $queryText = "SELECT * FROM jcalpro_events WHERE id = '".$eventID."'";
    $db->setQuery($queryText);
    $eventInfo = $db->loadAssoc();
    $eventData = json_decode($eventInfo['params']);
    $product_id = $eventData->Event;
    // Get the product info, including the currently defined option
    // for my purposes the product only has one option in mijoshop_product_option called "eventid"
    // which is a blank text field that is not required.
    $queryText = "
        SELECT p.*, po.product_option_id 
        FROM mijoshop_product p
        LEFT JOIN mijoshop_product_option po ON po.product_id = p.product_id
        WHERE p.product_id = '".$product_id."'";
    $db->setQuery($queryText);
    $productInfo = $db->loadAssoc();
    // $userInfo is a previous query where i grabbed the user's details
    // including Joomla User ID, Mijoshop User ID, email, etc
    $mUID = $userInfo['mUID']; // get mijoshop user ID for use
    $jUID = $userInfo['jUID']; // get Joomla user ID for use
    // First we have to log out the user in question so thier shopping cart will remain once we update it.
    // If we don't do this, the shopping cart will be overwritten any time they reload thier page.
    if ($mainframe->logout($jUID)) {
        // Replace the user's shopping cart to have the event's product in MijoShop
        $quantity = 1;                                                     // Default value for this project
        $option = array($productInfo['product_option_id'] => $eventID);    // Define array with option ID and value
        $serOption = serialize($option);                                   // Serialize the options
        $product_key = (int)$product_id . ':' . base64_encode($serOption); // Generate the Product info for the Cart
        $products = array($product_key => $quantity);                      // Put the products into an array, product type => quantity
        $serProducts = serialize($products);                               // Serialize that array for the cart
        // Now we can insert the product into the shopping cart
        $queryText = "UPDATE mijoshop_customer SET cart = '".$serProducts."' WHERE customer_id = '".$mUID."'";
        $db->setQuery($queryText);
        $db->execute();
        if ($debug) {echo "Step 8 - Placed the product in the ueser's Mijoshop cart.<br>\n";}
    } else {
        echo '<script type="text/javascript">alert("Unable to update the shopping cart for '.$name.'. You may need admin assitance.<br>\n");</script>';
    }
}
catch (Exception $e){
    echo $e->getMessage();
}