Process the Products

@param Basket $basket
@return array
432194
public function products(Basket $basket)
    {
        $products = [];

        foreach ($basket->products() as $product) {
            $products[] = [
                'sku'            => $product->sku,
                'name'           => $product->name,
                'price'          => $product->price,
                'rate'           => $product->rate,
                'quantity'       => $product->quantity,
                'freebie'        => $product->freebie,
                'taxable'        => $product->taxable,
                'delivery'       => $product->delivery,
                'coupons'        => $product->coupons,
                'tags'           => $product->tags,
                'discount'       => $product->discount,
                'attributes'     => $product->attributes,
                'category'       => $product->category,
                'total_value'    => $this->reconciler->value($product),
                'total_discount' => $this->reconciler->discount($product),
                'total_delivery' => $this->reconciler->delivery($product),
                'total_tax'      => $this->reconciler->tax($product),
                'subtotal'       => $this->reconciler->subtotal($product),
                'total'          => $this->reconciler->total($product)
            ];
        }

        return $products;
    }
1098178
private function addProductThree(Basket $basket)
    {
        $three = $this->products->three();

        $basket->add($three->sku, $three->name, $three->price, function ($product) use ($three) {
            $product->freebie($three->freebie);
        });

        return $basket;
    }
594084
public function getFirstBasketProduct()
    {
        if ($this->_oFirstBasketProduct === null) {
            $this->_oFirstBasketProduct = false;

            $aBasketArticles = $this->getBasketArticles();
            if (is_array($aBasketArticles) && $oProduct = reset($aBasketArticles)) {
                $this->_oFirstBasketProduct = $oProduct;
            }
        }

        return $this->_oFirstBasketProduct;
    }
1256953
public function meta(Basket $basket)
    {
        $meta = [];

        foreach ($this->metadata as $item) {
            $meta[$item->name()] = $item->generate($basket);
        }

        return $meta;
    }
1357673
public function getBasketItems()
    {
        if ($this->_aBasketItemList === null) {
            $this->_aBasketItemList = false;

            // passing basket articles
            if ($oBasket = $this->getSession()->getBasket()) {
                $this->_aBasketItemList = $oBasket->getBasketArticles();
            }
        }

        return $this->_aBasketItemList;
    }
445785
public function collect($object)
    {
        $result = array();
        $products = $object->getLoadedProductCollection();
        foreach ($products as $product) {
            $result[] = $product;
        }
        return $result;
    }
1095285
public function process()
	{
		$view = $this->getView();

		try
		{
			// only start if there's something to do
			if( ( $option = $view->param( 'cs-order', null ) ) === null
				|| $view->get( 'standardStepActive' ) !== null
			) {
				return;
			}

			$context = $this->_getContext();
			$orderBaseManager = MShop_Factory::createManager( $context, 'order/base' );

			$basket = $orderBaseManager->getSession();
			$basket->setCustomerId( $context->getUserId() );
			$basket->finish();

			$cntl = Controller_Frontend_Factory::createController( $context, 'order' );
			$orderItem = $cntl->store( $basket );
			$cntl->block( $orderItem );

			$context->getSession()->set( 'arcavias/orderid', $orderItem->getId() );

			$view->orderItem = $orderItem;
			$view->orderBasket = $basket;

			parent::process();

			// save again after sub-clients modified it's state
			MShop_Factory::createManager( $context, 'order' )->saveItem( $orderItem );
		}
		catch( Exception $e )
		{
			$view->standardStepActive = 'order';
			throw $e;
		}
	}
