예제 #1
0
 public function getProductsData($page, $productsIds = array())
 {
     $productsData = array();
     if (in_array($page, array("category", "product"))) {
         if (empty($productsIds)) {
             return array();
         }
         $criteria = $this->modx->newQuery('ShopContent');
         $criteria->where(array('id:IN' => $productsIds));
         $items = $this->modx->getIterator('ShopContent', $criteria);
         foreach ($items as $item) {
             $productsData[] = array("article" => $item->id, "name" => $item->pagetitle, "imageUrl" => "http://" . $_SERVER['SERVER_NAME'] . (defined('MODX_ASSETS_URL') ? MODX_ASSETS_URL : '/assets') . '/' . $item->image, "quantity" => 1, "amount" => $item->price);
         }
         return $productsData;
     }
     if (in_array($page, array("cart"))) {
         //Определяем параметры сниппета Shopkeeper
         $sys_property_sets = $this->modx->getOption('shk3.property_sets', $this->modx->config, 'default');
         $sys_property_sets = explode(',', $sys_property_sets);
         $propertySetName = trim(current($sys_property_sets));
         $snippet = $this->modx->getObject('modSnippet', array('name' => 'Shopkeeper3'));
         $properties = $snippet->getProperties();
         if ($propertySetName != 'default' && $this->modx->getCount('modPropertySet', array('name' => $propertySetName)) > 0) {
             $propSet = $this->modx->getObject('modPropertySet', array('name' => $propertySetName));
             $propSetProperties = $propSet->getProperties();
             if (is_array($propSetProperties)) {
                 $properties = array_merge($properties, $propSetProperties);
             }
         }
         $lang = $this->modx->getOption('lang', $properties, 'ru');
         $this->modx->getService('lexicon', 'modLexicon');
         $this->modx->lexicon->load($lang . ':shopkeeper3:default');
         if (!empty($_SESSION['shk_order'])) {
             require_once SHOPKEEPER_PATH . "model/shopkeeper.class.php";
             $shopCart = new Shopkeeper($this->modx, $properties);
             $purchasesData = $shopCart->getProductsData(true);
             $_tmp_purchasesData = array();
             foreach ($shopCart->data as $p_data) {
                 $_tmp_purchasesData[$p_data['id']] = array("price" => $p_data['price'], "quantity" => $p_data['count']);
             }
             foreach ($purchasesData as $cartItem) {
                 $productsData[] = array("article" => $cartItem['id'], "name" => $cartItem['pagetitle'], "imageUrl" => "http://" . $_SERVER['SERVER_NAME'] . (defined('MODX_ASSETS_URL') ? MODX_ASSETS_URL : '/assets') . '/' . $cartItem['image'], "quantity" => isset($_tmp_purchasesData[$cartItem['id']]) ? $_tmp_purchasesData[$cartItem['id']]["quantity"] : 1, "amount" => (isset($_tmp_purchasesData[$cartItem['id']]) ? $_tmp_purchasesData[$cartItem['id']]["quantity"] : 1) * $cartItem['price']);
             }
         }
         return $productsData;
     }
 }
