Ejemplo n.º 1
0
    /**
     * @param OnlineShop_Framework_Pricing_IRule $rule
     * @param string                             $field
     *
     * @return mixed
     */
    private function getData(OnlineShop_Framework_Pricing_IRule $rule, $field)
    {
        if (!array_key_exists($rule->getId(), self::$cache)) {
            $query = <<<'SQL'
SELECT 1

    , priceRule.ruleId
	, count(priceRule.o_id) as "soldCount"
	, sum(orderItem.totalPrice) as "salesAmount"

	-- DEBUG INFOS
	, orderItem.oo_id as "orderItem"
	, `order`.orderdate

FROM object_query_%2$d as `order`

    -- ordered products
    JOIN object_relations_%2$d as orderItems
        ON( 1
            AND orderItems.fieldname = "items"
            AND orderItems.src_id = `order`.oo_id
        )

	-- order item
	JOIN object_%1$d as orderItem
		ON ( 1
    	    AND orderItem.o_id = orderItems.dest_id
		)

	-- add active price rules
	JOIN object_collection_PricingRule_%1$d as priceRule
		ON( 1
			AND priceRule.o_id = orderItem.oo_id
			AND priceRule.fieldname = "PricingRules"
			AND priceRule.ruleId = %3$d
		)

WHERE 1
    AND `order`.orderState = "committed"

LIMIT 1
SQL;
            try {
                $query = sprintf($query, \Pimcore\Model\Object\OnlineShopOrderItem::classId(), \Pimcore\Model\Object\OnlineShopOrder::classId(), $rule->getId());
                $conn = \Pimcore\Resource::getConnection();
                self::$cache[$rule->getId()] = $conn->fetchRow($query);
            } catch (Exception $e) {
                Logger::error($e);
            }
        }
        return self::$cache[$rule->getId()][$field];
    }
Ejemplo n.º 2
0
    protected function getCurrentAmount(OnlineShop_Framework_Pricing_IRule $rule)
    {
        if (!array_key_exists($rule->getId(), $this->currentSalesAmount)) {
            $query = <<<'SQL'
SELECT 1

	, count(priceRule.o_id) as "count"
	, sum(orderItem.totalPrice) as "amount"

	-- DEBUG INFOS
	, orderItem.oo_id as "orderItem"
	, `order`.orderdate

FROM object_query_%2$d as `order`

    -- ordered products
    JOIN object_relations_%2$d as orderItems
        ON( 1
            AND orderItems.fieldname = "items"
            AND orderItems.src_id = `order`.oo_id
        )

	-- order item
	JOIN object_%1$d as orderItem
		ON ( 1
			AND orderItem.origin__id is null
    	    AND orderItem.o_id = orderItems.dest_id
		)

	-- add active price rules
	JOIN object_collection_PriceRule_%1$d as priceRule
		ON( 1
			AND priceRule.o_id = orderItem.oo_id
			AND priceRule.fieldname = "priceRules"
			AND priceRule.ruleId = %3$d
		)

WHERE 1
    AND `order`.orderState = "committed"
    AND `order`.origin__id is null

LIMIT 1
SQL;
            $query = sprintf($query, \Pimcore\Model\Object\OnlineShopOrderItem::classId(), \Pimcore\Model\Object\OnlineShopOrder::classId(), $rule->getId());
            $conn = \Pimcore\Resource::getConnection();
            $this->currentSalesAmount[$rule->getId()] = (int) $conn->fetchRow($query)['amount'];
        }
        return $this->currentSalesAmount[$rule->getId()];
    }
Ejemplo n.º 3
0
 /**
  * modify price
  *
  * @param OnlineShop_Framework_IPrice $currentSubTotal
  * @param OnlineShop_Framework_ICart  $cart
  *
  * @return OnlineShop_Framework_IPrice
  */
 public function modify(OnlineShop_Framework_IPrice $currentSubTotal, OnlineShop_Framework_ICart $cart)
 {
     if ($this->getAmount() != 0) {
         return new OnlineShop_Framework_Impl_ModificatedPrice($this->getAmount(), $currentSubTotal->getCurrency(), false, $this->rule->getLabel());
     }
 }