place order

@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since  2012-04-11

@param  bool $subscribe

@todo   Peform some sanity checks
@todo   Refactor the decrement part
325371
public function place($subscribe = false)
    {
        if (self::STATUS_CART != $this->getStatusCode())
        {
            throw new \Exception('Only orders of type cart may be placed');
        }

        $this->setStatusCode(self::STATUS_NEW);

        foreach ($this->getLineItems() as $lineItem)
        {
            $quantity = $lineItem->getQuantity();

            // Decrement stock from Product
            $product = $lineItem->getProduct();
            $product->setQuantityOnHold($product->getQuantityOnHold()+$quantity);
            $product->setQuantityAvailable($product->getQuantityAvailable()-$quantity);

            // Create stock transaction for each line item
            $stockTransaction = new OrderStockTransaction();
            $stockTransaction->setQuantity(-1*$quantity);
            $stockTransaction->setProduct($product);
            $stockTransaction->setStatusCode(OrderStockTransaction::STATUS_PENDING);

            $lineItem->setStockTransaction($stockTransaction);

            // Subscribe, if necessary
            if ($subscribe)
            {
                $lineItem->subscribe();
            }
        }
    }
268877
public function addFolder($name, $subscribe = false) {
        $success = imap_createmailbox($this->imap, $this->mailbox . $name);

        if ($success && $subscribe) {
            $success = imap_subscribe($this->imap, $this->mailbox . $name);
        }

        return $success;
    }
400858
public function onUpdate(SubscriberEvent $event)
    {
        $this->listRepository->update(
            $event->getListId(),
            $event->getSubscriber()
        );
    }
573535
public function setSubscriber($subscriber)
    {
        $this->_subscriber = $subscriber;

        if ($subscriber->persisted()) {
            $this->actorId = $this->_subscriber->id;
        } else {
            $this->set('actorId', PHP_INT_MAX);
        }

        $this->getRepository()->getSpace()->setSaveOrder($this, $this->_subscriber);

        return $this;
    }
289804
public function thenByDesc($order)
    {
        $order = LambdaUtils::toSelectCallable($order);
        $this->orders[] = array("property" => $order, "direction" => self::ORDER_DESC);
        return $this;
    }
325833
public function register($subscribers)
    {
        is_array($subscribers) || $subscribers = [$subscribers];

        foreach ($subscribers as $subscriber) {
            $this->registerSubscriber($subscriber);
        }
    }
1264163
public function setSortOrder($order = true)
    {
        $this->order = (bool) $order;

        // jeśli podano jako string
        $order = trim(strtolower($order));
        ($order === 'asc') and ($this->order = true);
        ($order === 'desc') and ($this->order = false);

        return $this;
    }
508643
protected function pushOrder()
    {
        if( $this->order ) {
            $this->parts[] = 'ORDER BY';
            $this->parts[] = $this->quoteIdentifierIfNotExpression($this->order);
            $this->parts[] = $this->direction == self::DESC ? self::DESC : self::ASC;
        }
    }
1284570
public function orderBy($order, $append = true, $first = false)
    {
        $this->setToken('OrderBy', $order, $append, $first);

        return $this;
    }
791422
public function onReorder($fx = null)
    {
        if (is_callable($fx)) {
            if ($this->triggered()) {
                $sortOrders = explode(',', @$_POST['order']);
                $source = @$_POST['source'];
                $newIdx = @$_POST['new_idx'];
                $orgIdx = @$_POST['org_idx'];
                $this->set(function () use ($fx, $sortOrders, $source, $newIdx, $orgIdx) {
                    return call_user_func_array($fx, [$sortOrders, $source, $newIdx, $orgIdx]);
                });
            }
        }
    }
88891
public function subscribed($subscription = 'default', $planId = null)
    {
        $subscription = $this->subscription($subscription);

        if (is_null($subscription)) {
            return false;
        }

        if (is_null($planId)) {
            return $subscription->isActive();
        }

        if ($planId == $subscription->plan_id and $subscription->isActive()) {
            return true;
        }

        return false;
    }
750634
public function addOrderBy($sort, $order = null)
    {
        return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), true);
    }
861833
private function doBeforeCompile(): void
	{
		$builder = $this->getContainerBuilder();
		$dispatcher = $builder->getDefinition($this->prefix('dispatcher'));

		$subscribers = $builder->findByType(EventSubscriberInterface::class);
		foreach ($subscribers as $name => $subscriber) {
			$dispatcher->addSetup('addSubscriber', [$subscriber]);
		}
	}
408290
public function set_sort($field,$order=false){
		if (!$field && !$order)
			$this->sort_by=array();
		else{
			if ($order===false)
				$this->sort_by[] = $field;
			else {
				$order=strtolower($order)=="asc"?"ASC":"DESC";
				$this->sort_by[]=array("name"=>$field,"direction" => $order);
			}
		}
	}
1146705
public function removeSubscription(\HarvestCloud\CoreBundle\Entity\ProductSubscription $subscription)
    {
        $this->subscriptions->removeElement($subscription);
    }
60729
public function onPending(SubscriberEvent $event)
    {
        $this->listRepository->pending(
            $event->getListId(),
            $event->getSubscriber()
        );
    }
67436
public function update($subscriptions)
    {
        $this->initCollection();

        /** @var SubscriptionInterface $subscription */
        foreach ($subscriptions as $subscription) {
            $this->changeSubscription(
                $subscription,
                (bool)$subscription->getSubscriberStatus() === true ?
                    Subscriber::STATUS_SUBSCRIBED :
                    Subscriber::STATUS_UNSUBSCRIBED
            );
        }

        return $this->statusResponseFactory->create()
            ->setStatus('ok');
    }