예제 #2
0
 public function updateShopkeeper3Order($order_id)
 {
     if (empty($order_id)) {
         return false;
     }
     if (!empty($_SESSION['shk_order'])) {
         require_once SHOPKEEPER_PATH . "model/shopkeeper.class.php";
         $shopCart = new Shopkeeper($this->getModX(), $properties);
         $this->getModX()->addPackage('shopkeeper3', SHOPKEEPER_PATH . 'model/');
         //Доставка
         $delivery = $this->getPayqr()->getDeliveryCasesSelected();
         $delivery_price = isset($delivery->amountFrom) ? $delivery->amountFrom : 0;
         $delivery_name = isset($delivery->name) ? $delivery->name : "";
         //Сохраняем данные заказа
         $insert_data = array('contacts' => $this->getBuyerContacts(), 'options' => '', 'price' => $this->getTotal(), 'currency' => $shopCart->config['currency'], 'date' => strftime('%Y-%m-%d %H:%M:%S'), 'sentdate' => strftime('%Y-%m-%d %H:%M:%S'), 'note' => '', 'email' => $emailField, 'delivery' => $delivery_name, 'delivery_price' => $delivery_price, 'payment' => 'PayQR', 'tracking_num' => '', 'status' => '1');
         if ($userId) {
             $insert_data['userid'] = $userId;
         }
         //производим обновление товара
         $result = $this->modxUpdate($insert_data, $this->getModX()->getOption('table_prefix') . "shopkeeper3_orders", "id='" . $order_id . "'");
         if ($result) {
             $purchasesData = $shopCart->getProductsData(true);
             //удаляем все старые товары из заказа
             $this->getModX()->query("DELETE FROM " . $this->getModX()->getOption('table_prefix') . "shopkeeper3_purchases WHERE order_id = " . $order_id);
             //
             foreach ($shopCart->data as $key => $p_data) {
                 $options = !empty($p_data['options']) ? json_encode($p_data['options']) : '';
                 $fields_data = !empty($purchasesData[$key]) ? $purchasesData[$key] : array();
                 $fields_data['url'] = !empty($p_data['url']) ? $p_data['url'] : '';
                 unset($fields_data['id']);
                 $fields_data_str = json_encode($fields_data);
                 $insert_data = array('p_id' => $p_data['id'], 'order_id' => $order_id, 'name' => $p_data['name'], 'price' => $p_data['price'], 'count' => $p_data['count'], 'class_name' => 'ShopContent', 'package_name' => 'shop', 'data' => $fields_data_str, 'options' => $options);
                 $purchase = $this->getModX()->newObject('shk_purchases');
                 $purchase->fromArray($insert_data);
                 $purchase->save();
             }
         }
         return true;
     } else {
         return null;
     }
 }
예제 #3
0
 $delivery_price = !empty($shopCart->delivery['price']) ? $shopCart->delivery['price'] : 0;
 $delivery_name = !empty($shopCart->delivery['label']) ? $shopCart->delivery['label'] : '';
 if (!$delivery_name) {
     $delivery_name = !empty($allFormFields[$deliveryField]) ? $allFormFields[$deliveryField] : '';
 }
 //Сохраняем данные заказа
 $order = $modx->newObject('shk_order');
 $insert_data = array('contacts' => $contacts, 'options' => '', 'price' => Shopkeeper::$price_total, 'currency' => $shopCart->config['currency'], 'date' => strftime('%Y-%m-%d %H:%M:%S'), 'sentdate' => strftime('%Y-%m-%d %H:%M:%S'), 'note' => '', 'email' => isset($allFormFields[$emailField]) ? $allFormFields[$emailField] : '', 'delivery' => $delivery_name, 'delivery_price' => $delivery_price, 'payment' => isset($allFormFields[$paymentField]) ? $allFormFields[$paymentField] : '', 'tracking_num' => '', 'phone' => isset($allFormFields[$phoneField]) ? $allFormFields[$phoneField] : '', 'status' => $modx->getOption('shk3.first_status', null, '1'));
 if ($userId) {
     $insert_data['userid'] = $userId;
 }
 $order->fromArray($insert_data);
 $saved = $order->save();
 //Сохраняем товары заказа
 if ($saved) {
     $purchasesData = $shopCart->getProductsData(true);
     foreach ($shopCart->data as $key => $p_data) {
         $options = !empty($p_data['options']) ? json_encode($p_data['options']) : '';
         $fields_data = !empty($purchasesData[$key]) ? $purchasesData[$key] : array();
         $fields_data['url'] = !empty($p_data['url']) ? $p_data['url'] : '';
         unset($fields_data['id']);
         $fields_data_str = json_encode($fields_data);
         $insert_data = array('p_id' => $p_data['id'], 'order_id' => $order->id, 'name' => $p_data['name'], 'price' => $p_data['price'], 'count' => $p_data['count'], 'class_name' => $p_data['className'], 'package_name' => $p_data['packageName'], 'data' => $fields_data_str, 'options' => $options);
         $purchase = $modx->newObject('shk_purchases');
         $purchase->fromArray($insert_data);
         $purchase->save();
     }
     $shopCart->setOrderDataSession($order->toArray());
 }
 $modx->invokeEvent('OnSHKChangeStatus', array('order_ids' => array($order->id), 'status' => $order->status));
 $orderOutputData = $shopCart->getOrderData($order->id);