@param $orderNumber
@param $sku
@param $name
@param $price
@param int $quantity
@internal param null $trackerName

@return Item
971654
public function createAnalyticsItem($orderNumber, $sku, $name, $price, $quantity = 1)
    {
        $item = new Item();
        $item->setOrderNumber($orderNumber);
        $item->setName($name);
        $item->setPrice($price);
        $item->setQuantity($quantity);
        $item->setSku($sku);

        $this->getAnalytics()->addItem($item);

        return $item;
    }
1087696
public function quantityAction(Profile $seller, $product_slug, Request $request)
    {
        $q  = $this->get('doctrine')
            ->getManager()
            ->createQuery('
                SELECT p
                FROM HarvestCloudCoreBundle:Product p
                WHERE p.seller = :seller
                AND p.slug = :product_slug
            ')
            ->setParameter('product_slug', $product_slug)
            ->setParameter('seller', $seller)
        ;

        $product = $q->getSingleResult();

        $form = $this->createForm(new AddToCartType(
            $product,
            $this->getCurrentCart()->getQuantity($product)
        ));

        if ($request->getMethod() == 'POST')
        {
            $form->bind($request);

            if ($form->isValid())
            {
                // Find OrderCollection
                $orderCollection = $this->getCurrentCart();

                // Update Product quantity in OrderCollection
                $lineItem = $orderCollection->updateProductQuantity($product, $form->get('quantity')->getData());

                // Persisting cascades to Order and OrderCollection
                $em = $this->getDoctrine()->getEntityManager();
                $em->persist($lineItem);
                $em->flush();

                if ($request->isXmlHttpRequest())
                {
                    return new JsonResponse(array(
                        'cart' => array(
                            'subtotal' => '$'.number_format($this->getCurrentCart()->getSubTotal(), 2),
                            'quantity' => $lineItem->getQuantity().' '.$lineItem->getProduct()->getUnitForNumber($lineItem->getQuantity()),
                            'line_item_id' => $lineItem->getId(),
                        ),
                    ));
                }

                return $this->redirect($this->generateUrl('Profile_product_show', array(
                    'slug'         => $seller->getSlug(),
                    'product_slug' => $product->getSlug(),
                )));
            }
        }

        exit('Here');

        return $this->render('HarvestCloudCoreBundle:Buyer/Product:show.html.twig', array(
          'product'          => $product,
          'quantity_in_cart' => $this->getCurrentCart()->getQuantity($product),
          'form'             => $form->createView(),
        ));
    }
605052
public function getUnique($sku, $store_id)
    {
        $existing = $this->get(array('sku' => $sku, 'store_id' => $store_id));

        if (empty($existing)) {
            return $sku;
        }

        $counter = 1;

        do {
            $modified = $sku . '-' . $counter;
            $counter++;
        } while ($this->get(array('sku' => $modified, 'store_id' => $store_id)));

        return $modified;
    }
889327
public function transact($amount, $orderId, $invoiceNumber = null)
    {
        $this->transaction = [
            'amount' => $amount,
            'orderId' => $orderId,
            'invoiceNumber' => $invoiceNumber ?: $orderId,
        ];

        return $this->initiateTransaction();
    }
903026
public function getLinkedskus($sku, $type = LINKED_SKU_TYPE_ALL) {
    // Without this we get following error:
    // 9006: Signature does not match expected signature.
    $sku = urlencode($sku);
    $endpoint = $this->apiVersion . "/agent/product/$sku/related/$type";

    $doReq = function ($client, $opt) use ($endpoint) {
      return ($client->get($endpoint, $opt));
    };

    $result = [];

    try {
      $result = $this->tryAgentRequest($doReq, 'linkedSkus', 'related');
    }
    catch (ConnectorException $e) {
      throw new RouteException(__FUNCTION__, $e->getMessage(), $e->getCode(), $this->getRouteEvents());
    }

    return $result;
  }
828718
protected function getItemBagForOrder(Order $order)
    {
        $itemBag = $this->createItemBagForOrder($order);

        $event = new ItemBagEvent([
            'items' => $itemBag,
            'order' => $order
        ]);
        $this->trigger(self::EVENT_AFTER_CREATE_ITEM_BAG, $event);

        return $event->items;
    }
749231
private function createOrder(
        CustomerInterface $customer,
        $number = null,
        ChannelInterface $channel = null,
        $localeCode = null
    ) {
        $order = $this->createCart($customer, $channel, $localeCode);

        if (null !== $number) {
            $order->setNumber($number);
        }

        $order->completeCheckout();

        return $order;
    }
1299780
public function updateCartQuantity($method, $cid, $quantity) {
    if ($method == 'ajax') {
      // Create AJAX Response object.
      $response = new AjaxResponse();

      $data = array(
        'cid' => $cid,
        'quantity' => $quantity,
      );
      $return = $this->databaseSendOrder->updateCartQuantity($data);

      $cost_total = $this->databaseSendOrder->getOrderCost();
      $response->addCommand(new HtmlCommand('.cart__cost-total-value', $cost_total));

      // Return ajax response.
      return $response;
    }
  }
296203
public function findOne($where = null, $orderby = null)
  {
    $m = $this->getManager();
    $q = $m->getQueryBuilder()
      ->select($this->getTable())
      ->where($where)
      ->orderby($orderby)
      ->limit(1);

    return $this->fetchObject($m->query($q));
  }
1058183
protected function createItem(Order $order, array $item)
    {
        if ($this->itemContainsABuyable($item)) {
            /** @var Buyable $product */
            $product = $item['product'];
            $item    = array_merge($item, [
                'product_type' => $product->morphTypeName(),
                'product_id'   => $product->getId(),
                'price'        => $product->getPrice(),
                'name'         => $product->getName()
            ]);
            unset($item['product']);
        }

        $order->items()->create($item);
    }
830277
public function index($name, $field, $order = null) {
        $this->index[$name] = [$field, $order];
        return $this;
    }
72497
public function getMerchantOrderParamValue($orderIndex = 0, $paramIndex = 0)
    {
        $orderParam = $this->getMerchantOrderParams($orderIndex);
        return array_key_exists('value', $orderParam[$paramIndex]) ? $orderParam[$paramIndex]['value'] : null;
    }
834027
public function add(&$obj, $quantity = 1)
    {
        $db = Loader::db();
        $existingPCID = $this->getPileContentID($obj);
        $v1 = array($this->pID);
        $q1 = "select max(displayOrder) as displayOrder from PileContents where pID = ?";
        $currentDO = $db->getOne($q1, $v1);
        $displayOrder = $currentDO + 1;
        if (!$existingPCID) {
            $v = array($this->pID, $obj->getBlockID(), "BLOCK", $quantity, $displayOrder);
            $q = "insert into PileContents (pID, itemID, itemType, quantity, displayOrder) values (?, ?, ?, ?, ?)";
            $r = $db->query($q, $v);
            if ($r) {
                $pcID = $db->Insert_ID();

                return $pcID;
            }
        } else {
            return $existingPCID;
        }
    }
83773
public function setOrderDelivery($order_id, $need_delivery = 0, $delivery_company = null, $delivery_track_no = null, $is_others = 0){
		if (!$this->access_token && !$this->checkAuth()) return false;
		if (!$order_id) return false;

		$data = array();
		$data['order_id'] = $order_id;
		if ($need_delivery) {
			$data['delivery_company'] = $delivery_company;
			$data['delivery_track_no'] = $delivery_track_no;
			$data['is_others'] = $is_others;
		}
		else {
			$data['need_delivery'] = $need_delivery;
		}

		$result = $this->http_post(self::API_BASE_URL_PREFIX.self::MERCHANT_ORDER_SETDELIVERY.'access_token='.$this->access_token, self::json_encode($data));
		if ($result)
		{
			$json = json_decode($result,true);
			if (isset($json['errcode']) && $json['errcode']) {
				$this->errCode = $json['errcode'];
				$this->errMsg = $json['errmsg'];
				return false;
			}
			return true;
		}
		return false;
	}
508464
protected function sumTotalWeight(&$total, array &$item, array $order)
    {
        $product = &$item['product'];

        if ($product['weight_unit'] !== $order['weight_unit']) {

            try {
                $product['weight'] = $this->convertor->convert($product['weight'], $product['weight_unit'], $order['weight_unit']);
            } catch (Exception $ex) {
                return null;
            }

            $product['weight_unit'] = $order['weight_unit'];
        }

        $total += (float) ($product['weight'] * $item['quantity']);
        return null;
    }
88937
public function getStockCount(string $productNumber) : int
    {
        Assert::that($productNumber)->minLength(1, 'The length of $productNumber has to be > 0');
        $product = $this->getDataProduct($productNumber);

        return (int)$product['stockCount'];
    }
262596
public function addLine($itemID, $name = null, $qty = 1, $price = '0.00', $options = [], $taxable = true)
    {
        return $this->add($itemID, $name, $qty, $price, $options, $taxable, true);
    }