726060
protected function process()
    {

        // query whether or not, we've found a new SKU => means we've found a new product
        if ($this->hasBeenProcessed($sku = $this->getValue(ColumnKeys::SKU))) {
            return;
        }

        // initialize the arrays for the new category product relations
        $categoryProducts = array();

        // load the category product relations found in the CSV file
        foreach ($this->getValue(ColumnKeys::CATEGORIES, array(), array($this, 'explode')) as $path) {
            // load the category for the found path
            $this->path = trim($path);

            // prepare the product category relation attributes
            if ($attr = $this->prepareAttributes()) {
                // initialize and persist the category product relation relation and add the
                // category ID to the list => necessary to create the URL rewrites later!
                $this->persistCategoryProduct($categoryProduct = $this->initializeCategoryProduct($attr));
                $this->addProductCategoryId($categoryId = $categoryProduct[MemberNames::CATEGORY_ID]);

                // tempoary persist the category ID
                $categoryProducts[] = $categoryId;
            }
        }

        // query whether or not we've to clean up existing category product relations
        if ($this->getSubject()->getConfiguration()->hasParam(ConfigurationKeys::CLEAN_UP_CATEGORY_PRODUCT_RELATIONS) &&
            $this->getSubject()->getConfiguration()->getParam(ConfigurationKeys::CLEAN_UP_CATEGORY_PRODUCT_RELATIONS)
        ) {
            // load the existing category product relations for the product with the given SKU
            $existingCategoryProducts = $this->getProductBunchProcessor()->getCategoryProductsBySku($sku);

            // initialize the counter for the deleted category product relations
            $counter = 0;

            // clean up the existing category product relations
            foreach ($existingCategoryProducts as $categoryId => $categoryProduct) {
                // query whether or not the category product relation exists in the CSV file
                if (!in_array($categoryId, $categoryProducts)) {
                    // if not, delete it from the database
                    $this->getProductBunchProcessor()
                         ->deleteCategoryProduct(array(MemberNames::ENTITY_ID => $categoryProduct[MemberNames::ENTITY_ID]));

                    // raise the counter for the deleted category product relations
                    $counter++;
                }
            }

            // log a message (if any category product relations have been cleaned-up)
            if ($counter > 0) {
                $this->getSubject()
                     ->getSystemLogger()
                     ->warning(
                         $this->getSubject()->appendExceptionSuffix(
                             sprintf(
                                 'Cleaned-up %d category product relation(s) for product with SKU "%s"',
                                 $counter,
                                 $sku
                             )
                         )
                     );
            }
        }
    }
627190
public function transformIntoOrder(BasketInterface $basket)
    {
        $event = new BasketTransformEvent($basket);
        $this->eventDispatcher->dispatch(TransformerEvents::PRE_BASKET_TO_ORDER_TRANSFORM, $event);

        // Customer
        $customer = $basket->getCustomer();

        if (!$customer instanceof CustomerInterface) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency('[Sonata\Component\Payment\Transform\Basket::transform] the customer is not valid');
            }

            throw new \RuntimeException('Invalid customer');
        }

        // Billing
        $billingAddress = $basket->getBillingAddress();

        if (!$billingAddress instanceof AddressInterface) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency('[Sonata\Component\Payment\Transform\Basket::transform] the billing address is not valid');
            }

            throw new \RuntimeException('Invalid billing address');
        }

        $paymentMethod = $basket->getPaymentMethod();
        if (!$paymentMethod instanceof PaymentInterface) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency('[Sonata\Component\Payment\PaymentInterface::transform] the payment method is not valid');
            }

            throw new \RuntimeException('Invalid payment method');
        }

        // Shipping
        $deliveryMethod = $basket->getDeliveryMethod();
        if (!$deliveryMethod instanceof ServiceDeliveryInterface) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency('[Sonata\Component\Delivery\ServiceDeliveryInterface::transform] the delivery method is not valid');
            }

            throw new \RuntimeException('Invalid delivery method');
        }

        $deliveryAddress = $basket->getDeliveryAddress();
        if ($deliveryMethod->isAddressRequired() && !$deliveryAddress instanceof AddressInterface) {
            if ($this->getLogger()) {
                $this->getLogger()->emergency('[Sonata\Component\Delivery\ServiceDeliveryInterface::transform] the shipping address is not valid');
            }

            throw new \RuntimeException('Invalid delivery address');
        }

        // add a custom class_instance for testing purpose.
        $order = $this->orderManager->create();

        $order->setCustomer($customer);
        $order->setUsername($customer->getFullname());
        $order->setLocale($customer->getLocale());

        if ($deliveryMethod->isAddressRequired()) {
            $order->setShippingAddress1($deliveryAddress->getAddress1());
            $order->setShippingAddress2($deliveryAddress->getAddress2());
            $order->setShippingAddress3($deliveryAddress->getAddress3());
            $order->setShippingPostcode($deliveryAddress->getPostcode());
            $order->setShippingCity($deliveryAddress->getCity());
            $order->setShippingCountryCode($deliveryAddress->getCountryCode());
            $order->setShippingName($deliveryAddress->getFirstname().' '.$deliveryAddress->getLastname());
            $order->setShippingPhone($deliveryAddress->getPhone());
        }

        $order->setBillingAddress1($billingAddress->getAddress1());
        $order->setBillingAddress2($billingAddress->getAddress2());
        $order->setBillingAddress3($billingAddress->getAddress3());
        $order->setBillingPostcode($billingAddress->getPostcode());
        $order->setBillingCity($billingAddress->getCity());
        $order->setBillingCountryCode($billingAddress->getCountryCode());
        $order->setBillingName($billingAddress->getFirstname().' '.$billingAddress->getLastname());
        $order->setBillingPhone($billingAddress->getPhone());

        $order->setTotalExcl($basket->getTotal());
        $order->setTotalInc($basket->getTotal(true));

        $order->setDeliveryVat($basket->getDeliveryVat());
        $order->setDeliveryCost($basket->getDeliveryPrice(true));
        $order->setDeliveryMethod($basket->getDeliveryMethod()->getCode());
        $order->setDeliveryStatus(ServiceDeliveryInterface::STATUS_OPEN);

        $order->setCreatedAt(new \DateTime());

        $order->setCurrency($basket->getCurrency());

        $order->setStatus(OrderInterface::STATUS_OPEN);

        $order->setPaymentStatus(TransactionInterface::STATUS_OPEN);
        $order->setPaymentMethod($basket->getPaymentMethod()->getCode());

        foreach ($basket->getBasketElements() as $basketElement) {
            $orderElement = $basketElement->getProductProvider()->createOrderElement($basketElement);

            if (!$orderElement instanceof OrderElementInterface) {
                continue;
            }

            $order->addOrderElement($orderElement);
        }

        $event = new OrderTransformEvent($order);
        $this->eventDispatcher->dispatch(TransformerEvents::POST_BASKET_TO_ORDER_TRANSFORM, $event);

        return $order;
    }
