コード例 #1
0
 /**
  * @param null $limit
  * @param null $offset
  * @return array
  */
 public function getItems($limit = null, $offset = null)
 {
     $reviews = array();
     if (ShopgateHelper::checkTable(sprintf('%sproduct_comment', _DB_PREFIX_))) {
         $reviews = Db::getInstance()->ExecuteS(sprintf('SELECT * FROM %sproduct_comment
                                                         WHERE validate = 1 AND deleted = 0%s%s', _DB_PREFIX_, is_int($limit) ? ' LIMIT ' . $limit : '', is_int($offset) ? ' OFFSET ' . $offset : ''));
     }
     return $reviews;
 }
コード例 #2
0
 /**
  * returns the video links
  *
  * @param $context
  * @return string
  */
 public static function getVideoLink($context)
 {
     switch ($context->language->iso_code) {
         case 'de':
             return ShopgateHelper::generateYoutubeLink(self::DEFAULT_YOUTUBE_ID_DE);
         case 'pl':
             return ShopgateHelper::generateYoutubeLink(self::DEFAULT_YOUTUBE_ID_PL);
         case 'fr':
             return ShopgateHelper::generateYoutubeLink(self::DEFAULT_YOUTUBE_ID_FR);
         default:
             return ShopgateHelper::generateYoutubeLink(self::DEFAULT_YOUTUBE_ID);
     }
 }
コード例 #3
0
 /**
  * @param $cart
  * @return array
  */
 protected function _addItems($cart)
 {
     $resultItems = array();
     foreach ($cart->getItems() as $item) {
         list($productId, $attributeId) = ShopgateHelper::getProductIdentifiers($item);
         /** @var ProductCore $product */
         $product = new Product($productId);
         $resultItem = new ShopgateCartItem();
         $resultItem->setItemNumber($item->getItemNumber());
         $resultItem->setStockQuantity($product->getQuantity($product->id, $attributeId));
         $resultItem->setUnitAmount($product->getPrice(false, $attributeId));
         $resultItem->setUnitAmountWithTax($product->getPrice(true, $attributeId));
         $resultItem->setOptions($item->getOptions());
         $resultItem->setAttributes($item->getAttributes());
         $resultItem->setInputs($item->getInputs());
         /**
          * validate product
          */
         if (!$this->_validateProduct($product, $attributeId)) {
             $this->_addItemException($resultItem, ShopgateLibraryException::CART_ITEM_PRODUCT_NOT_FOUND, sprintf('ProductId #%s AttributeId #%s', $productId, $attributeId));
             $resultItems[] = $resultItem;
             continue;
         }
         $addItemResult = $this->getPlugin()->getContext()->cart->updateQty($item->getQuantity(), $productId, $attributeId, false, 'up', $this->_deliveryAddress && $this->_deliveryAddress->id ? $this->_deliveryAddress->id : 0);
         $this->getPlugin()->getContext()->cart->save();
         if ($addItemResult != 1) {
             $resultItem->setIsBuyable(false);
             $resultItem->setQtyBuyable($product->getQuantity($productId, $attributeId));
             /**
              * add error
              */
             switch ($addItemResult) {
                 case -1:
                     $resultItem->setQtyBuyable($attributeId ? (int) Attribute::getAttributeMinimalQty($attributeId) : (int) $product->minimal_quantity);
                     $minimalQuantity = $attributeId ? (int) Attribute::getAttributeMinimalQty($attributeId) : (int) $product->minimal_quantity;
                     $this->_addItemException($resultItem, ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_UNDER_MINIMUM_QUANTITY, sprintf(Tools::displayError('You must add %d minimum quantity'), $minimalQuantity));
                     break;
                 default:
                     $this->_addItemException($resultItem, ShopgateLibraryException::CART_ITEM_REQUESTED_QUANTITY_NOT_AVAILABLE, Tools::displayError('There isn\'t enough product in stock.'));
                     break;
             }
         } else {
             $resultItem->setIsBuyable(true);
             $resultItem->setQtyBuyable((int) $item->getQuantity());
         }
         $resultItems[] = $resultItem;
     }
     return $resultItems;
 }
コード例 #4
0
 /**
  * @param $itemId
  * @return array
  */
 protected function getTierPricesFromDb($itemId)
 {
     /**
      * check table
      */
     if (ShopgateHelper::checkTable(sprintf('%sspecific_price', _DB_PREFIX_))) {
         $select = sprintf('SELECT * from %sspecific_price WHERE id_product = %s', _DB_PREFIX_, $itemId);
         return Db::getInstance()->ExecuteS($select);
     } else {
         return array();
     }
 }
コード例 #5
0
<?php

/**
 * Shopgate GmbH
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file AFL_license.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/AFL-3.0
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to interfaces@shopgate.com so we can send you a copy immediately.
 *
 * @author    Shopgate GmbH, Schloßstraße 10, 35510 Butzbach <*****@*****.**>
 * @copyright Shopgate GmbH
 * @license   http://opensource.org/licenses/AFL-3.0 Academic Free License ("AFL"), in the version 3.0
 */
/**
 * default relative path to config
 */
define('DEFAULT_RELATIVE_CONFIG_PATH', '/../../config/config.inc.php');
require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/classes/Helper.php';
require_once ShopgateHelper::normalizePath(array(dirname($_SERVER['SCRIPT_FILENAME']), DEFAULT_RELATIVE_CONFIG_PATH));
require_once dirname($_SERVER['SCRIPT_FILENAME']) . '/shopgate.php';
$controller = new FrontController();
$controller->init();
$plugin = new ShopgatePluginPrestashop();
$response = $plugin->handleRequest($_POST);
コード例 #6
0
 /**
  * @param ShopgateOrder $order
  *
  * @return array
  * @throws PrestaShopException
  * @throws ShopgateLibraryException
  */
 public function addOrder(ShopgateOrder $order)
 {
     /**
      * check exits shopgate order
      */
     if (ShopgateOrderPrestashop::loadByOrderNumber($order->getOrderNumber())->status == 1) {
         throw new ShopgateLibraryException(ShopgateLibraryException::PLUGIN_DUPLICATE_ORDER, sprintf('external_order_id: %s', $order->getOrderNumber()), true);
     }
     /** @var CarrierCore $sgCarrier */
     $sgCarrier = new Carrier(Configuration::get('SG_CARRIER_ID'));
     if (version_compare(_PS_VERSION_, '1.5.0', '<') && empty($sgCarrier->name)) {
         $sgCarrier->name = 'shopgate_tmp_carrier';
     }
     if ($order->getShippingType() != ShopgateShipping::DEFAULT_PLUGIN_API_KEY) {
         if ($order->getShippingInfos()->getAmount() > 0) {
             if (version_compare(_PS_VERSION_, '1.5.0', '<')) {
                 ShopgateModObjectModel::updateShippingPrice(pSQL($order->getShippingInfos()->getAmount()));
             } else {
                 $data = array('price' => pSQL($order->getShippingInfos()->getAmount()));
                 $where = 'a.id_carrier = ' . (int) Configuration::get('SG_CARRIER_ID');
                 ObjectModel::updateMultishopTable('Delivery', $data, $where);
             }
             $sgCarrier->is_free = 0;
         } else {
             $sgCarrier->is_free = 1;
         }
     }
     $sgCarrier->update();
     $customerModel = new ShopgateItemsCustomerImportJson($this->getPlugin());
     $paymentModel = new ShopgatePayment($this->getModule());
     $shippingModel = new ShopgateShipping($this->getModule());
     /**
      * read / check customer
      */
     if (!($customerId = Customer::customerExists($order->getMail(), true, false))) {
         /**
          * prepare customer
          */
         $shopgateCustomerItem = new ShopgateCustomer();
         $shopgateCustomerItem->setLastName($order->getInvoiceAddress()->getLastName());
         $shopgateCustomerItem->setFirstName($order->getInvoiceAddress()->getFirstName());
         $shopgateCustomerItem->setGender($order->getInvoiceAddress()->getGender());
         $shopgateCustomerItem->setBirthday($order->getInvoiceAddress()->getBirthday());
         $shopgateCustomerItem->setNewsletterSubscription(Configuration::get('SG_SUBSCRIBE_NEWSLETTER') ? true : false);
         $customerId = $customerModel->registerCustomer($order->getMail(), md5(_COOKIE_KEY_ . time()), $shopgateCustomerItem);
     }
     /** @var CustomerCore $customer */
     $customer = new Customer($customerId);
     /**
      * prepare cart
      */
     if (!$order->getDeliveryAddress()->getPhone()) {
         $order->getDeliveryAddress()->setPhone($order->getPhone());
     }
     if (!$order->getInvoiceAddress()->getPhone()) {
         $order->getInvoiceAddress()->setPhone($order->getPhone());
     }
     $this->getCart()->id_address_delivery = $customerModel->createAddress($order->getDeliveryAddress(), $customer);
     $this->getCart()->id_address_invoice = $customerModel->createAddress($order->getInvoiceAddress(), $customer);
     $this->getCart()->id_customer = $customerId;
     // id_guest is a connection to a ps_guest entry which includes screen width etc.
     // is_guest field only exists in Prestashop 1.4.1.0 and higher
     if (version_compare(_PS_VERSION_, '1.4.1.0', '>=')) {
         $this->getCart()->id_guest = $customer->is_guest;
     }
     $this->getCart()->secure_key = $customer->secure_key;
     $this->getCart()->id_carrier = $shippingModel->getCarrierIdByApiOrder($order);
     $shopgateCustomFieldsHelper = new ShopgateCustomFieldsHelper();
     $shopgateCustomFieldsHelper->saveCustomFields($this->getCart(), $order->getCustomFields());
     $this->getCart()->add();
     /**
      * add cart items
      */
     $canCreateOrder = true;
     $errorMessages = array();
     foreach ($order->getItems() as $item) {
         list($productId, $attributeId) = ShopgateHelper::getProductIdentifiers($item);
         if ($productId == 0) {
             continue;
         }
         $updateCart = $this->getCart()->updateQty($item->getQuantity(), $productId, $attributeId, false, 'up', $this->getCart()->id_address_delivery);
         if ($updateCart !== true) {
             $canCreateOrder = false;
             $errorMessages[] = array('product_id' => $productId, 'attribute_id' => $attributeId, 'quantity' => $item->getQuantity(), 'result' => $updateCart, 'reason' => $updateCart == -1 ? 'minimum quantity not reached' : '');
         }
     }
     /**
      * coupons
      */
     foreach ($order->getExternalCoupons() as $coupon) {
         /** @var CartRuleCore $cartRule */
         $cartRule = new CartRule(CartRule::getIdByCode($coupon->getCode()));
         if (Validate::isLoadedObject($cartRule)) {
             $this->getCart()->addCartRule($cartRule->id);
             $this->getCart()->save();
         }
     }
     if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) {
         /**
          * this field is not available in version 1.4.x.x
          * set delivery option
          */
         $delivery_option = array($this->getCart()->id_address_delivery => $shippingModel->getCarrierIdByApiOrder($order) . ',');
         $this->getCart()->setDeliveryOption($delivery_option);
     }
     /**
      * store shopgate order
      */
     $shopgateOrderItem = new ShopgateOrderPrestashop();
     $shopgateOrderItem->fillFromOrder($this->getCart(), $order, $this->getPlugin()->getShopgateConfig()->getShopNumber());
     if (version_compare(_PS_VERSION_, '1.6.0.0', '<')) {
         $shopgateOrderItem->add();
     }
     /**
      * create order
      */
     if ($canCreateOrder) {
         /**
          * get first item from order stats
          */
         $this->getCart()->save();
         $idOrderState = reset($paymentModel->getOrderStateId($order));
         $validateOder = $this->getModule()->validateOrder($this->getCart()->id, $idOrderState, $this->getCart()->getOrderTotal(true, defined('Cart::BOTH') ? Cart::BOTH : 3), $paymentModel->getPaymentTitleByKey($order->getPaymentMethod()), null, array(), null, false, $this->getCart()->secure_key);
         if (version_compare(_PS_VERSION_, '1.5.0.0', '<') && (int) $this->getModule()->currentOrder > 0 && $order->getShippingType() != ShopgateShipping::DEFAULT_PLUGIN_API_KEY && $order->getShippingInfos()->getAmount() > 0) {
             ShopgateLogger::log('PS < 1.5.0.0: update shipping and payment cost', ShopgateLogger::LOGTYPE_DEBUG);
             // in versions below 1.5.0.0 the shipping and payment costs must be updated after the order was imported
             /** @var OrderCore $updateShopgateOrder */
             $updateShopgateOrder = new Order($this->getModule()->currentOrder);
             $updateShopgateOrder->total_shipping = $order->getAmountShipping() + $order->getAmountShopPayment();
             $updateShopgateOrder->total_paid += $order->getAmountShipping() + $order->getAmountShopPayment();
             $updateShopgateOrder->total_paid_real += $order->getAmountShipping() + $order->getAmountShopPayment();
             $updateShopgateOrder->update();
         }
         /**
          * update shopgate order
          */
         if ($validateOder) {
             $shopgateOrderItem->id_order = $this->getModule()->currentOrder;
             $shopgateOrderItem->status = 1;
             $shopgateOrderItem->save();
             return array('external_order_id' => $shopgateOrderItem->id_order, 'external_order_number' => $shopgateOrderItem->id_order);
         }
     }
     $shopgateOrderItem->delete();
     throw new ShopgateLibraryException(ShopgateLibraryException::UNKNOWN_ERROR_CODE, 'Unable to create order:' . print_r($errorMessages, true), true);
 }
コード例 #7
0
 /**
  * @return mixed|string
  */
 public function hookDisplayMobileHeader()
 {
     return ShopgateHelper::calculateRedirect();
 }