Mijoshop"加入购物车"自定义选项

时间:2015-02-26 18:14:36

标签: php joomla

我目前正在与Joomla和Mijoshop合作,但他们不满足我的需求,因为我也必须将这些与jCalPro集成。这个想法是用户可以在jCalPro上创建事件,成员可以注册它们。

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

我知道MijoShop有一个“addToShoppingCart”功能,我可以在文件中看到它:

components/com_mijoshop/assets/js/product.js

问题是我不知道如何将MijoShop类加载到页面中以便我可以使用该函数。当我在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等集成在一起。

1 个答案:

答案 0 :(得分:1)

目前我找到的解决方案大致相当于以下几个方面:

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();
}