925720
public static function hasBasketGotSimilarItem(self $basket, ProductVariation $variation)
    {
        /** @var BasketItem[] $basketItem */
        $basketItem = $basket->BasketItems->filter(new Equals('ProductVariationID', $variation->UniqueIdentifier));
        if (count($basketItem)) {
            return $basketItem[0];
        }
        return false;
    }
443627
public function setBasket(Basket $basket = null)
    {
        if ($this->basket) {
            $this->basket->setOrder(null);
        }

        $this->basket = $basket;

        if ($basket) {
            $basket->setOrder($this);
        }

        return $this;
    }
185647
public function renderFinalReviewBasketElementAction(BasketElementInterface $basketElement, BasketInterface $basket)
    {
        $action = sprintf('%s:renderFinalReviewBasketElement', $basketElement->getProductProvider()->getBaseControllerName());

        $response = $this->forward($action, [
            'basketElement' => $basketElement,
            'basket' => $basket,
        ]);

        if ($this->get('kernel')->isDebug()) {
            $response->setContent(sprintf("\n<!-- [Sonata] Product code: %s, id: %s, action: %s -->\n%s\n<!-- [Sonata] end product -->\n",
                $basketElement->getProductCode(),
                $basketElement->getProductId(),
                $action,
                $response->getContent()
            ));
        }

        return $response;
    }
1208849
protected function process()
    {

        // query whether or not, we've found a new SKU => means we've found a new product
        if ($this->hasBeenProcessed($this->getValue(ColumnKeys::SKU))) {
            return;
        }

        // query whether or not, product => website relations has been specified
        if (!$this->hasValue(ColumnKeys::PRODUCT_WEBSITES)) {
            return;
        }

        // append the product => website relations found
        $codes = $this->getValue(ColumnKeys::PRODUCT_WEBSITES, array(), array($this, 'explode'));
        foreach ($codes as $code) {
            // set the code of the website that has to be processed
            $this->setCode($code);
            // prepare the product website relation attributes
            $attr = $this->prepareAttributes();

            try {
                // create the product website relation
                $productWebsite = $this->initializeProductWebsite($attr);
                $this->persistProductWebsite($productWebsite);
            } catch (\RuntimeException $re) {
                $this->getSystemLogger()->debug($re->getMessage());
            }
        }
    }
107650
function setBasket(Basket $basket)
    {
        foreach ($basket->toArray() as $param => $value) {
            $this->addParam($param, $value);
        }

        return $this;
    }
838896
public function get()
	{
		if( !isset( $this->baskets[$this->type] ) )
		{
			$this->baskets[$this->type] = $this->manager->getSession( $this->type );
			$this->checkLocale( $this->baskets[$this->type]->getLocale(), $this->type );
		}

		return $this->baskets[$this->type];
	}
269108
public function validateDelivery($basket)
    {
        if ($basket->getPaymentId() == 'oxidpaypal') {
            $shippingId = $basket->getShippingId();
            $basketPrice = $basket->getPrice()->getBruttoPrice();
            $user = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
            if (!$user->loadUserPayPalUser()) {
                $user = $this->getUser();
            }

            $validState = null;
            if (!$this->isPayPalPaymentValid($user, $basketPrice, $shippingId)) {
                $validState = self::ORDER_STATE_INVALIDDELIVERY;
            }
        } else {
            $validState = parent::validateDelivery($basket);
        }

        return $validState;
    }
462126
private function addProductOne(Basket $basket)
    {
        $one = $this->products->one();

        $basket->add($one->sku, $one->name, $one->price, function ($product) use ($one) {
            $product->category($one->category);
        });

        return $basket;
    }